当前位置: 首页>>代码示例>>C++>>正文


C++ UnicodeString::getBuffer方法代码示例

本文整理汇总了C++中UnicodeString::getBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ UnicodeString::getBuffer方法的具体用法?C++ UnicodeString::getBuffer怎么用?C++ UnicodeString::getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnicodeString的用法示例。


在下文中一共展示了UnicodeString::getBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: monkeyTestCase

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;
}
开发者ID:Acorld,项目名称:WinObjC-Heading,代码行数:48,代码来源:ssearch.cpp

示例2: getDisplayTimeZoneNative

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;
}
开发者ID:llnull,项目名称:platform_dalvik,代码行数:28,代码来源:ResourceInterface.cpp

示例3: parseArgNumber

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());
}
开发者ID:00zhengfu00,项目名称:third_party,代码行数:7,代码来源:messagepattern.cpp

示例4: intl_charFromString

/* {{{ 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;
}
开发者ID:0,项目名称:php-src,代码行数:39,代码来源:intl_convertcpp.cpp

示例5: setTargetString

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;
    }
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:25,代码来源:bmsearch.cpp

示例6: intl_stringFromChar

/* {{{ 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;
}
开发者ID:0xhacking,项目名称:php-src,代码行数:26,代码来源:intl_convertcpp.cpp

示例7: formatResult

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;
}
开发者ID:LeMaker,项目名称:android-actions,代码行数:33,代码来源:libcore_icu_NativeDecimalFormat.cpp

示例8: ICU_getDisplayLanguageNative

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());
}
开发者ID:TeamNyx,项目名称:libcore,代码行数:7,代码来源:libcore_icu_ICU.cpp

示例9: while

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;
}
开发者ID:servo,项目名称:mozjs,代码行数:32,代码来源:ustream.cpp

示例10: PHP_FUNCTION

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);
}
开发者ID:GreenLightt,项目名称:php-src,代码行数:31,代码来源:timezone_methods.cpp

示例11: itemizeDirection

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);
}
开发者ID:SlateScience,项目名称:Unicode,代码行数:34,代码来源:TextItemizer.cpp

示例12: loadNumericDateFormatterPattern

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;
}
开发者ID:winlibs,项目名称:icu4c,代码行数:32,代码来源:measfmt.cpp

示例13: setText

void StringSearch::setText(const UnicodeString &text, UErrorCode &status)
{
    if (U_SUCCESS(status)) {
        m_text_ = text;
        usearch_setText(m_strsrch_, text.getBuffer(), text.length(), &status);
    }
}
开发者ID:gitpan,项目名称:ponie,代码行数:7,代码来源:stsearch.cpp

示例14: ExplainCodePointTag

/* 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();
}
开发者ID:winlibs,项目名称:icu4c,代码行数:38,代码来源:idnaconf.cpp

示例15:

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;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:32,代码来源:ICUCategoryData.cpp


注:本文中的UnicodeString::getBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。