當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。