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


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

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


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

示例1: if

size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
                                 const StringPiece& needles) {
    if (UNLIKELY(needles.empty() || haystack.empty())) {
        return StringPiece::npos;
    } else if (needles.size() <= 16) {
        // we can save some unnecessary load instructions by optimizing for
        // the common case of needles.size() <= 16
        return qfind_first_byte_of_needles16(haystack, needles);
    }

    size_t index = haystack.size();
    for (size_t i = 0; i < haystack.size(); i += 16) {
        size_t b = 16;
        auto arr1 = __builtin_ia32_loaddqu(haystack.data() + i);
        for (size_t j = 0; j < needles.size(); j += 16) {
            auto arr2 = __builtin_ia32_loaddqu(needles.data() + j);
            auto index = __builtin_ia32_pcmpestri128(arr2, needles.size() - j,
                         arr1, haystack.size() - i, 0);
            b = std::min<size_t>(index, b);
        }
        if (b < 16) {
            return i + b;
        }
    };
    return StringPiece::npos;
}
开发者ID:beride,项目名称:hiphop-php,代码行数:26,代码来源:Range.cpp

示例2: 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

示例3: 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

示例4: WriteRecord

bool LocalSequenceFileWriter::WriteRecord(const StringPiece& key, const StringPiece& value) {
    int record_size = key.size() + value.size();
    int key_len = key.size();
    int int_len = sizeof(int);
    int size = 2 * int_len + record_size;
    int used_bytes = 0;
    scoped_array<char> data(new char[size]);

    if (m_records_written_after_sync >= kSyncInterval) {
        size += int_len + SYNC_HASH_SIZE;
        data.reset(new char[size]);
        used_bytes += WriteSyncToBuf(data.get() + used_bytes);
        m_records_written_after_sync = 0;
    }

    // format:
    // record_size|key_len|key|value

    used_bytes += WriteInt(data.get() + used_bytes, record_size);
    used_bytes += WriteInt(data.get() + used_bytes, key_len);

    memcpy(data.get() + used_bytes, key.data(), key_len);
    used_bytes += key_len;
    memcpy(data.get() + used_bytes, value.data(), value.size());
    used_bytes += value.size();

    CHECK(used_bytes == size);

    if (!Write(data.get(), used_bytes)) {
        return false;
    }

    ++m_records_written_after_sync;
    return true;
}
开发者ID:anqin,项目名称:toft,代码行数:35,代码来源:local_sequence_file_writer.cpp

示例5: qfind_first_of

size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
                                 const StringPiece& needles) {
  if (UNLIKELY(needles.empty() || haystack.empty())) {
    return StringPiece::npos;
  } else if (needles.size() <= 16) {
    // we can save some unnecessary load instructions by optimizing for
    // the common case of needles.size() <= 16
    return qfind_first_byte_of_needles16(haystack, needles);
  }

  if (haystack.size() < 16 &&
      PAGE_FOR(haystack.end() - 1) != PAGE_FOR(haystack.data() + 16)) {
    // We can't safely SSE-load haystack. Use a different approach.
    if (haystack.size() <= 2) {
      return qfind_first_of(haystack, needles, asciiCaseSensitive);
    }
    return qfind_first_byte_of_byteset(haystack, needles);
  }

  auto ret = scanHaystackBlock<false>(haystack, needles, 0);
  if (ret != StringPiece::npos) {
    return ret;
  }

  size_t i = nextAlignedIndex(haystack.data());
  for (; i < haystack.size(); i += 16) {
    auto ret = scanHaystackBlock<true>(haystack, needles, i);
    if (ret != StringPiece::npos) {
      return ret;
    }
  }

  return StringPiece::npos;
}
开发者ID:Elvins,项目名称:folly,代码行数:34,代码来源:Range.cpp

示例6: Rewrite

bool RML_RE::Rewrite(string *out, const StringPiece &rewrite,
                 const StringPiece &text, int *vec, int veclen) const {
  for (const char *s = rewrite.data(), *end = s + rewrite.size();
       s < end; s++) {
    int c = *s;
    if (c == '\\') {
      c = *++s;
      if (isdigit(c)) {
        int n = (c - '0');
        if (n >= veclen) {
          //fprintf(stderr, requested group %d in regexp %.*s\n",
          //        n, rewrite.size(), rewrite.data());
          return false;
        }
        int start = vec[2 * n];
        if (start >= 0)
          out->append(text.data() + start, vec[2 * n + 1] - start);
      } else if (c == '\\') {
        out->push_back('\\');
      } else {
        //fprintf(stderr, "invalid rewrite pattern: %.*s\n",
        //        rewrite.size(), rewrite.data());
        return false;
      }
    } else {
      out->push_back(c);
    }
  }
  return true;
}
开发者ID:arcady-chugunov,项目名称:thesis,代码行数:30,代码来源:pcre_rml.cpp

