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


C++ string_t::find方法代码示例

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


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

示例1: split_string

void split_string(string_t& source, const string_t& delim, std::list<string_t>& ret)
{
	ret.clear();

	if (delim.empty() || source.empty())
	{
		ret.push_back(source);
		return ;
	}

	size_t last = 0;
	size_t index = source.find(delim, last);

    while (index!=std::string::npos)
    {
		ret.push_back(source.substr(last, index - last));
		last = index + delim.size();
		index = source.find(delim, last);
	}

    if(index - last > 0)
	{
		ret.push_back(source.substr(last, index - last));
	}
}
开发者ID:OData,项目名称:odatacpp-server,代码行数:25,代码来源:utility.cpp

示例2: url_t

 url_t
 downloader::get_full_url(string_t const& url) const {
   if (url.find("http://") == std::string::npos) {
     return url_t(config_.host + url);
   }
   else {
     return url;
   }
 }
开发者ID:amireh,项目名称:Karazeh,代码行数:9,代码来源:downloader.cpp

示例3: detect_fucking_warez_ad_tag

static void detect_fucking_warez_ad_tag(string_t& str) {
  
  if (string_t_find_success(str.find("(www."))) 
  {
    size_t pos=str.find("(www.");
    str.erase(pos, string_t_size(str));
  }
  else if (string_t_find_success(str.find("(http://"))) 
  {
    size_t pos=str.find("(http://");
    str.erase(str.find("(http://"), string_t_size(str));
    str.erase(pos, string_t_size(str));
  }
  else if (string_t_find_success(str.find("http://"))) 
  {
    size_t pos=str.find("http://");
    str.erase(pos, string_t_size(str));
  }
  else if (string_t_find_success(str.find("www."))) {
    size_t pos=str.find("www.");
    str.erase(pos, string_t_size(str));
  }
  remove_useless_spaces_before(str);
}
开发者ID:lamogui,项目名称:libtools,代码行数:24,代码来源:decoder.cpp

示例4: loadMappingFile

void CharMapping::loadMappingFile( const string_t& mapFile )
{
    if (mapFile.find("cm-arafi.txt") != string_t::npos) {
        /// clear default mapping
        for (wchar_t i = 0x0021; i <= 0x007E; ++i)
            quickMap_[i] = 0;
    }

    Poco::FileInputStream fis(mapFile);
    
    int line = 0;
    wchar_t from, to;
    while (!fis.eof()) {
        string_t sl;
        wstring_t wsl;
        std::getline(fis, sl);
        ++line;

        sl = Poco::trim(sl);
        if (sl.empty())
            continue;

        wsl = toUtf16(sl);
        if (wsl.size() != 3) {
            throw std::logic_error("Invalid character mapping file: " + mapFile + ", line: " + Poco::NumberFormatter::format(line));
        }
        from = wsl[0];
        to   = wsl[2];

        if (from < 256)
            quickMap_[from] = to;
        else {
            mapping_[from] = to;
        }

        /// add identical mapping to avoid false warnings
        mapping_[to] = to;
    }
}
开发者ID:,项目名称:,代码行数:39,代码来源:

示例5: GetDelimiter

char_t Tokenizer::GetDelimiter(TokenRange range) const {
  // Symbols are sorted by their precedence, in decreasing order. While the most
  // common delimiters are underscore, space and dot, we give comma the priority
  // to handle the case where words are separated by ", ". Besides, we'll be
  // trimming whitespace later on.
  static const string_t kDelimiterTable = L",_ .-+;&|~";

  // Trim whitespace so that it doesn't interfere with our frequency analysis.
  // This proves useful for handling some edge cases, and it doesn't seem to
  // have any side effects.
  if (!TrimWhitespace(filename_, range))
    return L' ';

  static std::map<char_t, size_t> frequency;

  if (frequency.empty()) {
    // Initialize frequency map
    for (const auto& character : kDelimiterTable) {
      frequency.insert(std::make_pair(character, 0));
    }
  } else {
    // Reset frequency map
    for (auto& pair : frequency) {
      pair.second = 0;
    }
  }

  // Count all possible delimiters
  for (size_t i = range.offset; i < range.offset + range.size; i++) {
    const char_t character = filename_.at(i);
    if (IsAlphanumericChar(character))
      continue;
    if (frequency.find(character) == frequency.end())
      continue;
    frequency.at(character) += 1;
  }

  char_t delimiter = L'\0';

  for (const auto& pair : frequency) {
    if (pair.second == 0)
      continue;

    // Initialize delimiter at first iteration
    if (delimiter == L'\0') {
      delimiter = pair.first;
      continue;
    }

    int character_distance =
        static_cast<int>(kDelimiterTable.find(pair.first)) -
        static_cast<int>(kDelimiterTable.find(delimiter));
    // If the distance is negative, then the new delimiter has higher priority
    if (character_distance < 0) {
      delimiter = pair.first;
      continue;
    }

    // Even if the new delimiter has lower priority, it may be much more common
    float frequency_ratio = static_cast<float>(pair.second) /
                            static_cast<float>(frequency[delimiter]);
    // The constant value was chosen by trial and error. There should be room
    // for improvement.
    if (frequency_ratio / abs(character_distance) > 0.8f)
      delimiter = pair.first;
  }

  return delimiter;
}
开发者ID:vevix,项目名称:anitomy,代码行数:69,代码来源:tokenizer.cpp


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