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


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

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


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

示例1: XPath

bool XmlDocument::XPath(StringPiece const &v, std::wstring *r) {
  WStringPiece str;
  xmlXPathObjectPtr xpath = xmlXPathEvalExpression((unsigned char const*)v.data(), libxml_stuff->xpath_context);
  if (xpath) {
    xmlChar *s_ = xmlXPathCastToString(xpath);
    if (s_) {
      StringPiece s((char*)s_);
      wchar_t *output = conv_buf.Alloc(s.length());
      int const conv_result = cpcl::TryConvertUTF8_UTF16(s, output, conv_buf.Size());
      if (conv_result == -1) {
        output = 0;
        Trace(CPCL_TRACE_LEVEL_ERROR, "XmlDocument::XPath(%s): utf_to_uc fails", v.as_string().c_str());
      }
      else {
        output = conv_buf.Data() + conv_result;
        if (conv_result > ((int)(conv_buf.Size()&INT_MAX)))
          Trace(CPCL_TRACE_LEVEL_WARNING, "XmlDocument::XPath(%s): TryConvertUTF8_UTF16 okashi desu ne...", v.as_string().c_str());
      }

      xmlFree(s_);
      if (output) {
        //*output = 0;
        str = WStringPiece(conv_buf.Data(), output - conv_buf.Data());
      }
    }
    xmlXPathFreeObject(xpath);
  }

  if (TrimResults)
    str = str.trim(TrimChars);

  if ((!str.empty()) && (r))
    r->assign(str.data(), str.size());
  return (!str.empty());
}
开发者ID:hatc,项目名称:image-proxy,代码行数:35,代码来源:libxml_util.cpp

示例2: Predict

float VWPredictor::Predict(const StringPiece &label)
{
  m_ex->set_label(label.as_string());
  m_isFirstSource = true;
  m_isFirstTarget = true;
  float loss = m_ex->predict_partial();
  if (DEBUG) std::cerr << "VW :: Predicted loss: " << loss << "\n";
  m_ex->remns(); // remove target namespace
  return loss;
}
开发者ID:Deseaus,项目名称:mosesdecoder,代码行数:10,代码来源:VWPredictor.cpp

示例3: readNext

void FeatureDataIterator::readNext() {
  m_next.clear();
  try {
    StringPiece marker = m_in->ReadDelimited();
    if (marker != StringPiece(FEATURES_TXT_BEGIN)) {
      throw FileFormatException(m_in->FileName(), marker.as_string());
    }
    size_t sentenceId = m_in->ReadULong();
    size_t count = m_in->ReadULong();
    size_t length = m_in->ReadULong();
    m_in->ReadLine(); //discard rest of line
    for (size_t i = 0; i < count; ++i) {
      StringPiece line = m_in->ReadLine();
      m_next.push_back(FeatureDataItem());
      for (TokenIter<AnyCharacter, true> token(line, AnyCharacter(" \t")); token; ++token) {
        TokenIter<AnyCharacter,false> value(*token,AnyCharacter(":"));
        if (!value) throw FileFormatException(m_in->FileName(), line.as_string());
        StringPiece first = *value;
        ++value;
        if (!value) {
          //regular feature
          float floatValue = ParseFloat(first);
          m_next.back().dense.push_back(floatValue);
        } else {
          //sparse feature
          StringPiece second = *value;
          float floatValue = ParseFloat(second);
          m_next.back().sparse.set(first.as_string(),floatValue); 
        }
      }
      if (length != m_next.back().dense.size()) {
        throw FileFormatException(m_in->FileName(), line.as_string());
      }
    }
    StringPiece line = m_in->ReadLine();
    if (line != StringPiece(FEATURES_TXT_END)) {
      throw FileFormatException(m_in->FileName(), line.as_string());
    }
  } catch (EndOfFileException &e) {
    m_in.reset();
  }
}
开发者ID:CUNI-Khresmoi,项目名称:CUNI-Khresmoi-Moses,代码行数:42,代码来源:FeatureDataIterator.cpp

示例4: GetUnbinarizedChildren

//get the children of a node in a binarized tree; if a child is virtual, (transitively) replace it with its children
void InternalTree::GetUnbinarizedChildren(std::vector<TreePointer> &ret) const
{
  for (std::vector<TreePointer>::const_iterator itx = m_children.begin(); itx != m_children.end(); ++itx) {
    const StringPiece label = (*itx)->GetLabel().GetString(0);
    if (!label.empty() && label.as_string()[0] == '^') {
      (*itx)->GetUnbinarizedChildren(ret);
    } else {
      ret.push_back(*itx);
    }
  }
}
开发者ID:EktaGupta28,项目名称:mosesdecoder,代码行数:12,代码来源:InternalTree.cpp

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

示例6: GetVocabId

DALM::VocabId LanguageModelDALM::GetVocabId(const Factor *factor) const
{
	VocabMap::left_map::const_iterator iter;
	iter = m_vocabMap.left.find(factor);
	if (iter != m_vocabMap.left.end()) {
		return iter->second;
	}
	else {
		StringPiece str = factor->GetString();
		DALM::VocabId wid = m_vocab->lookup(str.as_string().c_str());
		return wid;
	}
}
开发者ID:arvs,项目名称:mosesdecoder,代码行数:13,代码来源:DALM.cpp

示例7: add_to_map

