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


C++ StringPiece::length方法代码示例

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


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

示例1: SplitStringKeepEmpty

void SplitStringKeepEmpty(
    const StringPiece& full,
    const StringPiece& delim,
    std::vector<std::string>* result)
{
    // 单个字符的分隔符转调字符版本的分割函数,要快一些
    if (delim.length() == 1)
    {
        SplitStringKeepEmpty(full, delim[0], result);
        return;
    }

    result->clear();

    if (full.empty() || delim.empty())
        return;

    size_t prev_pos = 0;
    size_t pos;
    std::string token;
    while ((pos = full.find(delim, prev_pos)) != std::string::npos)
    {
        token.assign(full.data() + prev_pos, pos - prev_pos);
        result->push_back(token);
        prev_pos = pos + delim.length();
    }

    token.assign(full.data() + prev_pos, full.length() - prev_pos);
    result->push_back(token);
}
开发者ID:343829084,项目名称:toft,代码行数:30,代码来源:algorithm.cpp

示例2: compare

UCollationResult Collator::compareUTF8(const StringPiece &source,
                                       const StringPiece &target,
                                       UErrorCode &status) const {
    if(U_FAILURE(status)) {
        return UCOL_EQUAL;
    }
    UCharIterator sIter, tIter;
    uiter_setUTF8(&sIter, source.data(), source.length());
    uiter_setUTF8(&tIter, target.data(), target.length());
    return compare(sIter, tIter, status);
}
开发者ID:CucasLoon,项目名称:in-the-box,代码行数:11,代码来源:coll.cpp

示例3:

std::u16string utf8ToUtf16(const StringPiece& utf8) {
    ssize_t utf16Length = utf8_to_utf16_length(reinterpret_cast<const uint8_t*>(utf8.data()),
            utf8.length());
    if (utf16Length <= 0) {
        return {};
    }

    std::u16string utf16;
    utf16.resize(utf16Length);
    utf8_to_utf16(reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length(), &*utf16.begin());
    return utf16;
}
开发者ID:OchSept,项目名称:platform_frameworks_base,代码行数:12,代码来源:Util.cpp

示例4: returnId

/// Return the vocID of word "text" if it exist in the vocabulary
/// Otherwise return 0
IndexType C_IDVocabulary::returnId(const StringPiece &text) const {
	StringPiece stemmed(text);
	if (stem_len_ > 0) { //take first stem_len_ characters
	    stemmed = text.substr(stem_len_);
        } else if ((stem_len_ < 0) && (text.length() > -stem_len_)) {//take last stem_len_ characters
	   stemmed = text.substr(text.length() + stem_len_, -stem_len_);
	} //otherwise leave as it is

	WordId::const_iterator iter = word_id_.find(stemmed);

	if(iter == word_id_.end()) {
		return 0;
	} else {
		return iter->second;
	}
}
开发者ID:kpu,项目名称:SALM,代码行数:18,代码来源:_IDVocabulary.cpp

示例5:

// -------------------------------------
void
DigitList::set(const StringPiece &source, UErrorCode &status) {
    if (U_FAILURE(status)) {
        return;
    }

    // Figure out a max number of digits to use during the conversion, and
    // resize the number up if necessary.
    int32_t numDigits = source.length();
    if (numDigits > fContext.digits) {
        fContext.digits = numDigits;
        char *t = fStorage.resize(sizeof(decNumber) + numDigits, fStorage.getCapacity());
        if (t == NULL) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return;
        }
        fDecNumber = (decNumber *)fStorage.getAlias();
    }
        
    fContext.status = 0;
    uprv_decNumberFromString(fDecNumber, source.data(), &fContext);
    if ((fContext.status & DEC_Conversion_syntax) != 0) {
        status = U_DECIMAL_NUMBER_SYNTAX_ERROR;
    }
    fHaveDouble = FALSE;
}   
开发者ID:LittoCats,项目名称:OT_4010D,代码行数:27,代码来源:digitlst.cpp

示例6: DoSplitLines

void DoSplitLines(
    const StringPiece& full,
    std::vector<StringType>* result,
    bool keep_line_endling
)
{
    result->clear();
    size_t prev_pos = 0;
    size_t pos;
    StringType token;
    while ((pos = full.find('\n', prev_pos)) != std::string::npos)
    {
        token.assign(full.data() + prev_pos, pos - prev_pos + 1);
        if (!keep_line_endling)
            RemoveLineEnding(&token);
        result->push_back(token);
        prev_pos = pos + 1;
    }
    if (prev_pos < full.size())
    {
        token.assign(full.data() + prev_pos, full.length() - prev_pos);
        if (!keep_line_endling)
            RemoveLineEnding(&token);
        result->push_back(token);
    }
}
开发者ID:343829084,项目名称:toft,代码行数:26,代码来源:algorithm.cpp

示例7: BuildLookupTable

