summaryrefslogtreecommitdiff
path: root/src/Fl_Text_Buffer.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-11-07 20:13:50 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-11-07 20:13:50 +0000
commitaccf34f276b200f87d30bc0800895420798ed2ff (patch)
tree476cdee7fdb9b3811ad5593f5fb2decbb7aab254 /src/Fl_Text_Buffer.cxx
parentf0993114811eef4e4dee703d4ebb4769c21f3ff9 (diff)
Implemented search backwards for utf-8. Tested on MSWindows - OK. Tested on Linux (Ubuntu) - K.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7808 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Text_Buffer.cxx')
-rw-r--r--src/Fl_Text_Buffer.cxx79
1 files changed, 48 insertions, 31 deletions
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx
index 531ec5029..52666333e 100644
--- a/src/Fl_Text_Buffer.cxx
+++ b/src/Fl_Text_Buffer.cxx
@@ -856,13 +856,11 @@ int Fl_Text_Buffer::word_end(int pos) const {
/*
- Matt: I am not sure why we need this function. Does it still make sense in
- the world of proportional characters?
+ Count the number of characters between two positions.
*/
int Fl_Text_Buffer::count_displayed_characters(int lineStartPos,
int targetPos) const
{
- // FIXME: this is misleading and may be used to count bytes instead of characters!
IS_UTF8_ALIGNED(address(lineStartPos))
IS_UTF8_ALIGNED(address(targetPos))
@@ -878,16 +876,13 @@ int Fl_Text_Buffer::count_displayed_characters(int lineStartPos,
/*
- Matt: I am not sure why we need this function. Does it still make sense in
- the world of proportional characters?
+ Skip ahead a number of characters from a given index.
+ This function breaks early if it encounters a newline character.
*/
-// All values are number of bytes.
-// - unicode ok?
int Fl_Text_Buffer::skip_displayed_characters(int lineStartPos, int nChars)
{
- // FIXME: this is misleading and may be used to count bytes instead of characters!
IS_UTF8_ALIGNED(address(lineStartPos))
- // FIXME: is this function still needed?
+
int pos = lineStartPos;
for (int charCount = 0; charCount < nChars && pos < mLength; charCount++) {
@@ -1060,37 +1055,60 @@ int Fl_Text_Buffer::search_forward(int startPos, const char *searchString,
return 0;
}
-
-/*
- Find a matching string in the buffer.
- NOT TESTED FOR UNICODE.
- */
int Fl_Text_Buffer::search_backward(int startPos, const char *searchString,
- int *foundPos, int matchCase) const {
- // FIXME: Unicode?
+ int *foundPos, int matchCase) const
+{
+ IS_UTF8_ALIGNED(address(startPos))
+ IS_UTF8_ALIGNED(searchString)
+
if (!searchString)
return 0;
int bp;
const char *sp;
- while (startPos > 0)
- {
- bp = startPos - 1;
- sp = searchString + strlen(searchString) - 1;
- do {
- if (sp < searchString) {
- *foundPos = bp + 1;
- return 1;
+ if (matchCase) {
+ while (startPos >= 0) {
+ bp = startPos;
+ sp = searchString;
+ for (;;) {
+ char c = *sp;
+ // we reached the end of the "needle", so we found the string!
+ if (!c) {
+ *foundPos = startPos;
+ return 1;
+ }
+ int l = fl_utf8len(c);
+ if (memcmp(sp, address(bp), l))
+ break;
+ sp += l; bp += l;
}
- // FIXME: character is ucs-4
- } while ((matchCase ? char_at(bp--) == (unsigned int)*sp-- :
- toupper(char_at(bp--)) == toupper(*sp--))
- && bp >= 0);
- startPos--;
- }
+ startPos = prev_char(startPos);
+ }
+ } else {
+ while (startPos >= 0) {
+ bp = startPos;
+ sp = searchString;
+ for (;;) {
+ // we reached the end of the "needle", so we found the string!
+ if (!*sp) {
+ *foundPos = startPos;
+ return 1;
+ }
+ int l;
+ unsigned int b = char_at(bp);
+ unsigned int s = fl_utf8decode(sp, 0, &l);
+ if (fl_tolower(b)!=fl_tolower(s))
+ break;
+ sp += l;
+ bp = next_char(bp);
+ }
+ startPos = prev_char(startPos);
+ }
+ }
return 0;
}
+
/*
Insert a string into the buffer.
Pos must be at a character boundary. Text must be a correct utf8 string.
@@ -1422,7 +1440,6 @@ void Fl_Text_Buffer::update_selections(int pos, int nDeleted,
// unicode safe, assuming the arguments are on character boundaries
void Fl_Text_Selection::update(int pos, int nDeleted, int nInserted)
{
- // FIXME: check if this is safe when seletion crosses selction boundaries
if (!mSelected || pos > mEnd)
return;
if (pos + nDeleted <= mStart) {