23 bool TextTools::find(
GUIStyledTextNode* textNode,
const string& findString,
bool matchCase,
bool wholeWord,
bool selection,
bool firstSearch,
int& index) {
25 auto findStringLowerCase = matchCase ==
false?StringTools::toLowerCase(findString):findString;
26 auto textMutableString = textNode->
getText();
28 auto textNodeController = required_dynamic_cast<GUIStyledTextNodeController*>(textNode->
getController());
29 auto inSelectionAvailable = textNodeController->getIndex() != -1 && textNodeController->getSelectionIndex() != -1;
30 auto i = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::min(textNodeController->getIndex(), textNodeController->getSelectionIndex())):0;
32 auto ni = textMutableString.getUtf8BinaryIndex(index);
33 auto l = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::max(textNodeController->getIndex(), textNodeController->getSelectionIndex())):textMutableString.size();
35 auto p = StringTools::indexOf(textLowerCase, findStringLowerCase, i);
36 if (p != string::npos && p < l) {
37 i = p + findStringLowerCase.size();
38 if (wholeWord ==
true) {
39 auto textCharIdxBefore = textMutableString.getUtf8CharacterIndex(p) - 1;
40 auto textCharIdxAfter = textMutableString.getUtf8CharacterIndex(p + findStringLowerCase.size());
41 auto textCharBefore = textMutableString.getUTF8CharAt(textCharIdxBefore);
42 auto textCharAfter = textMutableString.getUTF8CharAt(textCharIdxAfter);
43 if (Character::isAlphaNumeric(textCharBefore) ==
true || Character::isAlphaNumeric(textCharAfter) ==
true) {
48 if (ni != -1 && (firstSearch ==
true?p >= ni:p > ni)) {
62 if (ni != -1 && fi != -1) {
73 auto findStringLowerCase = matchCase ==
false?StringTools::toLowerCase(findString):findString;
74 auto textMutableString = textNode->
getText();
76 auto textNodeController = required_dynamic_cast<GUIStyledTextNodeController*>(textNode->
getController());
77 auto inSelectionAvailable = textNodeController->getIndex() != -1 && textNodeController->getSelectionIndex() != -1;
78 auto i = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::min(textNodeController->getIndex(), textNodeController->getSelectionIndex())):0;
79 auto l = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::max(textNodeController->getIndex(), textNodeController->getSelectionIndex())):textMutableString.size();
82 auto p = StringTools::indexOf(textLowerCase, findStringLowerCase, i);
83 if (p != string::npos && p < l) {
84 i = p + findStringLowerCase.size();
85 if (wholeWord ==
true) {
86 auto textCharIdxBefore = textMutableString.getUtf8CharacterIndex(p) - 1;
87 auto textCharIdxAfter = textMutableString.getUtf8CharacterIndex(p + findStringLowerCase.size());
88 auto textCharBefore = textMutableString.getUTF8CharAt(textCharIdxBefore);
89 auto textCharAfter = textMutableString.getUTF8CharAt(textCharIdxAfter);
90 if (Character::isAlphaNumeric(textCharBefore) ==
true || Character::isAlphaNumeric(textCharAfter) ==
true) {
105 auto success =
false;
106 auto findStringLowerCase = matchCase ==
false?StringTools::toLowerCase(findString):findString;
107 auto findStringLength = StringTools::getUtf8Length(findString);
108 auto textMutableString = textNode->
getText();
109 auto textLowerCase = matchCase ==
false?StringTools::toLowerCase(textMutableString.getString()):textMutableString.getString();
110 auto textNodeController = required_dynamic_cast<GUIStyledTextNodeController*>(textNode->
getController());
111 auto inSelectionAvailable = textNodeController->getIndex() != -1 && textNodeController->getSelectionIndex() != -1;
112 auto i = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::min(textNodeController->getIndex(), textNodeController->getSelectionIndex())):0;
114 auto ni = textMutableString.getUtf8BinaryIndex(index);
115 auto l = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::max(textNodeController->getIndex(), textNodeController->getSelectionIndex())):textMutableString.size();
117 auto p = StringTools::indexOf(textLowerCase, findStringLowerCase, i);
118 if (p != string::npos && p < l) {
119 i = p + findStringLowerCase.size();
120 if (wholeWord ==
true) {
121 auto textCharIdxBefore = textMutableString.getUtf8CharacterIndex(p) - 1;
122 auto textCharIdxAfter = textMutableString.getUtf8CharacterIndex(p + findStringLowerCase.size());
123 auto textCharBefore = textMutableString.getUTF8CharAt(textCharIdxBefore);
124 auto textCharAfter = textMutableString.getUTF8CharAt(textCharIdxAfter);
125 if (Character::isAlphaNumeric(textCharBefore) ==
true || Character::isAlphaNumeric(textCharAfter) ==
true) {
129 if (fi == -1) fi = p;
130 if (ni != -1 && p >= ni) {
132 auto replaceIndex = textMutableString.getUtf8CharacterIndex(p);
133 textNodeController->replace(replaceString, replaceIndex, findStringLength);
135 index = replaceIndex + findStringLength;
146 if (ni != -1 && fi != -1) {
148 auto replaceIndex = textMutableString.getUtf8CharacterIndex(fi);
149 textNodeController->replace(replaceString, replaceIndex, findStringLength);
151 index = replaceIndex + findStringLength;
160 auto success =
false;
161 auto findStringLowerCase = matchCase ==
false?StringTools::toLowerCase(findString):findString;
162 auto findStringLength = StringTools::getUtf8Length(findString);
163 auto textMutableString = textNode->
getText();
165 auto textNodeController = required_dynamic_cast<GUIStyledTextNodeController*>(textNode->
getController());
166 auto inSelectionAvailable = textNodeController->getIndex() != -1 && textNodeController->getSelectionIndex() != -1;
167 auto i = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::min(textNodeController->getIndex(), textNodeController->getSelectionIndex())):0;
168 auto l = selection ==
true && inSelectionAvailable ==
true?textMutableString.getUtf8BinaryIndex(Math::max(textNodeController->getIndex(), textNodeController->getSelectionIndex())):textMutableString.size();
170 auto p = StringTools::indexOf(textLowerCase, findStringLowerCase, i);
171 if (p != string::npos && p < l) {
172 i = p + replaceString.size();
173 if (wholeWord ==
true) {
174 auto textCharIdxBefore = textMutableString.getUtf8CharacterIndex(p) - 1;
175 auto textCharIdxAfter = textMutableString.getUtf8CharacterIndex(p + findStringLowerCase.size());
176 auto textCharBefore = textMutableString.getUTF8CharAt(textCharIdxBefore);
177 auto textCharAfter = textMutableString.getUTF8CharAt(textCharIdxAfter);
178 if (Character::isAlphaNumeric(textCharBefore) ==
true || Character::isAlphaNumeric(textCharAfter) ==
true) {
183 auto replaceIndex = textMutableString.getUtf8CharacterIndex(p);
184 textNodeController->replace(replaceString, replaceIndex, findStringLength);
186 textMutableString = textNode->
getText();
GUINodeController * getController()
GUI styled text node controller.
void setTextStyle(int startIdx, int endIdx, const GUIColor &color, const string &font=string(), int size=-1, const string &url=string())
Set text style.
void scrollToIndex(int index)
Set scroll to index.
const MutableString & getText() const
static int count(GUIStyledTextNode *textNode, const string &findString, bool matchCase, bool wholeWord, bool selection)
Count string.
static bool replace(GUIStyledTextNode *textNode, const string &findString, const string &replaceString, bool matchCase, bool wholeWord, bool selection, int &index)
Replace string.
static bool replaceAll(GUIStyledTextNode *textNode, const string &findString, const string &replaceString, bool matchCase, bool wholeWord, bool selection)
Replace all string.
const string & getString() const