summaryrefslogtreecommitdiffstats
path: root/scribus/text/storytext.cpp
diff options
context:
space:
mode:
authorjghali <jghali@11d20701-8431-0410-a711-e3c959e3b870>2012-06-05 21:51:22 +0000
committerjghali <jghali@11d20701-8431-0410-a711-e3c959e3b870>2012-06-05 21:51:22 +0000
commit1b786f099b838cf42237bf7b18b9615f858673b3 (patch)
tree9facffc02a3a224b1cb046552236085b956d1bb3 /scribus/text/storytext.cpp
parente81809849a4bae494032c4859467026f14be7aed (diff)
downloadscribus-1b786f099b838cf42237bf7b18b9615f858673b3.tar.gz
scribus-1b786f099b838cf42237bf7b18b9615f858673b3.tar.xz
scribus-1b786f099b838cf42237bf7b18b9615f858673b3.zip
#3730: impossible to search and replace "fl" in text area
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17540 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/text/storytext.cpp')
-rw-r--r--scribus/text/storytext.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/scribus/text/storytext.cpp b/scribus/text/storytext.cpp
index d85eee5..97c1ef9 100644
--- a/scribus/text/storytext.cpp
+++ b/scribus/text/storytext.cpp
@@ -201,6 +201,95 @@ void StoryText::clear()
invalidateAll();
}
+int StoryText::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const
+{
+ int foundIndex = -1;
+
+ if (str.isEmpty() || (from < 0))
+ return -1;
+
+ int strLen = str.length();
+ int storyLen = length();
+
+ QString qStr = str;
+ if (cs == Qt::CaseInsensitive)
+ qStr = qStr.toLower();
+ QChar ch = qStr.at(0);
+
+ if (cs == Qt::CaseSensitive)
+ {
+ int i = indexOf(ch, from, cs);
+ while (i >= 0 && i < (int) d->len)
+ {
+ int index = 0;
+ while ((index < strLen) && ((index + i) < storyLen))
+ {
+ if (qStr.at(index) != d->at(index + i)->ch)
+ break;
+ ++index;
+ }
+ if (index == strLen)
+ {
+ foundIndex = i;
+ break;
+ }
+ i = indexOf(ch, i + 1, cs);
+ }
+ }
+ else
+ {
+ int i = indexOf(ch, from, cs);
+ while (i >= 0 && i < (int) d->len)
+ {
+ int index = 0;
+ while ((index < strLen) && ((index + i) < storyLen))
+ {
+ if (qStr.at(index) != d->at(index + i)->ch.toLower())
+ break;
+ ++index;
+ }
+ if (index == strLen)
+ {
+ foundIndex = i;
+ break;
+ }
+ i = indexOf(ch, i + 1, cs);
+ }
+ }
+
+ return foundIndex;
+}
+
+int StoryText::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
+{
+ int foundIndex = -1;
+ int textLength = length();
+
+ if (cs == Qt::CaseSensitive)
+ {
+ for (int i = from; i < textLength; ++i)
+ {
+ if (d->at(i)->ch == ch)
+ {
+ foundIndex = i;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (int i = from; i < textLength; ++i)
+ {
+ if (d->at(i)->ch.toLower() == ch)
+ {
+ foundIndex = i;
+ break;
+ }
+ }
+ }
+ return foundIndex;
+}
+
void StoryText::insert(const StoryText& other, bool onlySelection)
{
insert(d->cursorPosition, other, onlySelection);