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


C++ Replaceable类代码示例

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


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

示例1: transliterate

/**
 * Transliterate the given text with the given UTransPosition
 * indices.  Return TRUE if the transliteration should continue
 * or FALSE if it should halt (because of a U_PARTIAL_MATCH match).
 * Note that FALSE is only ever returned if isIncremental is TRUE.
 * @param text the text to be transliterated
 * @param pos the position indices, which will be updated
 * @param incremental if TRUE, assume new text may be inserted
 * at index.limit, and return FALSE if thre is a partial match.
 * @return TRUE unless a U_PARTIAL_MATCH has been obtained,
 * indicating that transliteration should stop until more text
 * arrives.
 */
UBool TransliterationRuleSet::transliterate(Replaceable & text,
        UTransPosition & pos,
        UBool incremental)
{
	int16_t indexByte = (int16_t)(text.char32At(pos.start) & 0xFF);
	for (int32_t i = index[indexByte]; i < index[indexByte + 1]; ++i)
	{
		UMatchDegree m = rules[i]->matchAndReplace(text, pos, incremental);
		switch (m)
		{
		case U_MATCH:
			_debugOut("match", rules[i], text, pos);
			return TRUE;
		case U_PARTIAL_MATCH:
			_debugOut("partial match", rules[i], text, pos);
			return FALSE;
		default: /* Ram: added default to make GCC happy */
			break;
		}
	}
	// No match or partial match from any rule
	pos.start += UTF_CHAR_LENGTH(text.char32At(pos.start));
	_debugOut("no match", NULL, text, pos);
	return TRUE;
}
开发者ID:Botyto,项目名称:Core,代码行数:38,代码来源:rbt_set.cpp

示例2: replaceableAsString

//
//   replaceableAsString   Hack to let break iterators work
//                         on the replaceable text from transliterators.
//                         In practice, the only real Replaceable type that we
//                         will be seeing is UnicodeString, so this function
//                         will normally be efficient.
//
UnicodeString BreakTransliterator::replaceableAsString(Replaceable &r) {
    if (r.getDynamicClassID() == UnicodeString::getStaticClassID()) {
        return (UnicodeString &) r;
    }
    UnicodeString s;
    r.extractBetween(0, r.length(), s);
    return s;
}
开发者ID:CucasLoon,项目名称:in-the-box,代码行数:15,代码来源:brktrans.cpp

示例3: replaceableAsString

//
//   replaceableAsString   Hack to let break iterators work
//                         on the replaceable text from transliterators.
//                         In practice, the only real Replaceable type that we
//                         will be seeing is UnicodeString, so this function
//                         will normally be efficient.
//
UnicodeString BreakTransliterator::replaceableAsString(Replaceable &r) {
    UnicodeString s;
    UnicodeString *rs = dynamic_cast<UnicodeString *>(&r);
    if (rs != NULL) {
        s = *rs;
    } else {
        r.extractBetween(0, r.length(), s);
    }
    return s;
}
开发者ID:00zhengfu00,项目名称:third_party,代码行数:17,代码来源:brktrans.cpp

示例4: handleTransliterate

/**
 * Implements {@link Transliterator#handleTransliterate}.
 * Ignore isIncremental since we don't need the context, and
 * we work on codepoints.
 */
