static engine_return_t engine_fixed_whole_line_match(error_t **error, void *data, const UString *subject) { FETCH_DATA(data, p, fixed_pattern_t); if (ustring_empty(p->pattern)) { return ustring_empty(subject) ? ENGINE_WHOLE_LINE_MATCH : ENGINE_NO_MATCH; } else if (NULL != p->usearch) { int32_t ret; UErrorCode status; status = U_ZERO_ERROR; usearch_setText(p->usearch, subject->ptr, subject->len, &status); if (U_FAILURE(status)) { icu_error_set(error, FATAL, status, "usearch_setText"); return ENGINE_FAILURE; } ret = usearch_first(p->usearch, &status); if (U_FAILURE(status)) { icu_error_set(error, FATAL, status, "usearch_first"); return ENGINE_FAILURE; } usearch_unbindText(p->usearch); return (ret != USEARCH_DONE && ((size_t) usearch_getMatchedLength(p->usearch)) == subject->len ? ENGINE_WHOLE_LINE_MATCH : ENGINE_NO_MATCH); } else { if (IS_CASE_INSENSITIVE(p->flags)) { return (0 == u_strcasecmp(p->pattern->ptr, subject->ptr, 0) ? ENGINE_WHOLE_LINE_MATCH : ENGINE_NO_MATCH); } else { return (0 == u_strcmp(p->pattern->ptr, subject->ptr) ? ENGINE_WHOLE_LINE_MATCH : ENGINE_NO_MATCH); } } }
static void demo_C_Unicode_strings() { printf("\n* demo_C_Unicode_strings() --------- ***\n\n"); static const UChar text[]={ 0x41, 0x42, 0x43, 0 }; /* "ABC" */ static const UChar appendText[]={ 0x61, 0x62, 0x63, 0 }; /* "abc" */ static const UChar cmpText[]={ 0x61, 0x53, 0x73, 0x43, 0 }; /* "aSsC" */ UChar buffer[32]; int32_t compare; int32_t length=u_strlen(text); /* length=3 */ /* simple ANSI C-style functions */ buffer[0]=0; /* empty, NUL-terminated string */ u_strncat(buffer, text, 1); /* append just n=1 character ('A') */ u_strcat(buffer, appendText); /* buffer=="Aabc" */ length=u_strlen(buffer); /* length=4 */ printUString("should be \"Aabc\": ", buffer, -1); /* bitwise comparing buffer with text */ compare=u_strcmp(buffer, text); if(compare<=0) { printf("String comparison error, expected \"Aabc\" > \"ABC\"\n"); } /* Build "A<sharp s>C" in the buffer... */ u_strcpy(buffer, text); buffer[1]=0xdf; /* sharp s, case-compares equal to "ss" */ printUString("should be \"A<sharp s>C\": ", buffer, -1); /* Compare two strings case-insensitively using full case folding */ compare=u_strcasecmp(buffer, cmpText, U_FOLD_CASE_DEFAULT); if(compare!=0) { printf("String case insensitive comparison error, expected \"AbC\" to be equal to \"ABC\"\n"); } }
int main(int argc,const char* agrv[]) { if(argc < 2) { printf("Usage: talk_server /AUTOMTION | /REGSERVER | /UNREGSERVER\n"); return -1; } const char* szCmdParam = agrv[1]; HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { if(0 == u_strcasecmp(agrv[1],"/REGSERVER") || 0 == u_strcasecmp(agrv[1],"-REGSERVER")) { printf("/REGSERVER\n"); } else if(0 == u_strcasecmp(agrv[1],"/UNREGSERVER") || 0 == u_strcasecmp(agrv[1],"-UNREGSERVER")) { printf("/UNREGSERVER\n"); }else if(0 == u_strcasecmp(agrv[1],"/AUTOMATION") || 0 == u_strcasecmp(agrv[1],"-AUTOMATION") || 0 == u_strcasecmp(agrv[1],"/EMBEDDING") || 0 == u_strcasecmp(agrv[1],"-EMBEDDING") ) { IUnknown *pUnk = NULL; DWORD dwReg = 0; static tgmtl::class_factory<CTalkManager> cf; hr = cf.QueryInterface(IID_IUnknown,(void **)&pUnk); if (SUCCEEDED(hr)) { hr = CoRegisterClassObject(CLSID_TalkToStranger,pUnk,CLSCTX_LOCAL_SERVER,REGCLS_MULTIPLEUSE| REGCLS_SUSPENDED,&dwReg); if (SUCCEEDED(hr)) hr = CoResumeClassObjects(); if(SUCCEEDED(hr)){ printf("=============================================\n"); printf("Server is Ready!\n"); ModuleAddRef();//this line ensure the server running forever ModuleServerListen(); } CoRevokeClassObject(dwReg); } //pUnk->Release(); } else { #ifdef WIN32 MessageBoxA(NULL,"UNKNOWN PARAMS","Test",MB_OK); #endif } CoUninitialize(); } return hr; }
static int xstrcasecmp(const char *a, const char *b) { if (a == NULL) { if (b == NULL) return 0; return -1; } else if (b == NULL) { return 1; } return u_strcasecmp(a, b); }
static engine_return_t engine_bin_whole_line_match(error_t **UNUSED(error), void *data, const UString *subject) { FETCH_DATA(data, p, bin_pattern_t); /* If search is case insensitive, we don't do case folding here, u_strcasecmp suffice (it does full case folding internally) */ if (ustring_empty(p->pattern)) { return ustring_empty(subject) ? ENGINE_WHOLE_LINE_MATCH : ENGINE_NO_MATCH; } else { if (IS_CASE_INSENSITIVE(p->flags)) { return (0 == u_strcasecmp(p->pattern->ptr, subject->ptr, 0) ? ENGINE_WHOLE_LINE_MATCH : ENGINE_NO_MATCH); } else { return (0 == u_strcmp(p->pattern->ptr, subject->ptr) ? ENGINE_WHOLE_LINE_MATCH : ENGINE_NO_MATCH); } } }
static void TestCaseCompare(void) { static const UChar mixed[]= { 0x61, 0x42, 0x131, 0x3a3, 0xdf, 0xfb03, 0xd93f, 0xdfff, 0 }, otherDefault[]= { 0x41, 0x62, 0x131, 0x3c3, 0x73, 0x53, 0x46, 0x66, 0x49, 0xd93f, 0xdfff, 0 }, otherExcludeSpecialI[]={ 0x41, 0x62, 0x131, 0x3c3, 0x53, 0x73, 0x66, 0x46, 0x69, 0xd93f, 0xdfff, 0 }, different[]= { 0x41, 0x62, 0x131, 0x3c3, 0x73, 0x53, 0x46, 0x66, 0x49, 0xd93f, 0xdffd, 0 }; UVersionInfo unicodeVersion={ 0, 0, 17, 89 }, unicode_3_1={ 3, 1, 0, 0 }; int32_t result, lenMixed, lenOtherDefault, lenOtherExcludeSpecialI, lenDifferent; UErrorCode errorCode; UBool isUnicode_3_1; errorCode=U_ZERO_ERROR; lenMixed=u_strlen(mixed); lenOtherDefault=u_strlen(otherDefault); (void)lenOtherDefault; /* Suppress set but not used warning. */ lenOtherExcludeSpecialI=u_strlen(otherExcludeSpecialI); lenDifferent=u_strlen(different); /* if unicodeVersion()>=3.1 then test exclude-special-i cases as well */ u_getUnicodeVersion(unicodeVersion); isUnicode_3_1= uprv_memcmp(unicodeVersion, unicode_3_1, 4)>=0; (void)isUnicode_3_1; /* Suppress set but not used warning. */ /* test u_strcasecmp() */ result=u_strcasecmp(mixed, otherDefault, U_FOLD_CASE_DEFAULT); if(result!=0) { log_err("error: u_strcasecmp(mixed, other, default)=%ld instead of 0\n", result); } result=u_strCaseCompare(mixed, -1, otherDefault, -1, U_FOLD_CASE_DEFAULT, &errorCode); if(result!=0) { log_err("error: u_strCaseCompare(mixed, other, default)=%ld instead of 0\n", result); } /* test u_strcasecmp() - exclude special i */ result=u_strcasecmp(mixed, otherExcludeSpecialI, U_FOLD_CASE_EXCLUDE_SPECIAL_I); if(result!=0) { log_err("error: u_strcasecmp(mixed, other, exclude special i)=%ld instead of 0\n", result); } result=u_strCaseCompare(mixed, lenMixed, otherExcludeSpecialI, lenOtherExcludeSpecialI, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &errorCode); if(result!=0) { log_err("error: u_strCaseCompare(mixed, other, exclude special i)=%ld instead of 0\n", result); } /* test u_strcasecmp() */ result=u_strcasecmp(mixed, different, U_FOLD_CASE_DEFAULT); if(result<=0) { log_err("error: u_strcasecmp(mixed, different, default)=%ld instead of positive\n", result); } result=u_strCaseCompare(mixed, -1, different, lenDifferent, U_FOLD_CASE_DEFAULT, &errorCode); if(result<=0) { log_err("error: u_strCaseCompare(mixed, different, default)=%ld instead of positive\n", result); } /* test u_strncasecmp() - stop before the sharp s (U+00df) */ result=u_strncasecmp(mixed, different, 4, U_FOLD_CASE_DEFAULT); if(result!=0) { log_err("error: u_strncasecmp(mixed, different, 4, default)=%ld instead of 0\n", result); } result=u_strCaseCompare(mixed, 4, different, 4, U_FOLD_CASE_DEFAULT, &errorCode); if(result!=0) { log_err("error: u_strCaseCompare(mixed, 4, different, 4, default)=%ld instead of 0\n", result); } /* test u_strncasecmp() - stop in the middle of the sharp s (U+00df) */ result=u_strncasecmp(mixed, different, 5, U_FOLD_CASE_DEFAULT); if(result<=0) { log_err("error: u_strncasecmp(mixed, different, 5, default)=%ld instead of positive\n", result); } result=u_strCaseCompare(mixed, 5, different, 5, U_FOLD_CASE_DEFAULT, &errorCode); if(result<=0) { log_err("error: u_strCaseCompare(mixed, 5, different, 5, default)=%ld instead of positive\n", result); } /* test u_memcasecmp() - stop before the sharp s (U+00df) */ result=u_memcasecmp(mixed, different, 4, U_FOLD_CASE_DEFAULT); if(result!=0) { log_err("error: u_memcasecmp(mixed, different, 4, default)=%ld instead of 0\n", result); } /* test u_memcasecmp() - stop in the middle of the sharp s (U+00df) */ result=u_memcasecmp(mixed, different, 5, U_FOLD_CASE_DEFAULT); if(result<=0) { log_err("error: u_memcasecmp(mixed, different, 5, default)=%ld instead of positive\n", result); } }