void add_to_map(StoreVocab<uint64_t> &sourceVocab,
                const StringPiece &textin)
{
  //Tokenize
  util::TokenIter<util::SingleCharacter> itWord(textin, util::SingleCharacter(' '));

  while (itWord) {
    StringPiece word = *itWord;

    util::TokenIter<util::SingleCharacter> itFactor(word, util::SingleCharacter('|'));
    while (itFactor) {
      StringPiece factor = *itFactor;

      sourceVocab.Insert(getHash(factor), factor.as_string());
      itFactor++;
    }
    itWord++;
  }
}
开发者ID:a455bcd9,项目名称:mosesdecoder,代码行数:19,代码来源:vocabid.cpp

示例8: SplitUsingStringDelimiterToIterator

static inline
void SplitUsingStringDelimiterToIterator(const StringPiece& full,
                                         const char* delim,
                                         ITR& result)
{
    if (full.empty())
    {
        return;
    }
    if (delim[0] == '\0')
    {
        *result++ = full.as_string();
        return;
    }

    // Optimize the common case where delim is a single character.
    if (delim[1] == '\0')
    {
        SplitStringToIteratorUsing<StringType>(full, delim, result);
        return;
    }

    size_t delim_length = strlen(delim);
    for (size_t begin_index = 0; begin_index < full.size();)
    {
        size_t end_index = full.find(delim, begin_index);
        if (end_index == std::string::npos)
        {
            *result++ = full.substr(begin_index).as_string();
            return;
        }
        if (end_index > begin_index)
        {
            StringType value(full.data() + begin_index, end_index - begin_index);
            *result++ = value;
        }
        begin_index = end_index + delim_length;
    }
}
开发者ID:343829084,项目名称:toft,代码行数:39,代码来源:algorithm.cpp

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

示例10: SetProperties

void TargetPhrase::SetProperties(const StringPiece &str)
{
  if (str.size() == 0) {
    return;
  }

  vector<string> toks;
  TokenizeMultiCharSeparator(toks, str.as_string(), "{{");
  for (size_t i = 0; i < toks.size(); ++i) {
    string &tok = toks[i];
    if (tok.empty()) {
      continue;
    }
    size_t endPos = tok.rfind("}");

    tok = tok.substr(0, endPos - 1);

    vector<string> keyValue = TokenizeFirstOnly(tok, " ");
    UTIL_THROW_IF2(keyValue.size() != 2,
                   "Incorrect format of property: " << str);
    SetProperty(keyValue[0], keyValue[1]);
  }
}
开发者ID:schinger,项目名称:mosesdecoder,代码行数:23,代码来源:TargetPhrase.cpp

示例11: split_line

line_text split_line(StringPiece textin) {
  const char delim[] = " ||| ";
  StringPiece str; //Temp string container
  std::string temp; //Temp string for conversion
  int num;
  line_text output;

  //Tokenize
  util::TokenIter<util::MultiCharacter> it(textin, util::MultiCharacter(delim));
  //Get string
  str = *it;
  output.text = str;
  it++;

  //Get num
  str = *it;

  //Convert to int
  temp = str.as_string();
  num = atoi(temp.c_str());
  output.value = num;

  return output;
}
开发者ID:XapaJIaMnu,项目名称:ProbingPT,代码行数:24,代码来源:token_test.cpp

示例12: LsiMessageHandler

LsiRewriteDriverFactory::LsiRewriteDriverFactory(
    const ProcessContext &process_context,
    SystemThreadSystem *system_thread_system, StringPiece hostname, int port)
    : SystemRewriteDriverFactory(process_context, system_thread_system,
                                 NULL /* default shared memory runtime */, hostname, port),
      m_mainConf(NULL),
      m_bThreadsStarted(false),
      m_pLsiMessageHandler(new LsiMessageHandler(timer(),
                           thread_system()->NewMutex())),
      m_pHtmlParseLsiMessageHandler(
          new LsiMessageHandler(timer(), thread_system()->NewMutex())),
      m_pSharedCircularBuffer(NULL),
      m_sHostname(hostname.as_string()),
      m_iPort(port)
{
    InitializeDefaultOptions();
    default_options()->set_beacon_url("/ls_pagespeed_beacon");
    SystemRewriteOptions *system_options =
        dynamic_cast<SystemRewriteOptions *>(default_options());
    system_options->set_file_cache_clean_inode_limit(500000);
    system_options->set_avoid_renaming_introspective_javascript(true);
    set_message_handler(m_pLsiMessageHandler);
    set_html_parse_message_handler(m_pHtmlParseLsiMessageHandler);
}
开发者ID:52M,项目名称:openlitespeed,代码行数:24,代码来源:ls_rewrite_driver_factory.cpp

示例13: ReplaceAllChars

std::string ReplaceAllChars(const StringPiece& s, const StringPiece& from, char to)
{
    std::string result = s.as_string();
    ReplaceAllChars(&result, from, to);
    return result;
}
开发者ID:343829084,项目名称:toft,代码行数:6,代码来源:algorithm.cpp

示例14: StringTrim

std::string StringTrim(const StringPiece& str, const StringPiece& trim_value) {
    std::string res = str.as_string();
    StringTrim(&res, trim_value);
    return res;
}
开发者ID:343829084,项目名称:toft,代码行数:5,代码来源:algorithm.cpp

示例15: AddFeature

void VWPredictor::AddFeature(const StringPiece &name, float value)
{
  if (DEBUG) std::cerr << "VW :: Adding feature: " << EscapeSpecialChars(name.as_string()) << ":" << value << "\n";
  m_ex->addf(EscapeSpecialChars(name.as_string()), value);
}
开发者ID:Deseaus,项目名称:mosesdecoder,代码行数:5,代码来源:VWPredictor.cpp


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