void UnicodeNameTransliterator::handleTransliterate(Replaceable & text, UTransPosition & offsets,
        UBool /*isIncremental*/) const
{
	// The failure mode, here and below, is to behave like Any-Null,
	// if either there is no name data (max len == 0) or there is no
	// memory (malloc() => NULL).

	int32_t maxLen = uprv_getMaxCharNameLength();
	if (maxLen == 0)
	{
		offsets.start = offsets.limit;
		return;
	}

	// Accomodate the longest possible name plus padding
	char * buf = (char *) uprv_malloc(maxLen);
	if (buf == NULL)
	{
		offsets.start = offsets.limit;
		return;
	}

	int32_t cursor = offsets.start;
	int32_t limit = offsets.limit;

	UnicodeString str(FALSE, OPEN_DELIM, OPEN_DELIM_LEN);
	UErrorCode status;
	int32_t len;

	while (cursor < limit)
	{
		UChar32 c = text.char32At(cursor);
		int32_t clen = UTF_CHAR_LENGTH(c);
		status = U_ZERO_ERROR;
		if ((len = u_charName(c, U_EXTENDED_CHAR_NAME, buf, maxLen, &status)) > 0 && !U_FAILURE(status))
		{
			str.truncate(OPEN_DELIM_LEN);
			str.append(UnicodeString(buf, len, US_INV)).append(CLOSE_DELIM);
			text.handleReplaceBetween(cursor, cursor + clen, str);
			len += OPEN_DELIM_LEN + 1; // adjust for delimiters
			cursor += len; // advance cursor and adjust for new text
			limit += len - clen; // change in length
		}
		else
		{
			cursor += clen;
		}
	}

	offsets.contextLimit += limit - offsets.limit;
	offsets.limit = limit;
	offsets.start = cursor;

	uprv_free(buf);
}
开发者ID:Botyto,项目名称:Core,代码行数:60,代码来源:uni2name.cpp

示例5: handleTransliterate

/**
 * Implements {@link Transliterator#handleTransliterate}.
 */
void CaseMapTransliterator::handleTransliterate(Replaceable& text,
                                 UTransPosition& offsets, 
                                 UBool isIncremental) const
{
    if (offsets.start >= offsets.limit) {
        return;
    }

    UCaseContext csc;
    uprv_memset(&csc, 0, sizeof(csc));
    csc.p = &text;
    csc.start = offsets.contextStart;
    csc.limit = offsets.contextLimit;

    UnicodeString tmp;
    const UChar *s;
    UChar32 c;
    int32_t textPos, delta, result, locCache=0;

    for(textPos=offsets.start; textPos<offsets.limit;) {
        csc.cpStart=textPos;
        c=text.char32At(textPos);
        csc.cpLimit=textPos+=U16_LENGTH(c);

        result=fMap(fCsp, c, utrans_rep_caseContextIterator, &csc, &s, "", &locCache);

        if(csc.b1 && isIncremental) {
            // fMap() tried to look beyond the context limit
            // wait for more input
            offsets.start=csc.cpStart;
            return;
        }

        if(result>=0) {
            // replace the current code point with its full case mapping result
            // see UCASE_MAX_STRING_LENGTH
            if(result<=UCASE_MAX_STRING_LENGTH) {
                // string s[result]
                tmp.setTo(FALSE, s, result);
                delta=result-U16_LENGTH(c);
            } else {
                // single code point
                tmp.setTo(result);
                delta=tmp.length()-U16_LENGTH(c);
            }
            text.handleReplaceBetween(csc.cpStart, textPos, tmp);
            if(delta!=0) {
                textPos+=delta;
                csc.limit=offsets.contextLimit+=delta;
                offsets.limit+=delta;
            }
        }
    }
    offsets.start=textPos;
}
开发者ID:Katarzynasrom,项目名称:patch-hosting-for-android-x86-support,代码行数:58,代码来源:casetrn.cpp

示例6: handleTransliterate

/**
 * Implements {@link Transliterator#handleTransliterate}.
 */
