ExpressionCompletionMatchesFixtureClass() : FileTestFixtureClass(wxT("tag-cache")) , SqliteTestFixtureClass(t4p::ResourceSqlSchemaAsset()) , TagCache() , GlobalFile(wxT("src") + wxString(wxFileName::GetPathSeparator()) + wxT("global.php")) , File1(wxT("src") + wxString(wxFileName::GetPathSeparator()) + wxT("file1.php")) , File2(wxT("src") + wxString(wxFileName::GetPathSeparator()) + wxT("file2.php")) , GlobalCode() , Code1() , Code2() , DoDuckTyping(false) , DoFullyQualifiedMatchOnly(false) , Scope() , ParsedVariable(Scope) , SourceDirs() , VariableMatches() , TagMatches() , Error() , Search() , PhpFileExtensions() , MiscFileExtensions() { CreateSubDirectory(wxT("src")); Search.Init(TestProjectDir + wxT("src")); PhpFileExtensions.push_back(wxT("*.php")); Scope.ClassName = UNICODE_STRING_SIMPLE(""); Scope.MethodName = UNICODE_STRING_SIMPLE(""); Session1 = new soci::session(*soci::factory_sqlite3(), ":memory:"); CreateDatabase(*Session1, t4p::ResourceSqlSchemaAsset()); wxFileName srcDir; srcDir.AssignDir(TestProjectDir + wxT("src")); SourceDirs.push_back(srcDir); }
KhmerBreakEngine::KhmerBreakEngine(DictionaryMatcher *adoptDictionary, UErrorCode &status) : DictionaryBreakEngine((1 << UBRK_WORD) | (1 << UBRK_LINE)), fDictionary(adoptDictionary) { fKhmerWordSet.applyPattern(UNICODE_STRING_SIMPLE("[[:Khmr:]&[:LineBreak=SA:]]"), status); if (U_SUCCESS(status)) { setCharacters(fKhmerWordSet); } fMarkSet.applyPattern(UNICODE_STRING_SIMPLE("[[:Khmr:]&[:LineBreak=SA:]&[:M:]]"), status); fMarkSet.add(0x0020); fEndWordSet = fKhmerWordSet; fBeginWordSet.add(0x1780, 0x17B3); //fBeginWordSet.add(0x17A3, 0x17A4); // deprecated vowels //fEndWordSet.remove(0x17A5, 0x17A9); // Khmer independent vowels that can't end a word //fEndWordSet.remove(0x17B2); // Khmer independent vowel that can't end a word fEndWordSet.remove(0x17D2); // KHMER SIGN COENG that combines some following characters //fEndWordSet.remove(0x17B6, 0x17C5); // Remove dependent vowels // fEndWordSet.remove(0x0E31); // MAI HAN-AKAT // fEndWordSet.remove(0x0E40, 0x0E44); // SARA E through SARA AI MAIMALAI // fBeginWordSet.add(0x0E01, 0x0E2E); // KO KAI through HO NOKHUK // fBeginWordSet.add(0x0E40, 0x0E44); // SARA E through SARA AI MAIMALAI // fSuffixSet.add(THAI_PAIYANNOI); // fSuffixSet.add(THAI_MAIYAMOK); // Compact for caching. fMarkSet.compact(); fEndWordSet.compact(); fBeginWordSet.compact(); // fSuffixSet.compact(); }
std::vector<t4p::PhpTagClass> t4p::TagCacheClass::AllMemberTags(const UnicodeString& fullyQualifiedClassName, int fileTagId, std::vector<wxFileName>& sourceDirs) { std::vector<t4p::PhpTagClass> allMatches; // add the double colon so that we search for all members // first search for all members of the given class that is also in the given file t4p::TagSearchClass tagSearch(fullyQualifiedClassName + UNICODE_STRING_SIMPLE("::")); tagSearch.SetFileItemId(fileTagId); tagSearch.SetTraits(TagFinderList->ClassUsedTraits(fullyQualifiedClassName, tagSearch.GetParentClasses(), tagSearch.GetMethodName(), sourceDirs)); TagFinderList->NearMatchesFromAll(tagSearch, allMatches, sourceDirs); // now get all parent class (look in all files) also look for inherited members and traits UnicodeString parentClassName = TagFinderList->ParentClassName(fullyQualifiedClassName, fileTagId); if (!parentClassName.isEmpty()) { t4p::TagSearchClass hierarchySearch(parentClassName + UNICODE_STRING_SIMPLE("::")); hierarchySearch.SetParentClasses(TagFinderList->ClassParents(parentClassName, hierarchySearch.GetMethodName())); hierarchySearch.SetTraits(TagFinderList->ClassUsedTraits(parentClassName, hierarchySearch.GetParentClasses(), hierarchySearch.GetMethodName(), sourceDirs)); // search classes from the enabled source directories only hierarchySearch.SetSourceDirs(sourceDirs); TagFinderList->NearMatchesFromAll(hierarchySearch, allMatches, sourceDirs); TagFinderList->NearMatchTraitAliasesFromAll(hierarchySearch, allMatches); } return allMatches; }
void UTS46Test::TestNotSTD3() { IcuTestErrorCode errorCode(*this, "TestNotSTD3()"); char buffer[400]; LocalPointer<IDNA> not3(IDNA::createUTS46Instance(UIDNA_CHECK_BIDI, errorCode)); if(errorCode.isFailure()) { return; } UnicodeString input=UNICODE_STRING_SIMPLE("\\u0000A_2+2=4\\u000A.e\\u00DFen.net").unescape(); UnicodeString result; IDNAInfo info; if( not3->nameToUnicode(input, result, info, errorCode)!= UNICODE_STRING_SIMPLE("\\u0000a_2+2=4\\u000A.essen.net").unescape() || info.hasErrors() ) { prettify(result).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); errln("notSTD3.nameToUnicode(non-LDH ASCII) unexpected errors %04lx string %s", (long)info.getErrors(), buffer); } // A space (BiDi class WS) is not allowed in a BiDi domain name. input=UNICODE_STRING_SIMPLE("a z.xn--4db.edu"); not3->nameToASCII(input, result, info, errorCode); if(result!=input || info.getErrors()!=UIDNA_ERROR_BIDI) { errln("notSTD3.nameToASCII(ASCII-with-space.alef.edu) failed"); } // Characters that are canonically equivalent to sequences with non-LDH ASCII. input=UNICODE_STRING_SIMPLE("a\\u2260b\\u226Ec\\u226Fd").unescape(); not3->nameToUnicode(input, result, info, errorCode); if(result!=input || info.hasErrors()) { prettify(result).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer)); errln("notSTD3.nameToUnicode(equiv to non-LDH ASCII) unexpected errors %04lx string %s", (long)info.getErrors(), buffer); } }
TEST_FIXTURE(ExpressionCompletionMatchesFixtureClass, TagMatchesWithStaleMatches) { // create a class in global file with methodA // file2 will use the class from global file; file2 will be registered // then global file will be registered with file2 (invalidating methodA) // perform a search // methodA should not be a hit since it has been removed GlobalCode = wxT("<?php class ActionMy { function methodA() {} }"); Code1 = UNICODE_STRING_SIMPLE("<?php $action = new ActionMy(); "); Code2 = UNICODE_STRING_SIMPLE("<?php class ActionMy { function methodB() {} }"); CreateFixtureFile(GlobalFile, GlobalCode); t4p::WorkingCacheClass* cache1 = CreateWorkingCache(File1, Code1); t4p::TagFinderListClass* cache2 = CreateTagFinderList(wxT("src")); CHECK(TagCache.RegisterWorking(File1, cache1)); TagCache.RegisterGlobal(cache2); ToProperty(UNICODE_STRING_SIMPLE("$action"), UNICODE_STRING_SIMPLE("methodA")); TagCache.ResourceMatches(File1, ParsedVariable, Scope, SourceDirs, TagMatches, DoDuckTyping, DoFullyQualifiedMatchOnly, Error); CHECK_VECTOR_SIZE(1, TagMatches); CHECK_UNISTR_EQUALS("methodA", TagMatches[0].Identifier); CHECK_UNISTR_EQUALS("ActionMy", TagMatches[0].ClassName); // now update the code by creating a working version of the global code. // ie. the user opening a file. t4p::WorkingCacheClass* cache3 = CreateWorkingCache(GlobalFile, Code2); CHECK(TagCache.RegisterWorking(GlobalFile, cache3)); TagMatches.clear(); TagCache.ResourceMatches(GlobalFile, ParsedVariable, Scope, SourceDirs, TagMatches, DoDuckTyping, DoFullyQualifiedMatchOnly, Error); CHECK_VECTOR_SIZE(0, TagMatches); }
TitlecaseTransliterator::TitlecaseTransliterator(const Locale& theLoc) : Transliterator(_ID, 0), loc(theLoc), buffer(0) { buffer = (UChar *)uprv_malloc(u_getMaxCaseExpansion()*sizeof(buffer[0])); // Need to look back 2 characters in the case of "can't" setMaximumContextLength(2); umtx_lock(NULL); UBool f = (SKIP == NULL); umtx_unlock(NULL); if (f) { UErrorCode ec = U_ZERO_ERROR; UnicodeSet* skip = new UnicodeSet(UNICODE_STRING_SIMPLE("[\\u00AD \\u2019 \\' [:Mn:] [:Me:] [:Cf:] [:Lm:] [:Sk:]]"), ec); UnicodeSet* cased = new UnicodeSet(UNICODE_STRING_SIMPLE("[[:Lu:] [:Ll:] [:Lt:]]"), ec); if (skip != NULL && cased != NULL && U_SUCCESS(ec)) { umtx_lock(NULL); if (SKIP == NULL) { SKIP = skip; CASED = cased; skip = cased = NULL; } umtx_unlock(NULL); } delete skip; delete cased; ucln_i18n_registerCleanup(); } }
CjkBreakEngine::CjkBreakEngine(const TrieWordDictionary *adoptDictionary, LanguageType type, UErrorCode &status) : DictionaryBreakEngine(1<<UBRK_WORD), fDictionary(adoptDictionary){ if (!adoptDictionary->getValued()) { status = U_ILLEGAL_ARGUMENT_ERROR; return; } // Korean dictionary only includes Hangul syllables fHangulWordSet.applyPattern(UNICODE_STRING_SIMPLE("[\\uac00-\\ud7a3]"), status); fHanWordSet.applyPattern(UNICODE_STRING_SIMPLE("[:Han:]"), status); fKatakanaWordSet.applyPattern(UNICODE_STRING_SIMPLE("[[:Katakana:]\\uff9e\\uff9f]"), status); fHiraganaWordSet.applyPattern(UNICODE_STRING_SIMPLE("[:Hiragana:]"), status); if (U_SUCCESS(status)) { // handle Korean and Japanese/Chinese using different dictionaries if (type == kKorean) { setCharacters(fHangulWordSet); } else { //Chinese and Japanese UnicodeSet cjSet; cjSet.addAll(fHanWordSet); cjSet.addAll(fKatakanaWordSet); cjSet.addAll(fHiraganaWordSet); cjSet.add(UNICODE_STRING_SIMPLE("\\uff70\\u30fc")); setCharacters(cjSet); } } }
void RuleBasedNumberFormat::initDefaultRuleSet() { defaultRuleSet = NULL; if (!ruleSets) { return; } const UnicodeString spellout = UNICODE_STRING_SIMPLE("%spellout-numbering"); const UnicodeString ordinal = UNICODE_STRING_SIMPLE("%digits-ordinal"); const UnicodeString duration = UNICODE_STRING_SIMPLE("%duration"); NFRuleSet**p = &ruleSets[0]; while (*p) { if ((*p)->isNamed(spellout) || (*p)->isNamed(ordinal) || (*p)->isNamed(duration)) { defaultRuleSet = *p; return; } else { ++p; } } defaultRuleSet = *--p; if (!defaultRuleSet->isPublic()) { while (p != ruleSets) { if ((*--p)->isPublic()) { defaultRuleSet = *p; break; } } } }
TEST_FIXTURE(MysqlResourceFinderFixtureClass, FindColumns) { std::string query = "CREATE TABLE web_users(idIUser int);"; CHECK(DatabaseTestFixtureClass::Exec(query)); query = "CREATE TABLE service_names(idIServiceName int);"; CHECK(DatabaseTestFixtureClass::Exec(query)); query = "CREATE TABLE service_locations(idIServiceLocation int);"; CHECK(DatabaseTestFixtureClass::Exec(query)); query = "CREATE TABLE deleted_users(idIUser int, idIDeletedBy int);"; CHECK(DatabaseTestFixtureClass::Exec(query)); UnicodeString error; CHECK(Fetcher.Fetch(DatabaseTag, error)); std::vector<UnicodeString> columns = Finder.FindColumns(DatabaseTag, UNICODE_STRING_SIMPLE("idIServiceL")); CHECK_VECTOR_SIZE(1, columns); CHECK_UNISTR_EQUALS_NO_CASE("idIServiceLocation", columns[0]); columns = Finder.FindColumns(DatabaseTag, UNICODE_STRING_SIMPLE("idI")); CHECK_VECTOR_SIZE(4, columns); CHECK_UNISTR_EQUALS_NO_CASE("idIDeletedBy", columns[0]); CHECK_UNISTR_EQUALS_NO_CASE("idIServiceLocation", columns[1]); CHECK_UNISTR_EQUALS_NO_CASE("idIServiceName", columns[2]); CHECK_UNISTR_EQUALS_NO_CASE("idIUser", columns[3]); }
void StringCaseTest::TestFullCaseFoldingIterator() { UnicodeString ffi=UNICODE_STRING_SIMPLE("ffi"); UnicodeString ss=UNICODE_STRING_SIMPLE("ss"); FullCaseFoldingIterator iter; int32_t count=0; int32_t countSpecific=0; UChar32 c; UnicodeString full; while((c=iter.next(full))>=0) { ++count; // Check that the full Case_Folding has more than 1 code point. if(!full.hasMoreChar32Than(0, 0x7fffffff, 1)) { errln("error: FullCaseFoldingIterator.next()=U+%04lX full Case_Folding has at most 1 code point", (long)c); continue; } // Check that full == Case_Folding(c). UnicodeString cf(c); cf.foldCase(); if(full!=cf) { errln("error: FullCaseFoldingIterator.next()=U+%04lX full Case_Folding != cf(c)", (long)c); continue; } // Spot-check a couple of specific cases. if((full==ffi && c==0xfb03) || (full==ss && (c==0xdf || c==0x1e9e))) { ++countSpecific; } } if(countSpecific!=3) { errln("error: FullCaseFoldingIterator did not yield exactly the expected specific cases"); } if(count<70) { errln("error: FullCaseFoldingIterator yielded only %d (cp, full) pairs", (int)count); } }
void PluralRulesTest::testGetSamples() { // TODO: fix samples, re-enable this test. // no get functional equivalent API in ICU4C, so just // test every locale... UErrorCode status = U_ZERO_ERROR; int32_t numLocales; const Locale* locales = Locale::getAvailableLocales(numLocales); double values[1000]; for (int32_t i = 0; U_SUCCESS(status) && i < numLocales; ++i) { PluralRules *rules = PluralRules::forLocale(locales[i], status); if (U_FAILURE(status)) { break; } StringEnumeration *keywords = rules->getKeywords(status); if (U_FAILURE(status)) { delete rules; break; } const UnicodeString* keyword; while (NULL != (keyword = keywords->snext(status))) { int32_t count = rules->getSamples(*keyword, values, LENGTHOF(values), status); if (U_FAILURE(status)) { errln(UNICODE_STRING_SIMPLE("getSamples() failed for locale ") + locales[i].getName() + UNICODE_STRING_SIMPLE(", keyword ") + *keyword); continue; } if (count == 0) { // TODO: Lots of these. // errln(UNICODE_STRING_SIMPLE("no samples for keyword ") + *keyword + UNICODE_STRING_SIMPLE(" in locale ") + locales[i].getName() ); } if (count > LENGTHOF(values)) { errln(UNICODE_STRING_SIMPLE("getSamples()=") + count + UNICODE_STRING_SIMPLE(", too many values, for locale ") + locales[i].getName() + UNICODE_STRING_SIMPLE(", keyword ") + *keyword); count = LENGTHOF(values); } for (int32_t j = 0; j < count; ++j) { if (values[j] == UPLRULES_NO_UNIQUE_VALUE) { errln("got 'no unique value' among values"); } else { UnicodeString resultKeyword = rules->select(values[j]); // if (strcmp(locales[i].getName(), "uk") == 0) { // Debug only. // std::cout << " uk " << US(resultKeyword).cstr() << " " << values[j] << std::endl; // } if (*keyword != resultKeyword) { errln("file %s, line %d, Locale %s, sample for keyword \"%s\": %g, select(%g) returns keyword \"%s\"", __FILE__, __LINE__, locales[i].getName(), US(*keyword).cstr(), values[j], values[j], US(resultKeyword).cstr()); } } } } delete keywords; delete rules; } }
DatabaseTagTestFixtureClass() : DatabaseTestFixtureClass("database_tag") , DatabaseTag() { DatabaseTag.Schema = UNICODE_STRING_SIMPLE("database_tag"); DatabaseTag.Host = UNICODE_STRING_SIMPLE("127.0.0.1"); DatabaseTag.User = t4p::CharToIcu(UserName().c_str()); DatabaseTag.Password = t4p::CharToIcu(Password().c_str()); }
/** * Iterate through the given iterator, checking to see that all the strings * in the expected array are present. * @param expected array of strings we expect to see, or NULL * @param expectedCount number of elements of expected, or 0 */ int32_t CollationServiceTest::checkStringEnumeration(const char* msg, StringEnumeration& iter, const char** expected, int32_t expectedCount) { UErrorCode ec = U_ZERO_ERROR; U_ASSERT(expectedCount >= 0 && expectedCount < 31); // [sic] 31 not 32 int32_t i = 0, idxAfterReset = 0, n = iter.count(ec); assertSuccess("count", ec); UnicodeString buf, buffAfterReset; int32_t seenMask = 0; for (;; ++i) { const UnicodeString* s = iter.snext(ec); if (!assertSuccess("snext", ec) || s == NULL) break; if (i != 0) buf.append(UNICODE_STRING_SIMPLE(", ")); buf.append(*s); // check expected list for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) { if ((seenMask&bit)==0) { UnicodeString exp(expected[j], (char*)NULL); if (*s == exp) { seenMask |= bit; logln((UnicodeString)"Ok: \"" + exp + "\" seen"); } } } } // can't get pesky operator+(const US&, foo) to cooperate; use toString #if !UCONFIG_NO_FORMATTING logln(UnicodeString() + msg + " = [" + buf + "] (" + toString(i) + ")"); #else logln(UnicodeString() + msg + " = [" + buf + "] (??? NO_FORMATTING)"); #endif assertTrue("count verified", i==n); iter.reset(ec); for (;; ++idxAfterReset) { const UChar *s = iter.unext(NULL, ec); if (!assertSuccess("unext", ec) || s == NULL) break; if (idxAfterReset != 0) buffAfterReset.append(UNICODE_STRING_SIMPLE(", ")); buffAfterReset.append(s); } assertTrue("idxAfterReset verified", idxAfterReset==n); assertTrue("buffAfterReset verified", buffAfterReset==buf); // did we see all expected strings? if (((1<<expectedCount)-1) != seenMask) { for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) { if ((seenMask&bit)==0) { errln((UnicodeString)"FAIL: \"" + expected[j] + "\" not seen"); } } } return n; }
TEST_FIXTURE(MysqlResourceFinderFixtureClass, FindTableShouldLocateInformationSchema) { UnicodeString error; CHECK(Fetcher.Fetch(DatabaseTag, error)); std::vector<UnicodeString> tables = Finder.FindTables(DatabaseTag, UNICODE_STRING_SIMPLE("information_sche")); CHECK_VECTOR_SIZE(1, tables); CHECK_UNISTR_EQUALS_NO_CASE("information_schema", tables[0]); tables = Finder.FindTables(DatabaseTag, UNICODE_STRING_SIMPLE("colum")); CHECK_VECTOR_SIZE(2, tables); CHECK_UNISTR_EQUALS_NO_CASE("column_privileges", tables[0]); CHECK_UNISTR_EQUALS_NO_CASE("columns", tables[1]); }
void t4p::PhpCodeCompletionProviderClass::OnAutoCompletionSelected(wxStyledTextEvent& event) { wxStyledTextCtrl* txtCtrl = wxDynamicCast(event.GetEventObject(), wxStyledTextCtrl); if (!txtCtrl) { return; } t4p::CodeControlClass* ctrl = (t4p::CodeControlClass*)txtCtrl; if (!AutoCompletionResourceMatches.empty()) { UnicodeString selected = t4p::WxToIcu(event.GetText()); bool handled = false; for (size_t i = 0; i < AutoCompletionResourceMatches.size(); ++i) { t4p::PhpTagClass res = AutoCompletionResourceMatches[i]; if (res.Identifier == selected) { // user had selected a function /method name; let's add the // parenthesis and show the call tip ctrl->AutoCompCancel(); wxString selected = event.GetText(); int startPos = ctrl->WordStartPosition(ctrl->GetCurrentPos(), true); ctrl->SetSelection(startPos, ctrl->GetCurrentPos()); wxString status; if ((t4p::PhpTagClass::FUNCTION == res.Type || t4p::PhpTagClass::METHOD == res.Type) && !res.HasParameters()) { ctrl->ReplaceSelection(selected + wxT("()")); ctrl->HandleCallTip(0, true); } else if (t4p::PhpTagClass::FUNCTION == res.Type || t4p::PhpTagClass::METHOD == res.Type) { ctrl->ReplaceSelection(selected + wxT("(")); ctrl->HandleCallTip(0, true); } else { ctrl->ReplaceSelection(selected); } handled = true; break; } } if (!handled) { // complete the PHP alternative syntax for control structures // ie endif endwhile endfor endforeach endswitch // Scintilla cannot handle semicolons in keywords; we will add the semicolon here if (selected.caseCompare(UNICODE_STRING_SIMPLE("endif"), 0) == 0 || selected.caseCompare(UNICODE_STRING_SIMPLE("endwhile"), 0) == 0 || selected.caseCompare(UNICODE_STRING_SIMPLE("endfor"), 0) == 0 || selected.caseCompare(UNICODE_STRING_SIMPLE("endforeach"), 0) == 0 || selected.caseCompare(UNICODE_STRING_SIMPLE("endswitch"), 0) == 0) { ctrl->AutoCompCancel(); wxString selected = event.GetText(); int startPos = ctrl->WordStartPosition(ctrl->GetCurrentPos(), true); ctrl->SetSelection(startPos, ctrl->GetCurrentPos()); ctrl->ReplaceSelection(selected + wxT(";")); } } } }
MysqlResourceFinderFixtureClass() : DatabaseTestFixtureClass("sql_resource_finder") , SqliteTestFixtureClass(t4p::ResourceSqlSchemaAsset()) , DatabaseTag() , Fetcher(SqliteTestFixtureClass::Session) , Finder(SqliteTestFixtureClass::Session) { DatabaseTag.Driver = t4p::DatabaseTagClass::MYSQL; DatabaseTag.Schema = UNICODE_STRING_SIMPLE("sql_resource_finder"); // user name, pwd are #defines come from the premake script premake_opts.lua DatabaseTag.Host = UNICODE_STRING_SIMPLE("127.0.0.1"); DatabaseTag.User = t4p::CharToIcu(UserName().c_str()); DatabaseTag.Password = t4p::CharToIcu(Password().c_str()); }
TEST_FIXTURE(MysqlResourceFinderFixtureClass, FindDatabaseTagrmationSchemaColumns) { UnicodeString error; CHECK(Fetcher.Fetch(DatabaseTag, error)); std::vector<UnicodeString> columns = Finder.FindColumns(DatabaseTag, UNICODE_STRING_SIMPLE("table_nam")); CHECK_VECTOR_SIZE(1, columns); CHECK_UNISTR_EQUALS_NO_CASE("table_name", columns[0]); }
UnicodeString ICUSQLite3Utility::Format( const UDate& dateTime, const EIcuSqlite3DTStorageTypes type) { if(!m_dtFormat) { return UNICODE_STRING_SIMPLE(""); } if(ICUSQLITE_DATETIME_ISO8601 == type) { //Format as full date/time. See if we have milliseconds and // format accordingly. if(0 == (static_cast<int64_t>(dateTime) % 1000)) { SetFormat(DATE_FORMAT_ISO8601_DATETIME); } else { SetFormat(DATE_FORMAT_ISO8601_DATETIME_MILLISECONDS); } } else if(ICUSQLITE_DATETIME_ISO8601_TIME == type) { //Format as time only. See if we have milliseconds and // format accordingly. if(0 == (static_cast<int64_t>(dateTime) % 1000)) { SetFormat(DATE_FORMAT_ISO8601_TIME); } else { SetFormat(DATE_FORMAT_ISO8601_TIME_MILLISECONDS); } } else { SetFormat(static_cast<EIcuSqlite3FormatIndex>(type)); } UnicodeString result; return m_dtFormat->format(dateTime, result); }
TEST_FIXTURE(DatabaseTagTestFixtureClass, ConnectQueryAndResults) { Exec("CREATE TABLE names (id INT, name VARCHAR(255));"); // without the explicit transaction, this test fails on // ubuntu 12.04 and mysql 5.5 Exec("BEGIN"); Exec("INSERT INTO names(id, name) VALUES(1, 'one')"); Exec("INSERT INTO names(id, name) VALUES(2, 'two')"); Exec("INSERT INTO names(id, name) VALUES(3, 'three')"); Exec("COMMIT"); soci::session session; t4p::SqlQueryClass query; UnicodeString error; query.DatabaseTag.Copy(DatabaseTag); CHECK(query.Connect(session, error)); CHECK_EQUAL(0, error.length()); t4p::SqlResultClass results; CHECK(query.Execute(session, results, UNICODE_STRING_SIMPLE("SELECT * FROM names ORDER BY id;"))); CHECK_EQUAL(0, results.Error.length()); CHECK(results.Success); CHECK_EQUAL(3, results.AffectedRows); CHECK_EQUAL(0, error.length()); CHECK_VECTOR_SIZE(3, results.StringResults); CHECK_UNISTR_EQUALS("1", results.StringResults[0][0]); CHECK_UNISTR_EQUALS("one", results.StringResults[0][1]); CHECK_UNISTR_EQUALS("2", results.StringResults[1][0]); CHECK_UNISTR_EQUALS("two", results.StringResults[1][1]); CHECK_UNISTR_EQUALS("3", results.StringResults[2][0]); CHECK_UNISTR_EQUALS("three", results.StringResults[2][1]); }
void ProfileFindInFilesExactMode() { printf("*******\n"); wxLongLong time = wxGetLocalTimeMillis(); t4p::DirectorySearchClass directorySearch; if (directorySearch.Init(DirName)) { t4p::FindInFilesClass findInFiles; findInFiles.Expression = UNICODE_STRING_SIMPLE("class Db"); findInFiles.Mode = t4p::FinderClass::EXACT; if (findInFiles.Prepare()) { while (directorySearch.More()) { directorySearch.Walk(findInFiles); } std::vector<wxString> matchedFiles = directorySearch.GetMatchedFiles(); for (size_t i = 0; i < matchedFiles.size(); ++i) { printf("Found at least one match in file %s.\n", (const char*)matchedFiles[i].ToUTF8()); } time = wxGetLocalTimeMillis() - time; printf("time for findInFiles Exact Mode:%ld ms \n", time.ToLong()); } else { puts("Invalid expression: class Db\n"); } } else { printf("Could not open Directory: %s\n", (const char*)DirName.ToAscii()); } }
void ProfileFindInFilesCodeMode() { printf("*******\n"); wxLongLong time = wxGetLocalTimeMillis(); t4p::DirectorySearchClass directorySearch; t4p::SourceClass src; src.RootDirectory.AssignDir(DirName); src.SetIncludeWildcards(wxT("*.php")); std::vector<t4p::SourceClass> sources; sources.push_back(src); if (directorySearch.Init(sources)) { t4p::FindInFilesClass findInFiles; findInFiles.Expression = UNICODE_STRING_SIMPLE("class Db"); findInFiles.Mode = t4p::FinderClass::EXACT; if (findInFiles.Prepare()) { while (directorySearch.More()) { directorySearch.Walk(findInFiles); } std::vector<wxString> matchedFiles = directorySearch.GetMatchedFiles(); for (size_t i = 0; i < matchedFiles.size(); ++i) { printf("Found at least one match in file %s.\n", (const char*)matchedFiles[i].ToUTF8()); } time = wxGetLocalTimeMillis() - time; printf("time for findInFiles Code Mode:%ld ms\n", time.ToLong()); } else { puts("Invalid expression: class Db\n"); } } else { printf("Could not open Directory: %s\n", (const char*)DirName.ToAscii()); } }
bool t4p::FinderClass::FindNextRegularExpression(const UnicodeString& text, int32_t start) { if (U_SUCCESS(PatternErrorCode) && Pattern != NULL) { UnicodeString findText(text); if (start > 0 && start < text.length()) { findText.setTo(text, start); } else if (start > 0) { findText = UNICODE_STRING_SIMPLE(""); } int32_t foundPos = 0, length = 0, endPos = 0; UErrorCode error = U_ZERO_ERROR; RegexMatcher* matcher = Pattern->matcher(findText, error); if (U_SUCCESS(error) && matcher) { if (matcher->find()) { foundPos = matcher->start(error); endPos = matcher->end(error); if (U_SUCCESS(error) && U_SUCCESS(error)) { IsFound = true; length = endPos - foundPos; // end is the index after the match // if search was started from the middle of a string, // need to correct the found position LastPosition = start > 0 ? foundPos + start : foundPos; LastLength = length; } } delete matcher; } } return IsFound; }
/** * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized, * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ). */ const Region* U_EXPORT2 Region::getInstance (int32_t code, UErrorCode &status) { loadRegionData(); Region *r = (Region *)uhash_iget(numericCodeMap,code); if ( !r ) { // Just in case there's an alias that's numeric, try to find it. UErrorCode fs = U_ZERO_ERROR; UnicodeString pat = UNICODE_STRING_SIMPLE("00#"); DecimalFormat *df = new DecimalFormat(pat,fs); UnicodeString id; id.remove(); df->format(code,id); delete df; r = (Region *)uhash_get(regionAliases,&id); } if ( !r ) { status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } if ( r->type == URGN_DEPRECATED && r->preferredValues->size() == 1) { StringEnumeration *pv = r->getPreferredValues(); pv->reset(status); const UnicodeString *ustr = pv->snext(status); r = (Region *)uhash_get(regionIDMap,(void *)ustr); delete pv; } return r; }
TEST_FIXTURE(TagCacheSearchFixtureClass, ExactTags) { wxString code = wxT("<?php class ActionYou { function w() {} }"); CreateSubDirectory(wxT("src")); CreateFixtureFile(wxT("src") + wxString(wxFileName::GetPathSeparator()) + wxT("file1.php"), code); t4p::TagFinderListClass* cache = CreateTagFinderList(wxT("src")); TagCache.RegisterGlobal(cache); // empty means search all dirs std::vector<wxFileName> searchDirs; t4p::TagResultClass* result = TagCache.ExactTags(UNICODE_STRING_SIMPLE("ActionYou"), searchDirs); CHECK(result); if (!result) { return; } CHECK(result->More()); result->Next(); CHECK_UNISTR_EQUALS("ActionYou", result->Tag.Identifier); CHECK_UNISTR_EQUALS("ActionYou", result->Tag.ClassName); CHECK_EQUAL(false, result->More()); // do this now so that we dont use the inherited Session delete result; }
void MultithreadTest::TestBreakTranslit() { UErrorCode status = U_ZERO_ERROR; UnicodeString input( "\\u0E42\\u0E14\\u0E22\\u0E1E\\u0E37\\u0E49\\u0E19\\u0E10\\u0E32\\u0E19\\u0E41\\u0E25\\u0E49\\u0E27,"); input = input.unescape(); gTranslitInput = &input; gSharedTransliterator = Transliterator::createInstance( UNICODE_STRING_SIMPLE("Any-Latin; Lower; NFD; [:Diacritic:]Remove; NFC; Latin-ASCII;"), UTRANS_FORWARD, status); if (!gSharedTransliterator) { return; } TSMTHREAD_ASSERT_SUCCESS(status); UnicodeString expected(*gTranslitInput); gSharedTransliterator->transliterate(expected); gTranslitExpected = &expected; BreakTranslitThread threads[4]; for (int i=0; i<UPRV_LENGTHOF(threads); ++i) { threads[i].start(); } for (int i=0; i<UPRV_LENGTHOF(threads); ++i) { threads[i].join(); } delete gSharedTransliterator; gTranslitInput = NULL; gTranslitExpected = NULL; }
NFRuleSet::NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& status) : name() , rules(0) , negativeNumberRule(NULL) , fIsFractionRuleSet(FALSE) , fIsPublic(FALSE) , fIsParseable(TRUE) , fRecursionCount(0) { for (int i = 0; i < 3; ++i) { fractionRules[i] = NULL; } if (U_FAILURE(status)) { return; } UnicodeString& description = descriptions[index]; // !!! make sure index is valid if (description.length() == 0) { // throw new IllegalArgumentException("Empty rule set description"); status = U_PARSE_ERROR; return; } // if the description begins with a rule set name (the rule set // name can be omitted in formatter descriptions that consist // of only one rule set), copy it out into our "name" member // and delete it from the description if (description.charAt(0) == gPercent) { int32_t pos = description.indexOf(gColon); if (pos == -1) { // throw new IllegalArgumentException("Rule set name doesn't end in colon"); status = U_PARSE_ERROR; } else { name.setTo(description, 0, pos); while (pos < description.length() && PatternProps::isWhiteSpace(description.charAt(++pos))) { } description.remove(0, pos); } } else { name.setTo(UNICODE_STRING_SIMPLE("%default")); } if (description.length() == 0) { // throw new IllegalArgumentException("Empty rule set description"); status = U_PARSE_ERROR; } fIsPublic = name.indexOf(gPercentPercent, 2, 0) != 0; if ( name.endsWith(gNoparse,8) ) { fIsParseable = FALSE; name.truncate(name.length()-8); // remove the @noparse from the name } // all of the other members of NFRuleSet are initialized // by parseRules() }
void CollationRegressionTest::TestBeforeWithTooStrongAfter() { // ICU ticket #9959: // Forbid rules with a before-reset followed by a stronger relation. IcuTestErrorCode errorCode(*this, "TestBeforeWithTooStrongAfter"); RuleBasedCollator before2(UNICODE_STRING_SIMPLE("&[before 2]x<<q<p"), errorCode); if(errorCode.isSuccess()) { errln("should forbid before-2-reset followed by primary relation"); } else { errorCode.reset(); } RuleBasedCollator before3(UNICODE_STRING_SIMPLE("&[before 3]x<<<q<<s<p"), errorCode); if(errorCode.isSuccess()) { errln("should forbid before-3-reset followed by primary or secondary relation"); } else { errorCode.reset(); } }
void AlphabeticIndex::addIndexExemplars(const Locale &locale, UErrorCode &status) { LocalULocaleDataPointer uld(ulocdata_open(locale.getName(), &status)); if (U_FAILURE(status)) { return; } UnicodeSet exemplars; ulocdata_getExemplarSet(uld.getAlias(), exemplars.toUSet(), 0, ULOCDATA_ES_INDEX, &status); if (U_SUCCESS(status)) { initialLabels_->addAll(exemplars); return; } status = U_ZERO_ERROR; // Clear out U_MISSING_RESOURCE_ERROR // The locale data did not include explicit Index characters. // Synthesize a set of them from the locale's standard exemplar characters. ulocdata_getExemplarSet(uld.getAlias(), exemplars.toUSet(), 0, ULOCDATA_ES_STANDARD, &status); if (U_FAILURE(status)) { return; } // question: should we add auxiliary exemplars? if (exemplars.containsSome(0x61, 0x7A) /* a-z */ || exemplars.size() == 0) { exemplars.add(0x61, 0x7A); } if (exemplars.containsSome(0xAC00, 0xD7A3)) { // Hangul syllables // cut down to small list exemplars.remove(0xAC00, 0xD7A3). add(0xAC00).add(0xB098).add(0xB2E4).add(0xB77C). add(0xB9C8).add(0xBC14).add(0xC0AC).add(0xC544). add(0xC790).add(0xCC28).add(0xCE74).add(0xD0C0). add(0xD30C).add(0xD558); } if (exemplars.containsSome(0x1200, 0x137F)) { // Ethiopic block // cut down to small list // make use of the fact that Ethiopic is allocated in 8's, where // the base is 0 mod 8. UnicodeSet ethiopic( UNICODE_STRING_SIMPLE("[[:Block=Ethiopic:]&[:Script=Ethiopic:]]"), status); UnicodeSetIterator it(ethiopic); while (it.next() && !it.isString()) { if ((it.getCodepoint() & 0x7) != 0) { exemplars.remove(it.getCodepoint()); } } } // Upper-case any that aren't already so. // (We only do this for synthesized index characters.) UnicodeSetIterator it(exemplars); UnicodeString upperC; while (it.next()) { const UnicodeString &exemplarC = it.getString(); upperC = exemplarC; upperC.toUpper(locale); initialLabels_->add(upperC); } }
UBool IcuTestErrorCode::logDataIfFailureAndReset(const char *fmt, ...) { if(isFailure()) { char buffer[4000]; va_list ap; va_start(ap, fmt); vsprintf(buffer, fmt, ap); va_end(ap); UnicodeString msg(testName, -1, US_INV); msg.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV)); msg.append(UNICODE_STRING_SIMPLE(" - ")).append(UnicodeString(buffer, -1, US_INV)); testClass.dataerrln(msg); reset(); return TRUE; } else { reset(); return FALSE; } }
void CollationRegressionTest::TestTrailingComment() { // ICU ticket #8070: // Check that the rule parser handles a comment without terminating end-of-line. IcuTestErrorCode errorCode(*this, "TestTrailingComment"); RuleBasedCollator coll(UNICODE_STRING_SIMPLE("&c<b#comment1\n<a#comment2"), errorCode); UnicodeString a((UChar)0x61), b((UChar)0x62), c((UChar)0x63); assertTrue("c<b", coll.compare(c, b) < 0); assertTrue("b<a", coll.compare(b, a) < 0); }