示例7: parseRes

U_CAPI int32_t U_EXPORT2
unum_parseDecimal(const UNumberFormat*  fmt,
            const UChar*    text,
            int32_t         textLength,
            int32_t         *parsePos /* 0 = start */,
            char            *outBuf,
            int32_t         outBufLength,
            UErrorCode      *status)
{
    if (U_FAILURE(*status)) {
        return -1;
    }
    if ((outBuf == NULL && outBufLength != 0) || outBufLength < 0) {
        *status = U_ILLEGAL_ARGUMENT_ERROR;
        return -1;
    }
    Formattable res;
    parseRes(res, fmt, text, textLength, parsePos, status);
    StringPiece sp = res.getDecimalNumber(*status);
    if (U_FAILURE(*status)) {
       return -1;
    } else if (sp.size() > outBufLength) {
        *status = U_BUFFER_OVERFLOW_ERROR;
    } else if (sp.size() == outBufLength) {
        uprv_strncpy(outBuf, sp.data(), sp.size());
        *status = U_STRING_NOT_TERMINATED_WARNING;
    } else {
        U_ASSERT(outBufLength > 0);
        uprv_strcpy(outBuf, sp.data());
    }
    return sp.size();
}
开发者ID:119120119,项目名称:node,代码行数:32,代码来源:unum.cpp

示例8: ParseFloat

float ParseFloat(const StringPiece& str) {
  char* errIndex;
  float value = static_cast<float>(strtod(str.data(), &errIndex));
  if (errIndex == str.data()) {
    throw util::ParseNumberException(str);
  }
  return value;
}
开发者ID:CUNI-Khresmoi,项目名称:CUNI-Khresmoi-Moses,代码行数:8,代码来源:FeatureDataIterator.cpp

示例9: ReplaceAll

void ReplaceAll(std::string* s, const StringPiece& from, const StringPiece& to)
{
    size_t pos = 0;
    while ((pos = s->find(from.data(), pos, from.size())) != std::string::npos)
    {
        s->replace(pos, from.size(), to.data(), to.size());
        pos += to.size();
    }
}
开发者ID:343829084,项目名称:toft,代码行数:9,代码来源:algorithm.cpp

示例10: ParseInt

int ParseInt(const StringPiece& str ) {
  char* errIndex;
  //could wrap?
  int value = static_cast<int>(strtol(str.data(), &errIndex,10));
  if (errIndex == str.data()) {
    throw util::ParseNumberException(str);
  }
  return value;
}
开发者ID:CUNI-Khresmoi,项目名称:CUNI-Khresmoi-Moses,代码行数:9,代码来源:FeatureDataIterator.cpp

示例11: DigestUpdate

void Crypto::DigestUpdate(Digest x, const StringPiece &in) {
  auto d = FromVoid<CCDigest*>(x);
  switch(d->algo) {
    case CCDigestAlgo::MD5:    CC_MD5_Update   (static_cast<CC_MD5_CTX*>   (d->v), in.data(), in.size()); break;
    case CCDigestAlgo::SHA1:   CC_SHA1_Update  (static_cast<CC_SHA1_CTX*>  (d->v), in.data(), in.size()); break;
    case CCDigestAlgo::SHA256: CC_SHA256_Update(static_cast<CC_SHA256_CTX*>(d->v), in.data(), in.size()); break;
    case CCDigestAlgo::SHA384: CC_SHA384_Update(static_cast<CC_SHA512_CTX*>(d->v), in.data(), in.size()); break;
    case CCDigestAlgo::SHA512: CC_SHA512_Update(static_cast<CC_SHA512_CTX*>(d->v), in.data(), in.size()); break;
    default: break;
  }
}
开发者ID:LucidFusionLabs,项目名称:core,代码行数:11,代码来源:commoncrypto_crypto.cpp

示例12: 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

示例13: 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

示例14:

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

示例15: doPrint

void FDSymbolizePrinter::doPrint(StringPiece sp) {
  if (buffer_) {
    if (sp.size() > buffer_->tailroom()) {
      flush();
      writeFull(fd_, sp.data(), sp.size());
    } else {
      memcpy(buffer_->writableTail(), sp.data(), sp.size());
      buffer_->append(sp.size());
    }
  } else {
    writeFull(fd_, sp.data(), sp.size());
  }
}
开发者ID:genorm,项目名称:folly,代码行数:13,代码来源:Symbolizer.cpp


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