void FalagardActionButton::setCornerChar(int nPos, const String32& strChar) { String32 strCharSafe=" "; if(strChar.size() > 3) { strCharSafe += strChar.substr(0, 3); } else strCharSafe += strChar; strCharSafe[0] = 0XFBFFFFFF; strCharSafe[1] = 0XFC010101; switch(nPos) { case 0: d_CornerChar_TopLeft.d_Char = strCharSafe; break; case 1: d_CornerChar_TopRight.d_Char = strCharSafe; break; case 2: d_CornerChar_BotLeft.d_Char = strCharSafe; break; case 3: d_CornerChar_BotRight.d_Char = strCharSafe; break; default: break; } requestRedraw(); }
/************************************************************************* Trim all characters from the set specified in \a chars from the begining of 'str'. *************************************************************************/ void TextUtils::trimLeadingChars(String32& str, const String32& chars) { String32::size_type idx = str.find_first_not_of(chars); if (idx != String32::npos) { str.erase(0, idx); } else { str.erase(); } }
/************************************************************************* Trim all characters from the set specified in \a chars from the end of 'str'. *************************************************************************/ void TextUtils::trimTrailingChars(String32& str, const String32& chars) { String32::size_type idx = str.find_last_not_of(chars); if (idx != String32::npos) { str.resize(idx + 1); } else { str.erase(); } }
/************************************************************************* Return the index of the first character of the word after the word at 'idx'. *************************************************************************/ String32::size_type TextUtils::getNextWordStartIdx(const String32& str, String32::size_type idx) { String32::size_type str_len = str.length(); // do some checks for simple cases if ((idx >= str_len) || (str_len == 0)) { return str_len; } // is character at 'idx' alphanumeric if (String32::npos != DefaultAlphanumerical.find(str[idx])) { // find position of next character that is not alphanumeric idx = str.find_first_not_of(DefaultAlphanumerical, idx); } // is character also not whitespace (therefore a symbol) else if (String32::npos == DefaultWhitespace.find(str[idx])) { // find index of next character that is either alphanumeric or whitespace idx = str.find_first_of(DefaultAlphanumerical + DefaultWhitespace, idx); } // check result at this stage. if (String32::npos == idx) { idx = str_len; } else { // if character at 'idx' is whitespace if (String32::npos != DefaultWhitespace.find(str[idx])) { // find next character that is not whitespace idx = str.find_first_not_of(DefaultWhitespace, idx); } if (String32::npos == idx) { idx = str_len; } } return idx; }
/************************************************************************* return a String32 containing the the next word in a String32. *************************************************************************/ String32 TextUtils::getNextWord(const String32& str, String32::size_type start_idx, const String32& delimiters) { String32::size_type word_start = str.find_first_not_of(delimiters, start_idx); if (word_start == String32::npos) { word_start = start_idx; } //String32::size_type word_end = str.find_first_of(delimiters, word_start); //if (word_end == String32::npos) //{ // word_end = str.length(); //} //return str.substr(start_idx, (word_end - start_idx)); return str.substr(start_idx, 1); }
/************************************************************************* Return the index of the first character of the word at 'idx'. *************************************************************************/ String32::size_type TextUtils::getWordStartIdx(const String32& str, String32::size_type idx) { String32 temp = str.substr(0, idx); trimTrailingChars(temp, DefaultWhitespace); if (temp.length() <= 1) { return 0; } // identify the type of character at 'pos' if (String32::npos != DefaultAlphanumerical.find(temp[temp.length() - 1])) { idx = temp.find_last_not_of(DefaultAlphanumerical); } // since whitespace was stripped, character must be a symbol else { idx = temp.find_last_of(DefaultAlphanumerical + DefaultWhitespace); } // make sure we do not go past end of string (+1) if (idx == String32::npos) { return 0; } else { return idx + 1; } }
void toString32(Slice const& utf8, String32& to) { to.assign(FromUtf8IterC(utf8.first), FromUtf8IterC(utf8.second)); }
void toString32(std::string const& utf8Str, String32& to) { to.assign(FromUtf8Iter(utf8Str.begin()), FromUtf8Iter(utf8Str.end())); }
////////////////////////////////////////////////////////////////////////// // Modifying operations ////////////////////////////////////////////////////////////////////////// // swap the contents of str1 and str2 void swap(String32& str1, String32& str2) { str1.swap(str2); }
bool operator>=(const char* c_str, const String32& str) { return (str.compare(c_str) <= 0); }
bool operator>=(const utf8* utf8_str, const String32& str) { return (str.compare(utf8_str) <= 0); }
bool operator>=(const std::string& std_str, const String32& str) { return (str.compare(std_str) <= 0); }
bool operator>=(const String32& str1, const String32& str2) { return (str1.compare(str2) >= 0); }
bool operator<(const String32& str1, const String32& str2) { return (str1.compare(str2) < 0); }