1
2#include <UnicodeChar.h>
3#include <Collator.h>
4#include <Language.h>
5#include <Locale.h>
6#include <String.h>
7
8#include <stdio.h>
9
10
11void
12unicode_char_to_string(uint32 c, char *text)
13{
14	BUnicodeChar::ToUTF8(c, &text);
15	text[0] = '\0';
16}
17
18
19int
20main()
21{
22	// Test BUnicodeChar class
23
24	char text[16];
25
26	for (int32 i = 30; i < 70; i++) {
27		unicode_char_to_string(i, text);
28		printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, defined == %d, charType == %d\n",
29			text,
30			BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), BUnicodeChar::IsLower(i),
31			BUnicodeChar::IsUpper(i), BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i));
32	}
33
34	uint32 chars[] = {(uint8)'�', (uint8)'�', (uint8)'�', (uint8)'�', (uint8)'�', (uint8)'�', 0};
35	for (int32 j = 0, i; (i = chars[j]) != 0; j++) {
36		unicode_char_to_string(i, text);
37		printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, defined == %d, charType == %d\n",
38			text,
39			BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), BUnicodeChar::IsLower(i),
40			BUnicodeChar::IsUpper(i), BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i));
41
42		unicode_char_to_string(BUnicodeChar::ToUpper(i), text);
43		printf("toUpper == %s, ", text);
44		unicode_char_to_string(BUnicodeChar::ToLower(i), text);
45		printf("toLower == %s\n", text);
46	}
47
48	const char *utf8chars[] = {"à", "ß", "ñ", "é", "ç", "ä", NULL};
49	for (int32 j = 0, i; (i = BUnicodeChar::FromUTF8(utf8chars[j])) != 0; j++) {
50		unicode_char_to_string(i, text);
51		printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, defined == %d, charType == %d\n",
52			text,
53			BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), BUnicodeChar::IsLower(i),
54			BUnicodeChar::IsUpper(i), BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i));
55
56		unicode_char_to_string(BUnicodeChar::ToUpper(i), text);
57		printf("toUpper == %s, ", text);
58		unicode_char_to_string(BUnicodeChar::ToLower(i), text);
59		printf("toLower == %s\n", text);
60	}
61	printf("%c: digitValue == %ld\n", '8', BUnicodeChar::DigitValue('8'));
62
63	// Test BCollator class
64
65	BCollator *collator = be_locale->Collator();
66	const char *strings[] = {"gehen", "géhen", "aus", "äUß", "auss", "äUß", "WO",
67		"wÖ", "SO", "so", "açñ", "acn", NULL};
68	const char *strengths[] = {"primary:  ", "secondary:", "tertiary: "};
69	for (int32 i = 0; strings[i]; i += 2) {
70		for (int32 strength = B_COLLATE_PRIMARY; strength < 4; strength++) {
71			BString a, b;
72			collator->GetSortKey(strings[i], &a, strength);
73			collator->GetSortKey(strings[i + 1], &b, strength);
74
75			printf("%s sort keys: \"%s\" -> \"%s\", \"%s\" -> \"%s\"\n",
76				strengths[strength-1], strings[i], a.String(), strings[i+1], b.String());
77			printf("\tcmp = %d (key compare = %d)\n",
78				collator->Compare(strings[i], strings[i + 1], -1, strength),
79				strcmp(a.String(), b.String()));
80		}
81		putchar('\n');
82	}
83
84	// Tests the BLanguage class
85
86	BLanguage *language = be_locale->Language();
87	printf("Language name = \"%s\", code = \"%s\", family = \"%s\"\n", language->Name(),
88		language->Code(), language->Family());
89	printf("\tdirection = %s\n",
90		language->Direction() == B_LEFT_TO_RIGHT ? "left-to-right" :
91		language->Direction() == B_RIGHT_TO_LEFT ? "right-to-left" :
92		"top-to-bottom");
93
94	//for (int32 i = 0; i < 200; i++) {
95	//	const char *string = language.GetString(i);
96	//	if (string != NULL)
97	//		printf("%ld: %s\n", i, string);
98	//}
99
100	printf("First month = %s (%s)\n",
101		language->GetString(B_MON_1),
102		language->GetString(B_AB_MON_1));
103}
104
105