// For each character in characters_wanted, sets the index corresponding
// to the ASCII code of that character to 1 in table.  This is used by
// the m_find.*_of methods below to tell whether or not a character is in
// the lookup table in constant time.
// The argument `table' must be an array that is large enough to hold all
// the possible values of an unsigned char.  Thus it should be be declared
// as follows:
//   bool table[UCHAR_MAX + 1]
static inline void BuildLookupTable(const StringPiece& characters_wanted,
                                    bool* table) {
    const size_type length = characters_wanted.length();
    const char* const data = characters_wanted.data();
    for (size_type i = 0; i < length; ++i) {
        table[static_cast<unsigned char>(data[i])] = true;
    }
}
开发者ID:ChenglongChen,项目名称:mltk,代码行数:16,代码来源:string_piece.cpp

示例8:

void CaseMap::utf8ToUpper(
        const char *locale, uint32_t options,
        StringPiece src, ByteSink &sink, Edits *edits,
        UErrorCode &errorCode) {
    ucasemap_mapUTF8(
        ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
        src.data(), src.length(),
        ucasemap_internalUTF8ToUpper, sink, edits, errorCode);
}
开发者ID:MIPS,项目名称:external-icu,代码行数:9,代码来源:ucasemap.cpp

示例9: NativeDecimalFormat_parse

static jobject NativeDecimalFormat_parse(JNIEnv* env, jclass, jlong addr, jstring text,
        jobject position, jboolean parseBigDecimal) {

    static jmethodID gPP_getIndex = env->GetMethodID(JniConstants::parsePositionClass, "getIndex", "()I");
    static jmethodID gPP_setIndex = env->GetMethodID(JniConstants::parsePositionClass, "setIndex", "(I)V");
    static jmethodID gPP_setErrorIndex = env->GetMethodID(JniConstants::parsePositionClass, "setErrorIndex", "(I)V");

    ScopedJavaUnicodeString src(env, text);
    if (!src.valid()) {
      return NULL;
    }

    // make sure the ParsePosition is valid. Actually icu4c would parse a number
    // correctly even if the parsePosition is set to -1, but since the RI fails
    // for that case we have to fail too
    int parsePos = env->CallIntMethod(position, gPP_getIndex, NULL);
    if (parsePos < 0 || parsePos > env->GetStringLength(text)) {
        return NULL;
    }

    Formattable res;
    ParsePosition pp(parsePos);
    DecimalFormat* fmt = toDecimalFormat(addr);
    fmt->parse(src.unicodeString(), res, pp);

    if (pp.getErrorIndex() == -1) {
        env->CallVoidMethod(position, gPP_setIndex, pp.getIndex());
    } else {
        env->CallVoidMethod(position, gPP_setErrorIndex, pp.getErrorIndex());
        return NULL;
    }

    if (parseBigDecimal) {
        UErrorCode status = U_ZERO_ERROR;
        StringPiece str = res.getDecimalNumber(status);
        if (U_SUCCESS(status)) {
            int len = str.length();
            const char* data = str.data();
            if (strncmp(data, "NaN", 3) == 0 ||
                strncmp(data, "Inf", 3) == 0 ||
                strncmp(data, "-Inf", 4) == 0) {
                double resultDouble = res.getDouble(status);
                return doubleValueOf(env, resultDouble);
            }
            return newBigDecimal(env, data, len);
        }
        return NULL;
    }

    switch (res.getType()) {
        case Formattable::kDouble: return doubleValueOf(env, res.getDouble());
        case Formattable::kLong:   return longValueOf(env, res.getLong());
        case Formattable::kInt64:  return longValueOf(env, res.getInt64());
        default:                   return NULL;
    }
}
开发者ID:LeMaker,项目名称:android-actions,代码行数:56,代码来源:libcore_icu_NativeDecimalFormat.cpp

示例10: while

/**
 * Set the DigitList from a decimal number string.
 *
 * The incoming string _must_ be nul terminated, even though it is arriving
 * as a StringPiece because that is what the decNumber library wants.
 * We can get away with this for an internal function; it would not
 * be acceptable for a public API.
 */
