Locale Specific Code

I have some code that is supposed to manually separate the numerical groupings for arithmetic types when grabbing the locale being used; I'm in the midst of writing some unit tests and found locales that have one grouping and two groupings - but haven't found any locales that require 3 distinct groupings yet and am unable to test that portion of the code. I was hoping someone could point me in the right direction to find some locales that have 3 groupings?

i.e.

en_US has one grouping of 3 - so every third digit receives the separator for integrals
hi_IN has two groupings (one of 3 and then repeating groups of 2)
so that the furthest right grouping of three appears, then the separator, and any following groups of two digits are grouped before a new separator is added

-> I just haven't found a locale with 3 groupings yet but according to the standard, this is supported.


Last edited on
For testing, create locale of your own which has three groupings. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <locale>

struct three_groups : std::numpunct<char>
{
    char do_thousands_sep() const { return '\'' ;  }
    std::string do_grouping() const { return "\2\3\4" ; }
};

int main()
{
    std::locale test_locale( std::locale(), new three_groups ) ;
    std::cout.imbue(test_locale) ;
    std::cout << 123'4567'8901'234'56 << '\n' ; // 123'4567'8901'234'56
}

http://coliru.stacked-crooked.com/a/4c0f3b3d9c028128
I honestly have no idea why I didn't think of just doing a synthetic case... That totally works for test purposes so I appreciate your input and thank you!
BTW, India is the only outlier in digit groupings that exists in the real world.

I suppose the groupings can be co-opted for other useful purposes, but most people are unaware they exist at all, so...
Topic archived. No new replies allowed.