BytesTrieDictLookup(const DictionaryTriePerfTest &perfTest) : DictLookup(perfTest), trie(NULL), noDict(FALSE) { IcuToolErrorCode errorCode("BytesTrieDictLookup()"); builder=new BytesTrieBuilder(errorCode); CharString str; const ULine *lines=perf.getCachedLines(); int32_t numLines=perf.getNumLines(); for(int32_t i=0; i<numLines; ++i) { // Skip comment lines (start with a character below 'A'). if(lines[i].name[0]<0x41) { continue; } if(!thaiWordToBytes(lines[i].name, lines[i].len, str.clear(), errorCode)) { fprintf(stderr, "thaiWordToBytes(): failed for word %ld (0-based)\n", (long)i); noDict=TRUE; break; } builder->add(str.toStringPiece(), 0, errorCode); } if(!noDict) { int32_t length=builder->buildStringPiece(USTRINGTRIE_BUILD_SMALL, errorCode).length(); printf("size of BytesTrie: %6ld bytes\n", (long)length); trie=builder->build(USTRINGTRIE_BUILD_SMALL, errorCode); } }
/** * Return a string form of this number. * Format is as defined by the decNumber library, for interchange of * decimal numbers. */ void DigitList::getDecimal(CharString &str, UErrorCode &status) { if (U_FAILURE(status)) { return; } // A decimal number in string form can, worst case, be 14 characters longer // than the number of digits. So says the decNumber library doc. int32_t maxLength = fDecNumber->digits + 14; int32_t capacity = 0; char *buffer = str.clear().getAppendBuffer(maxLength, 0, capacity, status); if (U_FAILURE(status)) { return; // Memory allocation error on growing the string. } U_ASSERT(capacity >= maxLength); uprv_decNumberToString(this->fDecNumber, buffer); U_ASSERT((int32_t)uprv_strlen(buffer) <= maxLength); str.append(buffer, -1, status); }
void PreparsedUCD::parseScriptExtensions(const char *s, UnicodeSet &scx, UErrorCode &errorCode) { if(U_FAILURE(errorCode)) { return; } scx.clear(); CharString scString; for(;;) { const char *scs; const char *scLimit=strchr(s, ' '); if(scLimit!=NULL) { scs=scString.clear().append(s, (int32_t)(scLimit-s), errorCode).data(); if(U_FAILURE(errorCode)) { return; } } else { scs=s; } int32_t script=pnames->getPropertyValueEnum(UCHAR_SCRIPT, scs); if(script==UCHAR_INVALID_CODE) { fprintf(stderr, "error in preparsed UCD: '%s' is not a valid script code on line %ld\n", scs, (long)lineNumber); errorCode=U_PARSE_ERROR; return; } else if(scx.contains(script)) { fprintf(stderr, "error in preparsed UCD: scx has duplicate '%s' codes on line %ld\n", scs, (long)lineNumber); errorCode=U_PARSE_ERROR; return; } else { scx.add(script); } if(scLimit!=NULL) { s=scLimit+1; } else { break; } } if(scx.isEmpty()) { fprintf(stderr, "error in preparsed UCD: empty scx= on line %ld\n", (long)lineNumber); errorCode=U_PARSE_ERROR; } }