void
DigitList::set(StringPiece source, UErrorCode &status, uint32_t /*fastpathBits*/) {
    if (U_FAILURE(status)) {
        return;
    }

#if 0
    if(fastpathBits==(kFastpathOk|kNoDecimal)) {
      int32_t size = source.size();
      const char *data = source.data();
      int64_t r = 0;
      int64_t m = 1;
      // fast parse
      while(size>0) {
        char ch = data[--size];
        if(ch=='+') {
          break;
        } else if(ch=='-') {
          r = -r;
          break;
        } else {
          int64_t d = ch-'0';
          //printf("CH[%d]=%c, %d, *=%d\n", size,ch, (int)d, (int)m);
          r+=(d)*m;
          m *= 10;
        }
      }
      //printf("R=%d\n", r);
      set(r);
    } else
#endif
        {
      // Figure out a max number of digits to use during the conversion, and
      // resize the number up if necessary.
      int32_t numDigits = source.length();
      if (numDigits > fContext.digits) {
        // fContext.digits == fStorage.getCapacity()
        decNumber *t = fStorage.resize(numDigits, fStorage.getCapacity());
        if (t == NULL) {
          status = U_MEMORY_ALLOCATION_ERROR;
          return;
        }
        fDecNumber = t;
        fContext.digits = numDigits;
      }

      fContext.status = 0;
      uprv_decNumberFromString(fDecNumber, source.data(), &fContext);
      if ((fContext.status & DEC_Conversion_syntax) != 0) {
        status = U_DECIMAL_NUMBER_SYNTAX_ERROR;
      }
    }
    internalClear();
}
开发者ID:TestOrgPleaseIgnore,项目名称:node,代码行数:62,代码来源:digitlst.cpp

示例11: Insert

void C_IDVocabulary::Insert(const StringPiece &word, IndexType id) {
	if (id_word_.size() < id) {
		id_word_.resize(id + 1);
	}
	char *&place = id_word_[id];
	if (place) {
		StringPiece existing(place);
		if (existing != word) {
      std::cerr << "Duplicate SALM vocab id " << id << ": " << existing << " and " << word << std::endl;
      abort();
		} else {
			return;
		}
	}
	place = new char[word.length() + 1];
	memcpy(place, word.data(), word.length());
	place[word.length()] = 0;
	std::pair<WordId::iterator, bool> result(word_id_.insert(make_pair(StringPiece(place, word.length()), id)));
	if (!result.second) {
    std::cerr << "SALM words " << word << " and " << result.first->second << " have the same id " << id << std::endl;
    abort();
	}
}
开发者ID:kpu,项目名称:SALM,代码行数:23,代码来源:_IDVocabulary.cpp

示例12: SysMultiByteToWide

	// Do not assert in this function since it is used by the asssertion code!
	std::wstring SysMultiByteToWide(const StringPiece& mb, uint32 code_page) {
		if (mb.empty())
			return std::wstring();

		int mb_length = static_cast<int>(mb.length());
		// Compute the length of the buffer.
		int charcount = MultiByteToWideChar(code_page, 0,
			mb.data(), mb_length, NULL, 0);
		if (charcount == 0)
			return std::wstring();

		std::wstring wide;
		wide.resize(charcount);
		MultiByteToWideChar(code_page, 0, mb.data(), mb_length, &wide[0], charcount);

		return wide;
	}
开发者ID:623442733,项目名称:cef,代码行数:18,代码来源:sys_string_conversions_win.cpp

示例13: JoinStrings

// This function merges a vector of string components
void JoinStrings(
    const std::vector<std::string>& components,
    const StringPiece& delim,
    std::string* result)
{
    size_t length = 0;

    for (std::vector<std::string>::const_iterator iter = components.begin();
         iter != components.end(); ++iter)
    {
        if (iter != components.begin())
        {
            length += delim.length();
        }
        length += iter->size();
    }
    result->reserve(length);
    return JoinStrings<std::vector<std::string>::const_iterator>(
        components.begin(), components.end(), delim, result);
}
开发者ID:343829084,项目名称:toft,代码行数:21,代码来源:algorithm.cpp

示例14: ReplaceFirst

// Replace the first "old" pattern with the "new" pattern in a string
std::string ReplaceFirst(
    const StringPiece& s,
    const StringPiece& oldsub,
    const StringPiece& newsub)
{
    if (oldsub.empty())
        return s.as_string();

    std::string res;
    std::string::size_type pos = s.find(oldsub);
    if (pos == std::string::npos)
        return s.as_string();
    else
    {
        res.append(s.data(), pos);
        res.append(newsub.data(), newsub.size());
        res.append(s.data() + pos + oldsub.size(), s.length() - pos - oldsub.size());
    }
    return res;
}
开发者ID:OpenSourceX,项目名称:toft,代码行数:21,代码来源:algorithm.cpp

示例15: ReplaceAll

// Replace all the "old" pattern with the "new" pattern in a string
std::string ReplaceAll(const StringPiece& s, const StringPiece& oldsub,
                       const StringPiece& newsub)
{
    if (oldsub.empty())
        return s.as_string();

    std::string res;
    std::string::size_type start_pos = 0;
    std::string::size_type pos;
    do {
        pos = s.find(oldsub, start_pos);
        if (pos == std::string::npos)
        {
            break;
        }
        res.append(s.data() + start_pos, pos - start_pos);
        res.append(newsub.data(), newsub.size());
        start_pos = pos + oldsub.size();
    } while (true);
    res.append(s.data() + start_pos, s.length() - start_pos);
    return res;
}
开发者ID:343829084,项目名称:toft,代码行数:23,代码来源:algorithm.cpp


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