Author: matt
Date: 2010-04-06 16:00:56 -0700 (Tue, 06 Apr 2010)
New Revision: 7462
Log:
Marked some more issues with Fl_Text_...
Modified:
branches/branch-1.3/FL/Fl_Text_Buffer.H
branches/branch-1.3/src/Fl_Text_Buffer.cxx
branches/branch-1.3/src/Fl_Text_Display.cxx
branches/branch-1.3/src/Fl_Text_Editor.cxx
Modified: branches/branch-1.3/FL/Fl_Text_Buffer.H
===================================================================
--- branches/branch-1.3/FL/Fl_Text_Buffer.H 2010-04-06 20:36:34 UTC (rev
7461)
+++ branches/branch-1.3/FL/Fl_Text_Buffer.H 2010-04-06 23:00:56 UTC (rev
7462)
@@ -196,17 +196,15 @@
/**
Create an empty text buffer of a pre-determined size.
\param requestedSize use this to avoid unnecessary re-allocation
- if you know exactly how much the buffer will need to hold
+ if you know exactly how much the buffer will need to hold
\param preferredGapSize Initial size for the buffer gap (empty space
- in the buffer where text might be inserted
- if the user is typing sequential chars)
- \todo unicode check
+ in the buffer where text might be inserted
+ if the user is typing sequential chars)
*/
Fl_Text_Buffer(int requestedSize = 0, int preferredGapSize = 1024);
/**
Frees a text buffer
- \todo unicode check
*/
~Fl_Text_Buffer();
@@ -239,15 +237,16 @@
\param start byte offset to first character
\param end byte offset after last character in range
\return newly allocated text buffer - must be free'd
- */
+ */
char* text_range(int start, int end) const;
/**
Returns the character at the specified position pos in the buffer.
Positions start at 0
- \todo unicode check
+ \param pos byte offset into buffer
+ \return Unicode UCS-4 encoded character
*/
- char character(int pos) const;
+ unsigned int character(int pos) const;
/**
Returns the text from the given rectangle. When you are done
@@ -258,7 +257,8 @@
/**
Inserts null-terminated string \p text at position \p pos.
- \todo unicode check
+ \param pos insertion position as byte offset (must be utf-8 character
aligned)
+ \param text utf-8 encoded and nul terminated text
*/
void insert(int pos, const char* text);
@@ -270,13 +270,16 @@
/**
Deletes a range of characters in the buffer.
- \todo unicode check
+ \param start byte offset to first character to be removed
+ \param end byte offset to charcatre after last character to be removed
*/
void remove(int start, int end);
/**
Deletes the characters between \p start and \p end, and inserts the
null-terminated string \p text in their place in the buffer.
- \todo unicode check
+ \param start byte offset to first character to be removed and new insert
position
+ \param end byte offset to charcatre after last character to be removed
+ \param text utf-8 encoded and nul terminated text
*/
void replace(int start, int end, const char *text);
@@ -296,7 +299,6 @@
/**
Lets the undo system know if we can undo changes
- \todo unicode check
*/
void canUndo(char flag=1);
Modified: branches/branch-1.3/src/Fl_Text_Buffer.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Text_Buffer.cxx 2010-04-06 20:36:34 UTC (rev
7461)
+++ branches/branch-1.3/src/Fl_Text_Buffer.cxx 2010-04-06 23:00:56 UTC (rev
7462)
@@ -161,6 +161,8 @@
}
}
+
+// unicode ok
Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize)
{
mLength = 0;
@@ -196,6 +198,8 @@
#endif
}
+
+// unicode ok
Fl_Text_Buffer::~Fl_Text_Buffer()
{
free(mBuf);
@@ -221,6 +225,8 @@
return t;
}
+
+// unicode ok, functions called have not been verified yet
void Fl_Text_Buffer::text(const char *t)
{
call_predelete_callbacks(0, length());
@@ -230,14 +236,13 @@
int deletedLength = mLength;
free((void *) mBuf);
- /* Start a new buffer with a gap of mPreferredGapSize in the center */
+ /* Start a new buffer with a gap of mPreferredGapSize at the end */
int insertedLength = strlen(t);
mBuf = (char *) malloc(insertedLength + mPreferredGapSize);
mLength = insertedLength;
- mGapStart = insertedLength / 2;
+ mGapStart = insertedLength;
mGapEnd = mGapStart + mPreferredGapSize;
- memcpy(mBuf, t, mGapStart);
- memcpy(&mBuf[mGapEnd], &t[mGapStart], insertedLength - mGapStart);
+ memcpy(mBuf, t, insertedLength);
#ifdef PURIFY
{
int i;
@@ -293,17 +298,17 @@
}
-// FIXME: a character must be UCS-4 encoded
-char Fl_Text_Buffer::character(int pos) const {
+// TODO: we will need the same signature function to get bytes (style buffer)
+// unicode ok
+unsigned int Fl_Text_Buffer::character(int pos) const {
if (pos < 0 || pos >= mLength)
return '\0';
- if (pos < mGapStart)
- return mBuf[pos];
- else
- return mBuf[pos + mGapEnd - mGapStart];
+ const char *src = address(pos);
+ return fl_utf8decode(src, 0, 0);
}
+// unicode ok, dependents not tested
void Fl_Text_Buffer::insert(int pos, const char *text)
{
/* if pos is not contiguous to existing text, make it */
@@ -321,6 +326,8 @@
call_modify_callbacks(pos, 0, nInserted, 0, NULL);
}
+
+// unicode ok, dependents not tested
void Fl_Text_Buffer::replace(int start, int end, const char *text)
{
// Range check...
@@ -334,13 +341,14 @@
call_predelete_callbacks(start, end - start);
const char *deletedText = text_range(start, end);
remove_(start, end);
- //undoyankcut = undocut;
int nInserted = insert_(start, text);
mCursorPosHint = start + nInserted;
call_modify_callbacks(start, end - start, nInserted, 0, deletedText);
free((void *) deletedText);
}
+
+// unicode ok, dependents not tested
void Fl_Text_Buffer::remove(int start, int end)
{
/* Make sure the arguments make sense */
@@ -441,6 +449,8 @@
return 1;
}
+
+// unicode ok
void Fl_Text_Buffer::canUndo(char flag)
{
mCanUndo = flag;
@@ -918,26 +928,34 @@
char *Fl_Text_Buffer::line_text(int pos) const {
return text_range(line_start(pos), line_end(pos));
-} int Fl_Text_Buffer::line_start(int pos) const {
+}
+
+int Fl_Text_Buffer::line_start(int pos) const {
if (!findchar_backward(pos, '\n', &pos))
return 0;
return pos + 1;
-} int Fl_Text_Buffer::line_end(int pos) const {
+}
+
+int Fl_Text_Buffer::line_end(int pos) const {
if (!findchar_forward(pos, '\n', &pos))
pos = mLength;
return pos;
-} int Fl_Text_Buffer::word_start(int pos) const {
- while (pos && (isalnum(character(pos)) || character(pos) == '_'))
- {
+}
+
+int Fl_Text_Buffer::word_start(int pos) const {
+ // FIXME: character is ucs-4
+ while (pos && (isalnum(character(pos)) || character(pos) == '_')) {
pos--;
- } if (!(isalnum(character(pos)) || character(pos) == '_'))
+ }
+ // FIXME: character is ucs-4
+ if (!(isalnum(character(pos)) || character(pos) == '_'))
pos++;
return pos;
}
int Fl_Text_Buffer::word_end(int pos) const {
- while (pos < length()
- && (isalnum(character(pos)) || character(pos) == '_'))
+ // FIXME: character is ucs-4
+ while (pos < length() && (isalnum(character(pos)) || character(pos) == '_'))
{
pos++;
} return pos;
@@ -1121,13 +1139,13 @@
int Fl_Text_Buffer::search_forward(int startPos, const char *searchString,
int *foundPos,
- int matchCase) const {
+ int matchCase) const
+{
if (!searchString)
return 0;
int bp;
const char *sp;
- while (startPos < length())
- {
+ while (startPos < length()) {
bp = startPos;
sp = searchString;
do {
@@ -1135,6 +1153,7 @@
*foundPos = startPos;
return 1;
}
+ // FIXME: character is ucs-4
} while ((matchCase ? character(bp++) == *sp++ :
toupper(character(bp++)) == toupper(*sp++))
&& bp < length());
@@ -1159,6 +1178,7 @@
*foundPos = bp + 1;
return 1;
}
+ // FIXME: character is ucs-4
} while ((matchCase ? character(bp--) == *sp-- :
toupper(character(bp--)) == toupper(*sp--))
&& bp >= 0);
@@ -1331,7 +1351,7 @@
is counted with the length of insText) */
int start = line_start(startPos);
int nLines = countLines(insText) + 1;
- int insWidth = textWidth(insText, mTabDist);
+ int insWidth = textWidth(insText, mTabDist); // this function probably
returns a useless value
int end = line_end(skip_lines(start, nLines - 1));
int expReplLen, expInsLen, len, endOffset;
const char *replText = text_range(start, end);
@@ -2137,14 +2157,15 @@
{
int width = 0, maxWidth = 0;
- for (const char *c = text; *c != '\0'; c++) { // FIXME: increment is wrong!
+ // HUH? Why is "c" incremented? Shouldn't "text" be incrmented?
+ // FIXME: increment is wrong!
+ for (const char *c = text; *c != '\0'; c++) {
if (*c == '\n') {
if (width > maxWidth)
maxWidth = width;
width = 0;
} else
- width +=
- Fl_Text_Buffer::character_width(c, width, tabDist);
+ width += Fl_Text_Buffer::character_width(c, width, tabDist);
}
if (width > maxWidth)
return width;
@@ -2163,11 +2184,12 @@
/* find the start of the selection */
for (pos = lineStartPos; pos < mLength; pos++)
{
+ // FIXME: character is ucs-4
c = character(pos);
if (c == '\n')
break;
width =
- Fl_Text_Buffer::character_width(&c, indent, mTabDist); // FIXME: c si not
unicode
+ Fl_Text_Buffer::character_width(&c, indent, mTabDist); // FIXME: c is not
unicode
if (indent + width > rectStart) {
if (indent != rectStart && c != '\t') {
pos++;
@@ -2181,6 +2203,7 @@
/* find the end */
for (; pos < mLength; pos++) {
+ // FIXME: character is ucs-4
c = character(pos);
if (c == '\n')
break;
@@ -2338,7 +2361,7 @@
int buflen)
{
FILE *fp;
- if (!(fp = fl_fopen(file, "w")))
+ if (!(fp = fl_fopen(file, "wb")))
return 1;
for (int n; (n = min(end - start, buflen)); start += n) {
const char *p = text_range(start, start + n);
Modified: branches/branch-1.3/src/Fl_Text_Display.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Text_Display.cxx 2010-04-06 20:36:34 UTC (rev
7461)
+++ branches/branch-1.3/src/Fl_Text_Display.cxx 2010-04-06 23:00:56 UTC (rev
7462)
@@ -426,6 +426,7 @@
void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
int ok = 0;
while (!ok && startpos > 0) {
+ // FIXME: character is ucs-4
char c = buffer()->character( startpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -434,6 +435,7 @@
}
}
while (!ok && endpos < buffer()->length()) {
+ // FIXME: character is ucs-4
char c = buffer()->character( endpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -638,6 +640,7 @@
for ( p = startPos; ; p++ ) {
if ( p == buf->length() )
break;
+ // FIXME: character is ucs-4
ch = buf->character( p );
if ( ch == '\n' )
break;
@@ -779,6 +782,7 @@
Fl_Text_Buffer *buf = mBuffer;
int ok = 0;
while (!ok) {
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -894,6 +898,7 @@
return 0;
insert_position( mCursorPos + 1 );
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) ok = 1;
}
@@ -907,6 +912,7 @@
return 0;
insert_position( mCursorPos - 1 );
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) ok = 1;
}
@@ -947,6 +953,7 @@
int ok = 0;
while (!ok) {
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -983,6 +990,7 @@
int ok = 0;
while (!ok) {
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -1132,9 +1140,11 @@
/** Moves the current insert position right one word.*/
void Fl_Text_Display::next_word() {
int pos = insert_position();
+ // FIXME: character is ucs-4
while (pos < buffer()->length() &&
!fl_isseparator(buffer()->character(pos))) {
pos++;
}
+ // FIXME: character is ucs-4
while (pos < buffer()->length() && fl_isseparator(buffer()->character(pos)))
{
pos++;
}
@@ -1147,12 +1157,15 @@
int pos = insert_position();
if (pos==0) return;
pos--;
+ // FIXME: character is ucs-4
while (pos && fl_isseparator(buffer()->character(pos))) {
pos--;
}
+ // FIXME: character is ucs-4
while (pos && !fl_isseparator(buffer()->character(pos))) {
pos--;
}
+ // FIXME: character is ucs-4
if (fl_isseparator(buffer()->character(pos))) pos++;
insert_position( pos );
@@ -1820,10 +1833,12 @@
if ( lineIndex >= lineLen )
style = FILL_MASK;
else if ( styleBuf != NULL ) {
+ // FIXME: character is ucs-4
style = ( unsigned char ) styleBuf->character( pos );
if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
/* encountered "unfinished" style, trigger parsing */
(mUnfinishedHighlightCB)( pos, mHighlightCBArg);
+ // FIXME: character is ucs-4
style = (unsigned char) styleBuf->character( pos);
}
}
@@ -2344,6 +2359,7 @@
for ( i = 0; i < lineLen; i++ ) {
len = mBuffer->expand_character( lineStartPos + i,
charCount, expandedChar );
+ // FIXME: character is ucs-4
style = ( unsigned char ) mStyleBuffer->character(
lineStartPos + i ) - 'A';
@@ -2452,6 +2468,7 @@
lineStart = retPos;
nLines++;
if (lineStart > pos + nInserted &&
+ // FIXME: character is ucs-4
buf->character(lineStart-1) == '\n') {
countTo = lineStart;
*modRangeEnd = lineStart;
@@ -2597,6 +2614,7 @@
lineStart = retPos;
nLines++;
if (lineStart > pos + nDeleted &&
+ // FIXME: character is ucs-4
buf->character(lineStart-1) == '\n') {
break;
}
@@ -2674,6 +2692,7 @@
colNum = 0;
width = 0;
for (p=lineStart; p<buf->length(); p++) {
+ // FIXME: character is ucs-4
c = (unsigned char)buf->character(p);
/* If the character was a newline, count the line and start over,
@@ -2708,6 +2727,7 @@
if (colNum > wrapMargin || width > maxWidth) {
foundBreak = false;
for (b=p; b>=lineStart; b--) {
+ // FIXME: character is ucs-4
c = (unsigned char)buf->character(b);
if (c == '\t' || c == ' ') {
newLineStart = b + 1;
@@ -2716,6 +2736,7 @@
width = 0;
for (i=b+1; i<p+1; i++) {
width += measure_proportional_character(
+ // FIXME:
character is ucs-4
buf->character(i), colNum,
i+styleBufOffset);
colNum++;
@@ -2784,10 +2805,12 @@
if (styleBuf == 0) {
style = 0;
} else {
+ // FIXME: character is ucs-4
style = (unsigned char)styleBuf->character(pos);
if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
/* encountered "unfinished" style, trigger parsing */
(mUnfinishedHighlightCB)(pos, mHighlightCBArg);
+ // FIXME: character is ucs-4
style = (unsigned char)styleBuf->character(pos);
}
}
@@ -2844,6 +2867,7 @@
if (!mContinuousWrap || lineEndPos == buffer()->length())
return 1;
+ // FIXME: character is ucs-4
c = buffer()->character(lineEndPos);
return c == '\n' || ((c == '\t' || c == ' ') &&
lineEndPos + 1 != buffer()->length());
@@ -3123,6 +3147,7 @@
int pos = xy_to_position(Fl::event_x(), Fl::event_y(), CURSOR_POS);
int ok = 0;
while (!ok) {
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -3188,6 +3213,7 @@
pos = xy_to_position(X, Y, CURSOR_POS);
int ok = 0;
while (!ok) {
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
Modified: branches/branch-1.3/src/Fl_Text_Editor.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Text_Editor.cxx 2010-04-06 20:36:34 UTC (rev
7461)
+++ branches/branch-1.3/src/Fl_Text_Editor.cxx 2010-04-06 23:00:56 UTC (rev
7462)
@@ -254,6 +254,7 @@
int Fl_Text_Editor::kf_backspace(int, Fl_Text_Editor* e) {
if (!e->buffer()->selected() && e->move_left()) {
int l = 1;
+ // FIXME: character is ucs-4
char c = e->buffer()->character(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
@@ -449,6 +450,7 @@
int Fl_Text_Editor::kf_delete(int, Fl_Text_Editor* e) {
if (!e->buffer()->selected()) {
int l = 1;
+ // FIXME: character is ucs-4
char c = e->buffer()->character(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit