📄 words.cpp
字号:
TRACE9 ("Words::addName2Ignore (const Glib::ustring&, unsigned int) - Comp: " << strcmp (shMem->values + shMem->info->aOffsets[pos - 1], word.c_str ())); if (strcmp (shMem->values + shMem->info->aOffsets[pos - 1], word.c_str ()) < 0) { if (pos < shMem->info->cNames) { if (strcmp (shMem->values + shMem->info->aOffsets[pos], word.c_str ()) <= 0) pos = POS_UNKNOWN; } } else pos = POS_UNKNOWN; } } // Hint didn't work or wasn't passed: Search for position to insert if (pos == POS_UNKNOWN) if (shMem->info->cNames) { TRACE9 ("Words::addName2Ignore (const Glib::ustring&, unsigned int) - Search: " << word); pos = binarySearch (shMem->info, shMem->values, 0, shMem->info->cNames - 1, word.c_str ()); } else pos = 0; if (pos < shMem->info->cNames) moveValues (pos, shMem->info->cNames, pos + 1); TRACE3 ("Words::addName2Ignore (const Glib::ustring&, unsigned int) - Insert into " << pos); shMem->info->aOffsets[pos] = shMem->info->used; memcpy (shMem->values + shMem->info->used, word.c_str (), word.bytes ()); shMem->info->used += word.bytes () + 1; shMem->info->cNames++;}//-----------------------------------------------------------------------------/// Adds an article to ignore/// \param word: Article to ignore/// \param pos: Hint of position, where to insert//-----------------------------------------------------------------------------void Words::addArticle (const Glib::ustring& word, unsigned int pos) { Check2 (areAvailable ()); WordPtrs* shMem (ptrs[YGP::Process::getPID ()]); TRACE2 ("Words::addArticle (const Glib::ustring&, unsigned int) - " << word << " to " << shMem->info->cArticles); // Try to respect the hint if (pos != POS_UNKNOWN) { pos = ((pos > shMem->info->cArticles) ? shMem->info->maxEntries - 1 : shMem->info->maxEntries - shMem->info->cArticles + pos); TRACE9 ("Words::addArticle (const Glib::ustring&, unsigned int) - Checking pos " << pos); if (shMem->info->cArticles) { TRACE9 ("Words::addArticle (const Glib::ustring&, unsigned int) - Comp: " << strcmp (shMem->values + shMem->info->aOffsets[pos], word.c_str ())); if (strcmp (shMem->values + shMem->info->aOffsets[pos], word.c_str ()) < 0) { if (pos < (shMem->info->maxEntries - 1)) { if (strcmp (shMem->values + shMem->info->aOffsets[pos + 1], word.c_str ()) <= 0) pos = POS_UNKNOWN; } } else pos = POS_UNKNOWN; } } // Hint didn't work or wasn't passed: Search for position to insert if (pos == POS_UNKNOWN) if (shMem->info->cArticles) { TRACE9 ("Words::addArticles (const Glib::ustring&, unsigned int) - Search: " << word); pos = binarySearch (shMem->info, shMem->values, shMem->info->maxEntries - shMem->info->cArticles, shMem->info->maxEntries - 1, word.c_str ()); } else pos = shMem->info->maxEntries - 1; if (pos >= (shMem->info->maxEntries - shMem->info->cArticles)) moveValues (shMem->info->maxEntries - shMem->info->cArticles, pos, shMem->info->maxEntries - shMem->info->cArticles - 1); TRACE3 ("Words::addArticle (const Glib::ustring&, unsigned int) - Insert into " << pos); shMem->info->aOffsets[pos] = shMem->info->used; memcpy (shMem->values + shMem->info->used, word.c_str (), word.bytes ()); shMem->info->used += word.bytes () + 1; shMem->info->cArticles++;}//-----------------------------------------------------------------------------/// Removes a leading article from the passed name./// \param name: Name to manipulate/// \returns Glib::ustring: Name without article or name//-----------------------------------------------------------------------------Glib::ustring Words::removeArticle (const Glib::ustring& name) { TRACE9 ("Words::removeArticles (const Glib::ustring&) - " << name); Check2 (areAvailable ()); WordPtrs* shMem (ptrs[YGP::Process::getPID ()]); Glib::ustring word (getWord (name)); if (word.size () != name.size () && containsWord (shMem->info->maxEntries - shMem->info->cArticles, shMem->info->maxEntries - 1, word)) { unsigned int pos (word.size ()); while (!isalnum (name[pos])) ++pos; TRACE3 ("Words::removeArticles (const Glib::ustring&) - " << name << "->" << name.substr (pos)); return name.substr (pos); } return name;}//-----------------------------------------------------------------------------/// Removes a leading article from the passed name./// \param name: Name to manipulate/// \returns Glib::ustring: Name without article or name//-----------------------------------------------------------------------------Glib::ustring Words::removeNames (const Glib::ustring& name) { TRACE9 ("Words::removeNames (const Glib::ustring&) - " << name); Check2 (areAvailable ()); WordPtrs* shMem (ptrs[YGP::Process::getPID ()]); Glib::ustring work (name); Glib::ustring word (getWord (work)); while ((word.size () != name.size ()) && containsWord (0, shMem->info->cNames - 1, word)) { unsigned int pos (word.size ()); while (!isalnum (name[pos])) ++pos; work = work.substr (pos); word = getWord (work); } TRACE3 ("Words::removeName (const Glib::ustring&) - " << name << "->" << work); return work;}//-----------------------------------------------------------------------------/// Returns the first word of the passed string/// \param text: Text to extract the first word from/// \returns Glib::ustring: Changed name//-----------------------------------------------------------------------------Glib::ustring Words::getWord (const Glib::ustring& text) { unsigned int i (-1U); while (++i < text.size ()) if (isspace (text[i]) || (text[i] == '-')) break; TRACE9 ("Words::getWord (const Glib::ustring&) - '" << text.substr (0, i) << '\''); return text.substr (0, i);}//-----------------------------------------------------------------------------/// Checks if the passed list contains the passed word/// \param start: Start value/// \param end: End value/// \param word: Word to search for/// \returns bool: True, if the word exists//-----------------------------------------------------------------------------bool Words::containsWord (unsigned int start, unsigned int end, const Glib::ustring& word) { TRACE9 ("Words::containsWord (2x unsigned int, const Glib::ustring& word) - [" << start << '-' << end << ']'); Check2 (areAvailable ()); WordPtrs* shMem (ptrs[YGP::Process::getPID ()]); Check2 (end <= shMem->info->maxEntries); Check2 (start < end); TRACE9 ("Words::containsWord (2x unsigned int, const Glib::ustring& word) - " << shMem->values + shMem->info->aOffsets[start]); TRACE9 ("Words::containsWord (2x unsigned int, const Glib::ustring& word) - " << shMem->values + shMem->info->aOffsets[end]); if (start < end) { unsigned int pos (binarySearch (shMem->info, shMem->values, start, end, word.c_str ())); return ((pos != start) && (word == (shMem->values + shMem->info->aOffsets[pos - 1]))); } else return false;}//-----------------------------------------------------------------------------/// Returns the number of articles stored/// \returns unsigned int: Number of articles stored//-----------------------------------------------------------------------------unsigned int Words::cArticles () { Check2 (areAvailable ()); return ptrs[YGP::Process::getPID ()]->info->cArticles;}//-----------------------------------------------------------------------------/// Returns the number of names stored/// \returns unsigned int: Number of names stored//-----------------------------------------------------------------------------unsigned int Words::cNames () { Check2 (areAvailable ()); return ptrs[YGP::Process::getPID ()]->info->cNames;}//-----------------------------------------------------------------------------/// Returns the stored words for the current process/// \returns unsigned int: Stored words//-----------------------------------------------------------------------------const char* Words::getValues () { Check2 (areAvailable ()); return ptrs[YGP::Process::getPID ()]->values;}//-----------------------------------------------------------------------------/// Returns the stored values for the current process/// \returns unsigned int: Stored values//-----------------------------------------------------------------------------Words::values* Words::getInfo () { Check2 (areAvailable ()); return ptrs[YGP::Process::getPID ()]->info;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -