summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-04-05 21:10:40 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-04-05 21:10:40 +0000
commit07a4509a63bfc06fca31972002e2861449df49c3 (patch)
tree2910ad5fb66166fc347952949b06a58fd987c388
parent814da7f392144de2c61d40a052edffdd54523d0a (diff)
Validated utf-8 safety of Fl_Text_Selection.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7443 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Fl_Text_Buffer.H22
-rw-r--r--src/Fl_Text_Buffer.cxx3
2 files changed, 14 insertions, 11 deletions
diff --git a/FL/Fl_Text_Buffer.H b/FL/Fl_Text_Buffer.H
index 7a8fedb41..ac4cff7ac 100644
--- a/FL/Fl_Text_Buffer.H
+++ b/FL/Fl_Text_Buffer.H
@@ -64,7 +64,8 @@
/**
\class Fl_Text_Selection
\brief This is an internal class for Fl_Text_Buffer to manage text selections.
- \todo unicode check
+ This class works correctly with utf-8 strings assuming that the parameters
+ for all calls are on character boundaries.
*/
class FL_EXPORT Fl_Text_Selection {
friend class Fl_Text_Buffer;
@@ -93,58 +94,55 @@ public:
\param pos byte offset into text buffer at which the change occured
\param nDeleted number of bytes deleted from the buffer
\param nInserted number of bytes inserted into the buffer
- \todo unicode check
*/
void update(int pos, int nDeleted, int nInserted);
/**
\brief Returns true if the selection is rectangular.
- \todo unicode check
+ \return flag
*/
char rectangular() const { return mRectangular; }
/**
\brief Return the byte offset to the first selected character.
- \todo unicode check
+ \return byte offset
*/
int start() const { return mStart; }
/**
\brief Return the byte ofsset to the character after the last selected character.
- \todo unicode check
+ \return byte offset
*/
int end() const { return mEnd; }
/**
\brief Return the first column of the rectangular selection.
- \todo unicode check
+ \return first column of rectangular selection
*/
int rect_start() const { return mRectStart; }
/**
\brief Return the last column of the rectangular selection + 1.
- \todo unicode check
+ \return last column of rectangular selection +1
*/
int rect_end() const { return mRectEnd; }
/**
\brief Returns true if any text is selected.
- Returns a non-zero number if any text has been selected, or 0
+ \return a non-zero number if any text has been selected, or 0
if no text is selected.
- \todo unicode check
*/
char selected() const { return mSelected; }
/**
\brief Modify the 'selected' flag.
- \todo unicode check
+ \param b new flag
*/
void selected(char b) { mSelected = b; }
/**
Return true if position \p pos with indentation \p dispIndex is in
the Fl_Text_Selection.
- \todo unicode check
*/
int includes(int pos, int lineStartPos, int dispIndex) const;
@@ -152,6 +150,7 @@ public:
\brief Return the positions of this selection.
\param start retrun byte offset to first selected character
\param end retrun byte offset pointing after last selected character
+ \return true if selected
*/
int position(int* start, int* end) const;
@@ -162,6 +161,7 @@ public:
\param isRect return if the selection is rectangular
\param rectStart return first selected column
\param rectEnd return last selected column +1
+ \return true if selected
*/
int position(int* start, int* end, int* isRect, int* rectStart, int* rectEnd) const;
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx
index aa957e867..2b091ec95 100644
--- a/src/Fl_Text_Buffer.cxx
+++ b/src/Fl_Text_Buffer.cxx
@@ -1778,6 +1778,7 @@ int Fl_Text_Selection::position(int *startpos, int *endpos,
}
+// unicode safe
int Fl_Text_Selection::includes(int pos, int lineStartPos, int dispIndex) const {
return (selected()
&& ( (!rectangular() && pos >= start() && pos < end())
@@ -1999,6 +2000,8 @@ void Fl_Text_Buffer::update_selections(int pos, int nDeleted,
mHighlight.update(pos, nDeleted, nInserted);
}
+
+// unicode safe, assuming the arguments are on character boundaries
void Fl_Text_Selection::update(int pos, int nDeleted, int nInserted)
{
if (!mSelected || pos > mEnd)