CharacterClass String::GetClassW( WChar ch ) const { WORD wType = 0; BOOL bRes = GetStringTypeExW( LOCALE_SYSTEM_DEFAULT, CT_CTYPE1, &ch, 1, &wType ); DebugAssert( bRes != FALSE ); CharacterClass chClass = CHARACTER_CLASS_UNKNOWN; if ( wType & C1_CNTRL ) chClass |= CHARACTER_CLASS_CONTROL; if ( wType & C1_ALPHA ) chClass |= CHARACTER_CLASS_ALPHA; if ( wType & C1_UPPER ) chClass |= CHARACTER_CLASS_UPPERCASE; if ( wType & C1_LOWER ) chClass |= CHARACTER_CLASS_LOWERCASE; if ( wType & C1_DIGIT ) chClass |= CHARACTER_CLASS_DIGIT; if ( wType & C1_XDIGIT ) chClass |= CHARACTER_CLASS_HEXDIGIT; if ( wType & C1_PUNCT ) chClass |= CHARACTER_CLASS_PUNCTUATION; if ( wType & C1_BLANK ) chClass |= CHARACTER_CLASS_BLANK; if ( wType & C1_SPACE ) chClass |= CHARACTER_CLASS_SPACE; if ( wType & C1_DEFINED ) chClass |= CHARACTER_CLASS_SPECIAL; return chClass; }
/*++ Function: iswprint See MSDN for more details. --*/ int __cdecl PAL_iswprint( wchar_16 c ) { WORD CharType; int ret; ENTRY ("iswprint (%#X)\n", c); ret = GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1, (WCHAR*)&c, 1, &CharType); if (!ret) { ASSERT("GetStringTypeExW failed to get information for %#X!\n", c); ret = 0; } else { if (CharType & (C1_BLANK|C1_PUNCT|C1_ALPHA|C1_DIGIT)) { /* Character is printable */ ret = 1; } else { /* Character is not printable */ ret = 0; } } LOGEXIT ("iswprint returns %d\n", ret); return (ret); }
/*-- Function: PAL_iswspace See MSDN doc --*/ int __cdecl PAL_iswspace(wchar_16 c) { int ret; #if HAVE_CFSTRING static CFCharacterSetRef sSpaceSet; if (sSpaceSet == NULL) { sSpaceSet = CFCharacterSetGetPredefined(kCFCharacterSetWhitespace); } ENTRY("PAL_iswspace (c=%C)\n", c); if (c >= 0x2000 && c <= 0x200b) { // U+2000 through U+200b are space characters according to // Core Foundation, but not on Windows. ret = FALSE; } else if ((c >= 0x000a && c <= 0x000d) || c == 0x0085 || c == 0x1680) { // U+000A through U+000D, U+0085, and U+1680 are space // characters according to Windows, but not with Core Foundation. ret = TRUE; } else { ret = CFCharacterSetIsCharacterMember(sSpaceSet, c); } #else // HAVE_CFSTRING WORD Info; ENTRY("PAL_iswspace (c=%C)\n", c); ret = GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1, (WCHAR*)&c, 1, &Info); if (ret == FALSE) { ASSERT("GetStringTypeExW failed to get information for %#X!\n", c); return -1; } ret = (Info & C1_SPACE); #endif // HAVE_CFSTRING LOGEXIT("PAL_iswspace returns int %d\n", ret); return ret; }
int __cdecl main(int argc, char **argv) { WORD Info; int ret; int i; WCHAR ch; if (PAL_Initialize(argc, argv)) { return FAIL; } for (i=0; i<=0xFFFF; i++) { ch = i; ret = GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1, &ch, 1, &Info); if (!ret) { Fail("GetStringTypeExW failed to get information for %#X!\n", ch); } ret = iswprint(ch); if (Info & (C1_BLANK|C1_PUNCT|C1_ALPHA|C1_DIGIT)) { if (!ret) { Fail("iswprint returned incorrect results for %#X: " "expected printable\n", ch); } } else { if (ret) { Fail("iswprint returned incorrect results for %#X: " "expected non-printable\n", ch); } } } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WORD Info; BOOL ret; int i; /* check only the bits listed in rotor_pal.doc */ const WORD PAL_VALID_C1_BITS = C1_DIGIT | C1_SPACE; if (PAL_Initialize(argc, argv)) { return FAIL; } for (i=0; i <TEST_LEN; i++) { ret = GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1, &TestStr[i], 1, &Info); if (!ret) { Fail("GetStringTypeExW failed!\n"); } if ((Info & PAL_VALID_C1_BITS) != (TestFlags[i] & PAL_VALID_C1_BITS)) { Fail("GetStringTypeExW (test #%i) returned wrong type info for %c (%d)\n" "Expected %#x, got %#x\n", i, TestStr[i], TestStr[i], TestFlags[i], Info); } } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WCHAR wideStr[] = {'9',' '}; WORD values1[] = { C1_DIGIT, C1_SPACE }; int len = 2; WORD Info[256]; BOOL ret; int i; if (PAL_Initialize(argc, argv)) { return FAIL; } for (i=0; i<len; i++) { ret = GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1, &wideStr[i], 1, &Info[i]); if (!ret) { Fail("GetStringTypeExW failed!\n"); } if ((Info[i] & values1[i])!= values1[i]) { Fail("GetStringTypeExW returned wrong type info for %c (%d)\n" "Expected %#x, got %#x\n", wideStr[i], wideStr[i], values1[i], Info[i]); } } PAL_Terminate(); return PASS; }