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


C++ ustring::casefold方法代码示例

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


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

示例1: add_to_renderings

void WindowCheckKeyterms::add_to_renderings(const ustring & rendering, bool wholeword)
// Adds "rendering" to renderings. If it contains any capitals, the 
// casesensitive is set too.
{
  ustring keyterm;
  keyterms_get_term(keyword_id, keyterm);
  GtkTreeIter iter;
  gtk_tree_store_append(treestore_renderings, &iter, NULL);
  bool casesensitive = rendering != rendering.casefold();
  gtk_tree_store_set(treestore_renderings, &iter, 0, wholeword, 1, casesensitive, 2, rendering.c_str(), 3, 1, -1);
  save_renderings();
}
开发者ID:postiffm,项目名称:bibledit-gtk,代码行数:12,代码来源:windowcheckkeyterms.cpp

示例2: find_renderings

bool WindowCheckKeyterms::find_renderings (const ustring& text, const vector <ustring>& renderings, const vector <bool>& wholewords, const vector <bool>& casesensitives, vector <size_t> * startpositions, vector <size_t> * lengths)
// Finds renderings in the text.
// text: Text to be looked into.
// renderings: Renderings to look for.
// wholewords / casesensitives: Attributes of the renderings.
// startpositions: If non-NULL, will be filled with the positions that each rendering starts at.
// lengths: If non-NULL, will be filled with the lengths of the renderings found.
// Returns whether one or more renderings were found in the verse.
{
  if (startpositions)
    startpositions->clear();
  if (lengths)
    lengths->clear();

  GtkTextBuffer * textbuffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_set_text (textbuffer, text.c_str(), -1);
  GtkTextIter startiter;
  gtk_text_buffer_get_start_iter(textbuffer, &startiter);

  bool found = false;

  for (unsigned int i2 = 0; i2 < renderings.size(); i2++) {

    ustring rendering = renderings[i2];
    bool wholeword = wholewords[i2];
    bool casesensitive = casesensitives[i2];

    ustring mytext;
    ustring myrendering;
    if (casesensitive) {
      mytext = text;
      myrendering = rendering;
    } else {
      mytext = text.casefold();
      myrendering = rendering.casefold();
    }
    size_t position = mytext.find(myrendering);
    while (position != string::npos) {
      bool temporally_approved = true;
      GtkTextIter approvedstart = startiter;
      GtkTextIter approvedend;
      gtk_text_iter_forward_chars(&approvedstart, position);
      approvedend = approvedstart;
      gtk_text_iter_forward_chars(&approvedend, rendering.length());
      if (wholeword) {
        if (!gtk_text_iter_starts_word(&approvedstart))
          temporally_approved = false;
        if (!gtk_text_iter_ends_word(&approvedend))
          temporally_approved = false;
      }
      if (temporally_approved) {
        found = true;
        if (startpositions)
          startpositions->push_back (position);
        if (lengths)
          lengths->push_back (rendering.length());
      }
      position = mytext.find(myrendering, ++position);
    }
  }

  g_object_unref (textbuffer);  
  
  return found;
}
开发者ID:postiffm,项目名称:bibledit-gtk,代码行数:65,代码来源:windowcheckkeyterms.cpp

示例3: searchwords_find_fast

bool searchwords_find_fast (const ustring& text, 
                            const vector <ustring>& searchwords,
							const vector <bool>& wholewords,
							const vector <bool>& casesensitives, 
                            vector <size_t>& startpositions,
							vector <size_t>& lengths)
// Finds occurrences of searchwords in the text.
// text: Text to be looked through.
// searchwords: Search words to look for.
// wholewords / casesensitives: Attributes of the searchwords.
// startpositions: If non-NULL, will be filled with the positions that each searchword starts at.
// lengths: If non-NULL, will be filled with the lengths of the searchwords found.
// Returns whether one or more searchwords were found in the text.
{
  // Clear output containers.
  startpositions.clear();
  lengths.clear();

  // A textbuffer makes searching text easier in this case.
  GtkTextBuffer * textbuffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_set_text (textbuffer, text.c_str(), -1);
  GtkTextIter startiter;
  gtk_text_buffer_get_start_iter(textbuffer, &startiter);

  bool found = false;

  // Go through all words to look for.
  for (unsigned int i2 = 0; i2 < searchwords.size(); i2++) {

    // Define this search word and its parameters.
    ustring searchword = searchwords[i2];
    bool wholeword = wholewords[i2];
    bool casesensitive = casesensitives[i2];

    // Handle case sensitivity.
    ustring mytext;
    ustring mysearchword;
    if (casesensitive) {
      mytext = text;
      mysearchword = searchword;
    } else {
      mytext = text.casefold();
      mysearchword = searchword.casefold();
    }
    // Find all occurrences of the word.
    size_t position = mytext.find(mysearchword);
    while (position != string::npos) {
      bool temporally_approved = true;
      GtkTextIter approvedstart = startiter;
      GtkTextIter approvedend;
      gtk_text_iter_forward_chars(&approvedstart, position);
      approvedend = approvedstart;
      gtk_text_iter_forward_chars(&approvedend, searchword.length());
      if (wholeword) {
        if (!gtk_text_iter_starts_word(&approvedstart))
          temporally_approved = false;
        if (!gtk_text_iter_ends_word(&approvedend))
          temporally_approved = false;
      }
      if (temporally_approved) {
        found = true;
        startpositions.push_back (position);
        lengths.push_back (searchword.length());
      }
      position = mytext.find(mysearchword, ++position);
    }
  }
 
  // Free textbuffer used.
  g_object_unref (textbuffer);  

  if (found) {
    // Sort the output.
    quick_sort (startpositions, lengths, 0, (unsigned int)startpositions.size());
    // Overlapping items need to be combined to avoid crashes.
    xml_combine_overlaps (startpositions, lengths);
  }

  // Return true if anything was found.  
  return found;
}
开发者ID:alerque,项目名称:bibledit,代码行数:81,代码来源:highlight.cpp


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