void EscapeTransliterator::handleTransliterate(Replaceable & text,
        UTransPosition & pos,
        UBool /*isIncremental*/) const
{
	/* TODO: Verify that isIncremental can be ignored */
	int32_t start = pos.start;
	int32_t limit = pos.limit;

	UnicodeString buf(prefix);
	int32_t prefixLen = prefix.length();
	UBool redoPrefix = FALSE;

	while (start < limit)
	{
		int32_t c = grokSupplementals ? text.char32At(start) : text.charAt(start);
		int32_t charLen = grokSupplementals ? UTF_CHAR_LENGTH(c) : 1;

		if ((c & 0xFFFF0000) != 0 && supplementalHandler != NULL)
		{
			buf.truncate(0);
			buf.append(supplementalHandler->prefix);
			ICU_Utility::appendNumber(buf, c, supplementalHandler->radix,
			                          supplementalHandler->minDigits);
			buf.append(supplementalHandler->suffix);
			redoPrefix = TRUE;
		}
		else
		{
			if (redoPrefix)
			{
				buf.truncate(0);
				buf.append(prefix);
				redoPrefix = FALSE;
			}
			else
			{
				buf.truncate(prefixLen);
			}
			ICU_Utility::appendNumber(buf, c, radix, minDigits);
			buf.append(suffix);
		}

		text.handleReplaceBetween(start, start + charLen, buf);
		start += buf.length();
		limit += buf.length() - charLen;
	}

	pos.contextLimit += limit - pos.limit;
	pos.limit = limit;
	pos.start = start;
}
开发者ID:Botyto,项目名称:Core,代码行数:54,代码来源:esctrn.cpp

示例7: handleTransliterate

