int32_t SSearchTest::monkeyTestCase(UCollator *coll, const UnicodeString &testCase, const UnicodeString &pattern, const UnicodeString &altPattern, const char *name, const char *strength, uint32_t seed) { UErrorCode status = U_ZERO_ERROR; int32_t actualStart = -1, actualEnd = -1; //int32_t expectedStart = prefix.length(), expectedEnd = prefix.length() + altPattern.length(); int32_t expectedStart = -1, expectedEnd = -1; int32_t notFoundCount = 0; LocalUStringSearchPointer uss(usearch_openFromCollator(pattern.getBuffer(), pattern.length(), testCase.getBuffer(), testCase.length(), coll, NULL, // the break iterator &status)); // **** TODO: find *all* matches, not just first one **** simpleSearch(coll, testCase, 0, pattern, expectedStart, expectedEnd); usearch_search(uss.getAlias(), 0, &actualStart, &actualEnd, &status); if (expectedStart >= 0 && (actualStart != expectedStart || actualEnd != expectedEnd)) { errln("Search for <pattern> in <%s> failed: expected [%d, %d], got [%d, %d]\n" " strength=%s seed=%d", name, expectedStart, expectedEnd, actualStart, actualEnd, strength, seed); } if (expectedStart == -1 && actualStart == -1) { notFoundCount += 1; } // **** TODO: find *all* matches, not just first one **** simpleSearch(coll, testCase, 0, altPattern, expectedStart, expectedEnd); usearch_setPattern(uss.getAlias(), altPattern.getBuffer(), altPattern.length(), &status); usearch_search(uss.getAlias(), 0, &actualStart, &actualEnd, &status); if (expectedStart >= 0 && (actualStart != expectedStart || actualEnd != expectedEnd)) { errln("Search for <alt_pattern> in <%s> failed: expected [%d, %d], got [%d, %d]\n" " strength=%s seed=%d", name, expectedStart, expectedEnd, actualStart, actualEnd, strength, seed); } if (expectedStart == -1 && actualStart == -1) { notFoundCount += 1; } return notFoundCount; }
static jstring getDisplayTimeZoneNative(JNIEnv* env, jclass clazz, jstring zoneID, jboolean isDST, jint style, jstring localeID) { // Build TimeZone object const jchar* idChars = env->GetStringChars(zoneID, NULL); jint idLength = env->GetStringLength(zoneID); UnicodeString idString((UChar*)idChars, idLength); TimeZone* zone = TimeZone::createTimeZone(idString); env->ReleaseStringChars(zoneID, idChars); // Build Locale object (can we rely on zero termination of JNI result?) const char* localeChars = env->GetStringUTFChars(localeID, NULL); jint localeLength = env->GetStringLength(localeID); Locale locale = Locale::createFromName(localeChars); // Try to get the display name of the TimeZone according to the Locale UnicodeString buffer; zone->getDisplayName((UBool)isDST, (style == 0 ? TimeZone::SHORT : TimeZone::LONG), locale, buffer); const UChar* tempChars = buffer.getBuffer(); int tempLength = buffer.length(); jstring result = env->NewString((jchar*)tempChars, tempLength); env->ReleaseStringUTFChars(localeID, localeChars); // Clean up everything delete(zone); return result; }
int32_t MessagePattern::validateArgumentName(const UnicodeString &name) { if(!PatternProps::isIdentifier(name.getBuffer(), name.length())) { return UMSGPAT_ARG_NAME_NOT_VALID; } return parseArgNumber(name, 0, name.length()); }
/* {{{ intl_charFromString * faster than doing intl_convert_utf16_to_utf8(&res, &res_len, * from.getBuffer(), from.length(), &status), * but consumes more memory */ int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UErrorCode *status) { if (from.isBogus()) { return FAILURE; } //the number of UTF-8 code units is not larger than that of UTF-16 code //units * 3 + 1 for the terminator int32_t capacity = from.length() * 3 + 1; if (from.isEmpty()) { *res = (char*)emalloc(1); **res = '\0'; *res_len = 0; return SUCCESS; } *res = (char*)emalloc(capacity); *res_len = 0; //tbd const UChar *utf16buf = from.getBuffer(); int32_t actual_len; u_strToUTF8WithSub(*res, capacity - 1, &actual_len, utf16buf, from.length(), U_SENTINEL, NULL, status); if (U_FAILURE(*status)) { efree(*res); *res = NULL; return FAILURE; } (*res)[actual_len] = '\0'; *res_len = (int)actual_len; return SUCCESS; }
static jcharArray formatResult(JNIEnv* env, const UnicodeString &str, FieldPositionIterator* fpi, jobject fpIter) { jclass fieldPositionIteratorClass = env->FindClass( "com/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator"); static jmethodID gFPI_setData = env->GetMethodID( fieldPositionIteratorClass, "setData", "([I)V"); if (fpi != NULL) { int len = fpi->getData(NULL, 0); jintArray data = NULL; if (len) { data = env->NewIntArray(len); ScopedIntArrayRW ints(env, data); if (ints.get() == NULL) { return NULL; } fpi->getData(ints.get(), len); } env->CallVoidMethod(fpIter, gFPI_setData, data); } jcharArray result = env->NewCharArray(str.length()); if (result != NULL) { // by jshwang // env->SetCharArrayRegion(result, 0, str.length(), str.getBuffer()); env->SetCharArrayRegion(result, 0, str.length(), (jchar *) str.getBuffer()); } return result; }
void Target::setTargetString(const UnicodeString *target) { if (charBreakIterator != NULL) { ubrk_close(charBreakIterator); ucol_closeElements(elements); } targetString = target; if (targetString != NULL) { UErrorCode status = U_ZERO_ERROR; targetBuffer = targetString->getBuffer(); targetLength = targetString->length(); elements = ucol_openElements(coll, target->getBuffer(), target->length(), &status); ucol_forceHanImplicit(elements, &status); charBreakIterator = ubrk_open(UBRK_CHARACTER, ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status), targetBuffer, targetLength, &status); } else { targetBuffer = NULL; targetLength = 0; } }
/* {{{ intl_stringFromChar */ int intl_stringFromChar(UnicodeString &ret, char *str, size_t str_len, UErrorCode *status) { if(str_len > INT32_MAX) { *status = U_BUFFER_OVERFLOW_ERROR; ret.setToBogus(); return FAILURE; } //the number of UTF-16 code units is not larger than that of UTF-8 code //units, + 1 for the terminator int32_t capacity = (int32_t)str_len + 1; //no check necessary -- if NULL will fail ahead UChar *utf16 = ret.getBuffer(capacity); int32_t utf16_len = 0; *status = U_ZERO_ERROR; u_strFromUTF8WithSub(utf16, ret.getCapacity(), &utf16_len, str, str_len, U_SENTINEL /* no substitution */, NULL, status); ret.releaseBuffer(utf16_len); if (U_FAILURE(*status)) { ret.setToBogus(); return FAILURE; } return SUCCESS; }
static jcharArray formatResult(JNIEnv* env, const UnicodeString& s, FieldPositionIterator* fpi, jobject javaFieldPositionIterator) { static jmethodID gFPI_setData = env->GetMethodID(JniConstants::fieldPositionIteratorClass, "setData", "([I)V"); if (fpi != NULL) { std::vector<int32_t> data; FieldPosition fp; while (fpi->next(fp)) { data.push_back(fp.getField()); data.push_back(fp.getBeginIndex()); data.push_back(fp.getEndIndex()); } jintArray javaData = NULL; if (!data.empty()) { javaData = env->NewIntArray(data.size()); if (javaData == NULL) { return NULL; } ScopedIntArrayRW ints(env, javaData); if (ints.get() == NULL) { return NULL; } memcpy(ints.get(), &data[0], data.size() * sizeof(int32_t)); } env->CallVoidMethod(javaFieldPositionIterator, gFPI_setData, javaData); } jcharArray result = env->NewCharArray(s.length()); if (result != NULL) { env->SetCharArrayRegion(result, 0, s.length(), s.getBuffer()); } return result; }
static jstring ICU_getDisplayLanguageNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) { Locale loc = getLocale(env, locale); Locale targetLoc = getLocale(env, targetLocale); UnicodeString str; targetLoc.getDisplayLanguage(loc, str); return env->NewString(str.getBuffer(), str.length()); }
U_IO_API STD_OSTREAM & U_EXPORT2 operator<<(STD_OSTREAM& stream, const UnicodeString& str) { if(str.length() > 0) { char buffer[200]; UConverter *converter; UErrorCode errorCode = U_ZERO_ERROR; // use the default converter to convert chunks of text converter = u_getDefaultConverter(&errorCode); if(U_SUCCESS(errorCode)) { const UChar *us = str.getBuffer(); const UChar *uLimit = us + str.length(); char *s, *sLimit = buffer + (sizeof(buffer) - 1); do { errorCode = U_ZERO_ERROR; s = buffer; ucnv_fromUnicode(converter, &s, sLimit, &us, uLimit, 0, FALSE, &errorCode); *s = 0; // write this chunk if(s > buffer) { stream << buffer; } } while(errorCode == U_BUFFER_OVERFLOW_ERROR); u_releaseDefaultConverter(converter); } } /* stream.flush();*/ return stream; }
U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id) { char *str_id; size_t str_id_len; zend_long index; intl_error_reset(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &str_id, &str_id_len, &index) == FAILURE || index < (zend_long)INT32_MIN || index > (zend_long)INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_get_equivalent_id: bad arguments", 0); RETURN_FALSE; } UErrorCode status = UErrorCode(); UnicodeString id; if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) { intl_error_set(NULL, status, "intltz_get_equivalent_id: could not convert time zone id to UTF-16", 0); RETURN_FALSE; } const UnicodeString result = TimeZone::getEquivalentID(id, (int32_t)index); zend_string *u8str; u8str = intl_convert_utf16_to_utf8(result.getBuffer(), result.length(), &status); INTL_CHECK_STATUS(status, "intltz_get_equivalent_id: " "could not convert resulting time zone id to UTF-16"); RETVAL_NEW_STR(u8str); }
void TextItemizer::itemizeDirection(const UnicodeString &text, hb_direction_t overallDirection, vector<DirectionItem> &items) { /* * IF overallDirection IS UNDEFINED: THE PARAGRAPH-LEVEL WILL BE DETERMINED FROM THE TEXT * * SEE: http://www.icu-project.org/apiref/icu4c/ubidi_8h.html#abdfe9e113a19dd8521d3b7ac8220fe11 */ UBiDiLevel paraLevel = (overallDirection == HB_DIRECTION_INVALID) ? UBIDI_DEFAULT_LTR : ((overallDirection == HB_DIRECTION_RTL) ? 1 : 0); auto length = text.length(); UErrorCode error = U_ZERO_ERROR; UBiDi *bidi = ubidi_openSized(length, 0, &error); ubidi_setPara(bidi, text.getBuffer(), length, paraLevel, 0, &error); auto direction = ubidi_getDirection(bidi); if (direction != UBIDI_MIXED) { items.emplace_back(0, length, icuDirectionToHB(direction)); } else { auto count = ubidi_countRuns(bidi, &error); for (int i = 0; i < count; ++i) { int32_t start, length; direction = ubidi_getVisualRun(bidi, i, &start, &length); items.emplace_back(start, start + length, icuDirectionToHB(direction)); } } ubidi_close(bidi); }
static UnicodeString loadNumericDateFormatterPattern( const UResourceBundle *resource, const char *pattern, UErrorCode &status) { UnicodeString result; if (U_FAILURE(status)) { return result; } CharString chs; chs.append("durationUnits", status) .append("/", status).append(pattern, status); LocalUResourceBundlePointer patternBundle( ures_getByKeyWithFallback( resource, chs.data(), NULL, &status)); if (U_FAILURE(status)) { return result; } getString(patternBundle.getAlias(), result, status); // Replace 'h' with 'H' int32_t len = result.length(); UChar *buffer = result.getBuffer(len); for (int32_t i = 0; i < len; ++i) { if (buffer[i] == 0x68) { // 'h' buffer[i] = 0x48; // 'H' } } result.releaseBuffer(len); return result; }
void StringSearch::setText(const UnicodeString &text, UErrorCode &status) { if (U_SUCCESS(status)) { m_text_ = text; usearch_setText(m_strsrch_, text.getBuffer(), text.length(), &status); } }
/* Explain <xxxxx> tag to a native value * * Since <xxxxx> is always larger than the native value, * the operation will replace the tag directly in the buffer, * and, of course, will shift tail elements. */ void IdnaConfTest::ExplainCodePointTag(UnicodeString& buf){ buf.append((UChar)0); // add a terminal NULL UChar* bufBase = buf.getBuffer(buf.length()); UChar* p = bufBase; while (*p != 0){ if ( *p != 0x3C){ // < *bufBase++ = *p++; } else { p++; // skip < UChar32 cp = 0; for ( ;*p != 0x3E; p++){ // > if (0x30 <= *p && *p <= 0x39){ // 0-9 cp = (cp * 16) + (*p - 0x30); } else if (0x61 <= *p && *p <= 0x66){ // a-f cp = (cp * 16) + (*p - 0x61) + 10; } else if (0x41 <= *p && *p <= 0x46) {// A-F cp = (cp * 16) + (*p - 0x41) + 10; } // no else. hope everything is good. } p++; // skip > if (U_IS_BMP(cp)){ *bufBase++ = cp; } else { *bufBase++ = U16_LEAD(cp); *bufBase++ = U16_TRAIL(cp); } } } *bufBase = 0; // close our buffer buf.releaseBuffer(); }
status_t ICUCategoryData::_ConvertUnicodeStringToLocaleconvEntry( const UnicodeString& string, char* destination, int destinationSize, const char* defaultValue) { UConverter* converter; status_t result = _GetConverter(converter); if (result != B_OK) return result; UErrorCode icuStatus = U_ZERO_ERROR; ucnv_fromUChars(converter, destination, destinationSize, string.getBuffer(), string.length(), &icuStatus); if (!U_SUCCESS(icuStatus)) { switch (icuStatus) { case U_BUFFER_OVERFLOW_ERROR: result = B_NAME_TOO_LONG; break; case U_INVALID_CHAR_FOUND: case U_TRUNCATED_CHAR_FOUND: case U_ILLEGAL_CHAR_FOUND: result = B_BAD_DATA; break; default: result = B_ERROR; break; } strlcpy(destination, defaultValue, destinationSize); } return result; }
U_CAPI int32_t U_EXPORT2 uspoof_getSkeletonUTF8(const USpoofChecker *sc, uint32_t type, const char *id, int32_t length, char *dest, int32_t destCapacity, UErrorCode *status) { SpoofImpl::validateThis(sc, *status); if (U_FAILURE(*status)) { return 0; } if (length<-1 || destCapacity<0 || (destCapacity==0 && dest!=NULL)) { *status = U_ILLEGAL_ARGUMENT_ERROR; return 0; } UnicodeString srcStr = UnicodeString::fromUTF8(StringPiece(id, length>=0 ? length : uprv_strlen(id))); UnicodeString destStr; uspoof_getSkeletonUnicodeString(sc, type, srcStr, destStr, status); if (U_FAILURE(*status)) { return 0; } int32_t lengthInUTF8 = 0; u_strToUTF8(dest, destCapacity, &lengthInUTF8, destStr.getBuffer(), destStr.length(), status); return lengthInUTF8; }
U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id) { char *str_id; int str_id_len; long index; intl_error_reset(NULL TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &str_id, &str_id_len, &index) == FAILURE || index < (long)INT32_MIN || index > (long)INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_get_equivalent_id: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } UErrorCode status = UErrorCode(); UnicodeString id; if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) { intl_error_set(NULL, status, "intltz_get_equivalent_id: could not convert time zone id to UTF-16", 0 TSRMLS_CC); RETURN_FALSE; } const UnicodeString result = TimeZone::getEquivalentID(id, (int32_t)index); intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), result.getBuffer(), result.length(), &status); INTL_CHECK_STATUS(status, "intltz_get_equivalent_id: " "could not convert resulting time zone id to UTF-16"); Z_TYPE_P(return_value) = IS_STRING; }
void Normalizer2DataBuilder::setRoundTripMapping(UChar32 c, const UnicodeString &m) { if(U_IS_SURROGATE(c)) { fprintf(stderr, "error in gennorm2 phase %d: " "illegal round-trip mapping from surrogate code point U+%04lX\n", (int)phase, (long)c); exit(U_INVALID_FORMAT_ERROR); } if(!isWellFormed(m)) { fprintf(stderr, "error in gennorm2 phase %d: " "illegal round-trip mapping from U+%04lX to malformed string\n", (int)phase, (long)c); exit(U_INVALID_FORMAT_ERROR); } int32_t numCP=u_countChar32(m.getBuffer(), m.length()); if(numCP!=2) { fprintf(stderr, "error in gennorm2 phase %d: " "illegal round-trip mapping from U+%04lX to %d!=2 code points\n", (int)phase, (long)c, (int)numCP); exit(U_INVALID_FORMAT_ERROR); } Norm *p=checkNormForMapping(createNorm(c), c); p->mapping=new UnicodeString(m); p->mappingType=Norm::ROUND_TRIP; p->mappingCP=U_SENTINEL; }
void ReplaceableGlue::extractBetween(int32_t start, int32_t limit, UnicodeString & target) const { (*func->extract)(rep, start, limit, target.getBuffer(limit - start)); target.releaseBuffer(limit - start); }
StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr) : UCharCharacterIterator(textStr.getBuffer(), textStr.length()), text(textStr) { // we had set the input parameter's array, now we need to set our copy's array UCharCharacterIterator::text = this->text.getBuffer(); }
extern "C" jstring Java_libcore_icu_ICU_getDisplayVariantNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) { Locale loc = getLocale(env, locale); Locale targetLoc = getLocale(env, targetLocale); UnicodeString str; targetLoc.getDisplayVariant(loc, str); return env->NewString(str.getBuffer(), str.length()); }
U_I18N_API UnicodeString & U_EXPORT2 uspoof_getSkeletonUnicodeString(const USpoofChecker *sc, uint32_t type, const UnicodeString &s, UnicodeString &dest, UErrorCode *status) { if (U_FAILURE(*status)) { return dest; } dest.remove(); const UChar *str = s.getBuffer(); int32_t strLen = s.length(); UChar smallBuf[USPOOF_STACK_BUFFER_SIZE]; UChar *buf = smallBuf; int32_t outputSize = uspoof_getSkeleton(sc, type, str, strLen, smallBuf, USPOOF_STACK_BUFFER_SIZE, status); if (*status == U_BUFFER_OVERFLOW_ERROR) { buf = static_cast<UChar *>(uprv_malloc((outputSize+1)*sizeof(UChar))); if (buf == NULL) { *status = U_MEMORY_ALLOCATION_ERROR; return dest; } *status = U_ZERO_ERROR; uspoof_getSkeleton(sc, type, str, strLen, buf, outputSize+1, status); } if (U_SUCCESS(*status)) { dest.setTo(buf, outputSize); } if (buf != smallBuf) { uprv_free(buf); } return dest; }
Collator::EComparisonResult RuleBasedCollator::compare( const UnicodeString& source, const UnicodeString& target, int32_t length) const { UErrorCode status = U_ZERO_ERROR; return getEComparisonResult(compare(source.getBuffer(), uprv_min(length,source.length()), target.getBuffer(), uprv_min(length,target.length()), status)); }
void PreparsedUCD::parseString(const char *s, UnicodeString &uni, UErrorCode &errorCode) { UChar *buffer=uni.getBuffer(-1); int32_t length=u_parseString(s, buffer, uni.getCapacity(), NULL, &errorCode); if(errorCode==U_BUFFER_OVERFLOW_ERROR) { errorCode=U_ZERO_ERROR; uni.releaseBuffer(0); buffer=uni.getBuffer(length); length=u_parseString(s, buffer, uni.getCapacity(), NULL, &errorCode); } uni.releaseBuffer(length); if(U_FAILURE(errorCode)) { fprintf(stderr, "error in preparsed UCD: '%s' is not a valid Unicode string on line %ld\n", s, (long)lineNumber); } }
void CasePropsBuilder::makeUnfoldData(UErrorCode &errorCode) { if(U_FAILURE(errorCode)) { return; } UChar *p, *q; int32_t i, j, k; /* sort the data */ int32_t unfoldLength=unfold.length(); int32_t unfoldRows=unfoldLength/UGENCASE_UNFOLD_WIDTH-1; UChar *unfoldBuffer=unfold.getBuffer(-1); uprv_sortArray(unfoldBuffer+UGENCASE_UNFOLD_WIDTH, unfoldRows, UGENCASE_UNFOLD_WIDTH*2, compareUnfold, NULL, FALSE, &errorCode); /* make unique-string rows by merging adjacent ones' code point columns */ /* make p point to row i-1 */ p=unfoldBuffer+UGENCASE_UNFOLD_WIDTH; for(i=1; i<unfoldRows;) { if(0==u_memcmp(p, p+UGENCASE_UNFOLD_WIDTH, UGENCASE_UNFOLD_STRING_WIDTH)) { /* concatenate code point columns */ q=p+UGENCASE_UNFOLD_STRING_WIDTH; for(j=1; j<UGENCASE_UNFOLD_CP_WIDTH && q[j]!=0; ++j) {} for(k=0; k<UGENCASE_UNFOLD_CP_WIDTH && q[UGENCASE_UNFOLD_WIDTH+k]!=0; ++j, ++k) { q[j]=q[UGENCASE_UNFOLD_WIDTH+k]; } if(j>UGENCASE_UNFOLD_CP_WIDTH) { fprintf(stderr, "genprops error: too many code points in unfold[]: %ld>%d=UGENCASE_UNFOLD_CP_WIDTH\n", (long)j, UGENCASE_UNFOLD_CP_WIDTH); errorCode=U_BUFFER_OVERFLOW_ERROR; return; } /* move following rows up one */ --unfoldRows; u_memmove(p+UGENCASE_UNFOLD_WIDTH, p+UGENCASE_UNFOLD_WIDTH*2, (unfoldRows-i)*UGENCASE_UNFOLD_WIDTH); } else { p+=UGENCASE_UNFOLD_WIDTH; ++i; } } unfoldBuffer[UCASE_UNFOLD_ROWS]=(UChar)unfoldRows; if(beVerbose) { puts("unfold data:"); p=unfoldBuffer; for(i=0; i<unfoldRows; ++i) { p+=UGENCASE_UNFOLD_WIDTH; printf("[%2d] %04x %04x %04x <- %04x %04x\n", (int)i, p[0], p[1], p[2], p[3], p[4]); } } unfold.releaseBuffer((unfoldRows+1)*UGENCASE_UNFOLD_WIDTH); }
void font_face_set::get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format) { double avg_height = character_dimensions('X').height(); UErrorCode err = U_ZERO_ERROR; UnicodeString reordered; UnicodeString shaped; int32_t length = ustr.length(); UBiDi *bidi = ubidi_openSized(length, 0, &err); ubidi_setPara(bidi, ustr.getBuffer(), length, UBIDI_DEFAULT_LTR, 0, &err); ubidi_writeReordered(bidi, reordered.getBuffer(length), length, UBIDI_DO_MIRRORING, &err); reordered.releaseBuffer(length); u_shapeArabic(reordered.getBuffer(), length, shaped.getBuffer(length), length, U_SHAPE_LETTERS_SHAPE | U_SHAPE_LENGTH_FIXED_SPACES_NEAR | U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &err); shaped.releaseBuffer(length); if (U_SUCCESS(err)) { StringCharacterIterator iter(shaped); for (iter.setToStart(); iter.hasNext();) { UChar ch = iter.nextPostInc(); char_info char_dim = character_dimensions(ch); char_dim.format = format; char_dim.avg_height = avg_height; info.add_info(char_dim); } } #if (U_ICU_VERSION_MAJOR_NUM*100 + U_ICU_VERSION_MINOR_NUM >= 406) if (ubidi_getBaseDirection(ustr.getBuffer(), length) == UBIDI_RTL) { info.set_rtl(true); } #endif ubidi_close(bidi); }
/** * This method gets called when a function is found. * * @param const UnicodeString& namespace the fully qualified namespace of the function that was found * @param const UnicodeString& functionName the name of the method that was found * @param const UnicodeString& signature string containing method parameters. String is normalized, meaning that * any extra white space is removed, and every token is separated by one space only. ie. for the code * "public function doWork( $item1, $item2 ) " the signature will be "($item1, $item2)" * @param const UnicodeString& returnType the function's return type, as dictated by the PHPDoc comment * @param const UnicodeString& comment PHPDoc attached to the class * @param lineNumber the line number (1-based) that the function was found in */ virtual void FunctionFound(const UnicodeString& namespaceName, const UnicodeString& functionName, const UnicodeString& signature, const UnicodeString& returnType, const UnicodeString& comment, const int lineNumber) { UFILE* ufout = u_finit(stdout, NULL, NULL); if (returnType.isEmpty()) { u_fprintf(ufout, "Function Found: %.*S in namespace %.*S on line %d. Function Did not have @return in PHPDoc comment\n", functionName.length(), functionName.getBuffer(), namespaceName.length(), namespaceName.getBuffer(), lineNumber); } else { u_fprintf(ufout, "Function Found: %.*S in namespace %.*S on line %d and it returns %.*S\n", functionName.length(), functionName.getBuffer(), namespaceName.length(), namespaceName.getBuffer(), lineNumber, returnType.length(), returnType.getBuffer()); } u_fclose(ufout); }
CEList::CEList(UCollator *coll, const UnicodeString &string, UErrorCode &status) : ces(NULL), listMax(CELIST_BUFFER_SIZE), listSize(0) { UCollationElements *elems = ucol_openElements(coll, string.getBuffer(), string.length(), &status); UCollationStrength strength = ucol_getStrength(coll); UBool toShift = ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &status) == UCOL_SHIFTED; uint32_t variableTop = ucol_getVariableTop(coll, &status); uint32_t strengthMask = 0; int32_t order; if (U_FAILURE(status)) { return; } // **** only set flag if string has Han(gul) **** // ucol_forceHanImplicit(elems, &status); -- removed for ticket #10476 switch (strength) { default: strengthMask |= UCOL_TERTIARYORDERMASK; U_FALLTHROUGH; case UCOL_SECONDARY: strengthMask |= UCOL_SECONDARYORDERMASK; U_FALLTHROUGH; case UCOL_PRIMARY: strengthMask |= UCOL_PRIMARYORDERMASK; } ces = ceBuffer; while ((order = ucol_next(elems, &status)) != UCOL_NULLORDER) { UBool cont = isContinuation(order); order &= strengthMask; if (toShift && variableTop > (uint32_t)order && (order & UCOL_PRIMARYORDERMASK) != 0) { if (strength >= UCOL_QUATERNARY) { order &= UCOL_PRIMARYORDERMASK; } else { order = UCOL_IGNORABLE; } } if (order == UCOL_IGNORABLE) { continue; } if (cont) { order |= UCOL_CONTINUATION_MARKER; } add(order, status); } ucol_closeElements(elems); }
static jstring NativeNormalizer_normalizeImpl(JNIEnv* env, jclass, jstring s, jint intMode) { ScopedJavaUnicodeString src(env, s); UNormalizationMode mode = static_cast<UNormalizationMode>(intMode); UErrorCode status = U_ZERO_ERROR; UnicodeString dst; Normalizer::normalize(src.unicodeString(), mode, 0, dst, status); maybeThrowIcuException(env, status); return dst.isBogus() ? NULL : env->NewString(dst.getBuffer(), dst.length()); }