void UnaccentTransliterator::handleTransliterate(Replaceable& text,
                                                 UTransPosition& index,
                                                 UBool incremental) const {
    UnicodeString str("a");
    while (index.start < index.limit) {
        UChar c = text.charAt(index.start);
        UChar d = unaccent(c);
        if (c != d) {
            str.setCharAt(0, d);
            text.handleReplaceBetween(index.start, index.start+1, str);
        }
        index.start++;
    }
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:14,代码来源:unaccent.cpp

示例8: handleTransliterate

/**
 * Implements {@link Transliterator#handleTransliterate}.
 */
void BreakTransliterator::handleTransliterate(Replaceable & text, UTransPosition & offsets,
        UBool isIncremental) const
{

	UErrorCode status = U_ZERO_ERROR;
	boundaries->removeAllElements();
	BreakTransliterator * nonConstThis = (BreakTransliterator *)this;
	nonConstThis->getBreakIterator(); // Lazy-create it if necessary
	UnicodeString sText = replaceableAsString(text);
	bi->setText(sText);
	bi->preceding(offsets.start);

	// To make things much easier, we will stack the boundaries, and then insert at the end.
	// generally, we won't need too many, since we will be filtered.

	int32_t boundary;
	for (boundary = bi->next(); boundary != UBRK_DONE && boundary < offsets.limit; boundary = bi->next())
	{
		if (boundary == 0) { continue; }
		// HACK: Check to see that preceeding item was a letter

		UChar32 cp = sText.char32At(boundary - 1);
		int type = u_charType(cp);
		//System.out.println(Integer.toString(cp,16) + " (before): " + type);
		if ((U_MASK(type) & (U_GC_L_MASK | U_GC_M_MASK)) == 0) { continue; }

		cp = sText.char32At(boundary);
		type = u_charType(cp);
		//System.out.println(Integer.toString(cp,16) + " (after): " + type);
		if ((U_MASK(type) & (U_GC_L_MASK | U_GC_M_MASK)) == 0) { continue; }

		boundaries->addElement(boundary, status);
		// printf("Boundary at %d\n", boundary);
	}

	int delta = 0;
	int lastBoundary = 0;

	if (boundaries->size() != 0)   // if we found something, adjust
	{
		delta = boundaries->size() * fInsertion.length();
		lastBoundary = boundaries->lastElementi();

		// we do this from the end backwards, so that we don't have to keep updating.

		while (boundaries->size() > 0)
		{
			boundary = boundaries->popi();
			text.handleReplaceBetween(boundary, boundary, fInsertion);
		}
	}

	// Now fix up the return values
	offsets.contextLimit += delta;
	offsets.limit += delta;
	offsets.start = isIncremental ? lastBoundary + delta : offsets.limit;

	// TODO:  do something with U_FAILURE(status);
	//        (need to look at transliterators overall, not just here.)
}
开发者ID:Botyto,项目名称:Core,代码行数:63,代码来源:brktrans.cpp

示例9: finishTransliteration

void Transliterator::finishTransliteration(Replaceable& text,
                                           UTransPosition& index) const {
    if (!positionIsValid(index, text.length())) {
        return;
    }

    filteredTransliterate(text, index, FALSE, TRUE);
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:8,代码来源:translit.cpp

示例10: uiter_setReplaceable

/**
 * Implements {@link Transliterator#handleTransliterate}.
 */
void UppercaseTransliterator::handleTransliterate(Replaceable& text,
                                 UTransPosition& offsets, 
                                 UBool isIncremental) const {
    int32_t textPos = offsets.start;
    if (textPos >= offsets.limit) return;

    // get string for context
    
    UnicodeString original;
    text.extractBetween(offsets.contextStart, offsets.contextLimit, original);
    
    UCharIterator iter;
    uiter_setReplaceable(&iter, &text);
    iter.start = offsets.contextStart;
    iter.limit = offsets.contextLimit;
            
    // Walk through original string
    // If there is a case change, modify corresponding position in replaceable
    
    int32_t i = textPos - offsets.contextStart;
    int32_t limit = offsets.limit - offsets.contextStart;
    UChar32 cp;
    int32_t oldLen;
    
    for (; i < limit; ) {
        UTF_GET_CHAR(original.getBuffer(), 0, i, original.length(), cp);
        oldLen = UTF_CHAR_LENGTH(cp);
        i += oldLen;
        iter.index = i; // Point _past_ current char
        int32_t newLen = u_internalToUpper(cp, &iter, buffer, u_getMaxCaseExpansion(), loc.getName());
        if (newLen >= 0) {
            UnicodeString temp(buffer, newLen);
            text.handleReplaceBetween(textPos, textPos + oldLen, temp);
            if (newLen != oldLen) {
                textPos += newLen;
                offsets.limit += newLen - oldLen;
                offsets.contextLimit += newLen - oldLen;
                continue;
            }
        }
        textPos += oldLen;
    }
    offsets.start = offsets.limit;
}
开发者ID:gitpan,项目名称:ponie,代码行数:47,代码来源:toupptrn.cpp

示例11: replace

/**
 * UnicodeReplacer API
 */
int32_t StringMatcher::replace(Replaceable& text,
                               int32_t start,
                               int32_t limit,
                               int32_t& /*cursor*/) {
    
    int32_t outLen = 0;
    
    // Copy segment with out-of-band data
    int32_t dest = limit;
    // If there was no match, that means that a quantifier
    // matched zero-length.  E.g., x (a)* y matched "xy".
    if (matchStart >= 0) {
        if (matchStart != matchLimit) {
            text.copy(matchStart, matchLimit, dest);
            outLen = matchLimit - matchStart;
        }
    }
    
    text.handleReplaceBetween(start, limit, EMPTY); // delete original text
    
    return outLen;
}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:25,代码来源:strmatch.cpp

示例12: transliterate

int32_t Transliterator::transliterate(Replaceable& text,
                                      int32_t start, int32_t limit) const {
    if (start < 0 ||
        limit < start ||
        text.length() < limit) {
        return -1;
    }

    UTransPosition offsets;
    offsets.contextStart= start;
    offsets.contextLimit = limit;
    offsets.start = start;
    offsets.limit = limit;
    filteredTransliterate(text, offsets, FALSE, TRUE);
    return offsets.limit;
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:16,代码来源:translit.cpp

示例13: matches

/**
 * Implement UnicodeMatcher
 */
UMatchDegree StringMatcher::matches(const Replaceable& text,
                                    int32_t& offset,
                                    int32_t limit,
                                    UBool incremental) {
    int32_t i;
    int32_t cursor = offset;
    if (limit < cursor) {
        // Match in the reverse direction
        for (i=pattern.length()-1; i>=0; --i) {
            UChar keyChar = pattern.charAt(i);
            UnicodeMatcher* subm = data->lookupMatcher(keyChar);
            if (subm == 0) {
                if (cursor > limit &&
                    keyChar == text.charAt(cursor)) {
                    --cursor;
                } else {
                    return U_MISMATCH;
                }
            } else {
                UMatchDegree m =
                    subm->matches(text, cursor, limit, incremental);
                if (m != U_MATCH) {
                    return m;
                }
            }
        }
        // Record the match position, but adjust for a normal
        // forward start, limit, and only if a prior match does not
        // exist -- we want the rightmost match.
        if (matchStart < 0) {
            matchStart = cursor+1;
            matchLimit = offset+1;
        }
    } else {
        for (i=0; i<pattern.length(); ++i) {
            if (incremental && cursor == limit) {
                // We've reached the context limit without a mismatch and
                // without completing our match.
                return U_PARTIAL_MATCH;
            }
            UChar keyChar = pattern.charAt(i);
            UnicodeMatcher* subm = data->lookupMatcher(keyChar);
            if (subm == 0) {
                // Don't need the cursor < limit check if
                // incremental is TRUE (because it's done above); do need
                // it otherwise.
                if (cursor < limit &&
                    keyChar == text.charAt(cursor)) {
                    ++cursor;
                } else {
                    return U_MISMATCH;
                }
            } else {
                UMatchDegree m =
                    subm->matches(text, cursor, limit, incremental);
                if (m != U_MATCH) {
                    return m;
                }
            }
        }
        // Record the match position
        matchStart = offset;
        matchLimit = cursor;
    }

    offset = cursor;
    return U_MATCH;
}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:71,代码来源:strmatch.cpp

示例14: handleTransliterate

/**
 * Implements {@link Transliterator#handleTransliterate}.
 */
void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
                                                    UBool isIncremental) const {
    // The failure mode, here and below, is to behave like Any-Null,
    // if either there is no name data (max len == 0) or there is no
    // memory (malloc() => NULL).

    int32_t maxLen = uprv_getMaxCharNameLength();
    if (maxLen == 0) {
        offsets.start = offsets.limit;
        return;
    }

    // Accomodate the longest possible name
    ++maxLen; // allow for temporary trailing space
    char* cbuf = (char*) uprv_malloc(maxLen);
    if (cbuf == NULL) {
        offsets.start = offsets.limit;
        return;
    }

    UnicodeString openPat(TRUE, OPEN, -1);
    UnicodeString str, name;

    int32_t cursor = offsets.start;
    int32_t limit = offsets.limit;

    // Modes:
    // 0 - looking for open delimiter
    // 1 - after open delimiter
    int32_t mode = 0;
    int32_t openPos = -1; // open delim candidate pos

    UChar32 c;
    while (cursor < limit) {
        c = text.char32At(cursor);

        switch (mode) {
        case 0: // looking for open delimiter
            if (c == OPEN_DELIM) { // quick check first
                openPos = cursor;
                int32_t i =
                    ICU_Utility::parsePattern(openPat, text, cursor, limit);
                if (i >= 0 && i < limit) {
                    mode = 1;
                    name.truncate(0);
                    cursor = i;
                    continue; // *** reprocess char32At(cursor)
                }
            }
            break;

        case 1: // after open delimiter
            // Look for legal chars.  If \s+ is found, convert it
            // to a single space.  If closeDelimiter is found, exit
            // the loop.  If any other character is found, exit the
            // loop.  If the limit is reached, exit the loop.

            // Convert \s+ => SPACE.  This assumes there are no
            // runs of >1 space characters in names.
            if (PatternProps::isWhiteSpace(c)) {
                // Ignore leading whitespace
                if (name.length() > 0 &&
                    name.charAt(name.length()-1) != SPACE) {
                    name.append(SPACE);
                    // If we are too long then abort.  maxLen includes
                    // temporary trailing space, so use '>'.
                    if (name.length() > maxLen) {
                        mode = 0;
                    }
                }
                break;
            }

            if (c == CLOSE_DELIM) {
                int32_t len = name.length();

                // Delete trailing space, if any
                if (len > 0 &&
                    name.charAt(len-1) == SPACE) {
                    --len;
                }

                if (uprv_isInvariantUString(name.getBuffer(), len)) {
                    name.extract(0, len, cbuf, maxLen, US_INV);

                    UErrorCode status = U_ZERO_ERROR;
                    c = u_charFromName(U_EXTENDED_CHAR_NAME, cbuf, &status);
                    if (U_SUCCESS(status)) {
                        // Lookup succeeded

                        // assert(U16_LENGTH(CLOSE_DELIM) == 1);
                        cursor++; // advance over CLOSE_DELIM

                        str.truncate(0);
                        str.append(c);
                        text.handleReplaceBetween(openPos, cursor, str);

//.........这里部分代码省略.........
开发者ID:DavidCai1993,项目名称:node,代码行数:101,代码来源:name2uni.cpp

示例15: uiter_setReplaceable

void NormalizationTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
                                                      UBool isIncremental) const {
    // start and limit of the input range
    int32_t start = offsets.start;
    int32_t limit = offsets.limit;
    int32_t length, delta;

    if(start >= limit) {
        return;
    }

    // a C code unit iterator, implemented around the Replaceable
    UCharIterator iter;
    uiter_setReplaceable(&iter, &text);

    // the output string and buffer pointer
    UnicodeString output;
    UChar *buffer;
    UBool neededToNormalize;

    UErrorCode errorCode;

    /*
     * Normalize as short chunks at a time as possible even in
     * bulk mode, so that styled text is minimally disrupted.
     * In incremental mode, a chunk that ends with offsets.limit
     * must not be normalized.
     *
     * If it was known that the input text is not styled, then
     * a bulk mode normalization could look like this:
     *

    UChar staticChars[256];
    UnicodeString input;

    length = limit - start;
    input.setTo(staticChars, 0, sizeof(staticChars)/U_SIZEOF_UCHAR); // writable alias

    _Replaceable_extractBetween(text, start, limit, input.getBuffer(length));
    input.releaseBuffer(length);

    UErrorCode status = U_ZERO_ERROR;
    Normalizer::normalize(input, fMode, options, output, status);

    text.handleReplaceBetween(start, limit, output);

    int32_t delta = output.length() - length;
    offsets.contextLimit += delta;
    offsets.limit += delta;
    offsets.start = limit + delta;

     *
     */
    while(start < limit) {
        // set the iterator limits for the remaining input range
        // this is a moving target because of the replacements in the text object
        iter.start = iter.index = start;
        iter.limit = limit;

        // incrementally normalize a small chunk of the input
        buffer = output.getBuffer(-1);
        errorCode = U_ZERO_ERROR;
        length = unorm_next(&iter, buffer, output.getCapacity(),
                            fMode, 0,
                            TRUE, &neededToNormalize,
                            &errorCode);
        output.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);

        if(errorCode == U_BUFFER_OVERFLOW_ERROR) {
            // use a larger output string buffer and do it again from the start
            iter.index = start;
            buffer = output.getBuffer(length);
            errorCode = U_ZERO_ERROR;
            length = unorm_next(&iter, buffer, output.getCapacity(),
                                fMode, 0,
                                TRUE, &neededToNormalize,
                                &errorCode);
            output.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
        }

        if(U_FAILURE(errorCode)) {
            break;
        }

        limit = iter.index;
        if(isIncremental && limit == iter.limit) {
            // stop in incremental mode when we reach the input limit
            // in case there are additional characters that could change the
            // normalization result

            // UNLESS all characters in the result of the normalization of
            // the last run are in the skippable set
            const UChar *s=output.getBuffer();
            int32_t i=0, outLength=output.length();
            UChar32 c;

            while(i<outLength) {
                U16_NEXT(s, i, outLength, c);
                if(!unorm_isNFSkippable(c, fMode)) {
                    outLength=-1; // I wish C++ had labeled loops and break outer; ...
//.........这里部分代码省略.........
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:101,代码来源:nortrans.cpp


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