DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2348
Version: 1.3-current
Link: http://www.fltk.org/str.php?L2348
Version: 1.3-current
Index: src/Fl_Text_Buffer.cxx
===================================================================
--- src/Fl_Text_Buffer.cxx (revision 7555)
+++ src/Fl_Text_Buffer.cxx (working copy)
@@ -161,7 +161,6 @@
}
}
-
// unicode ok
Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize)
{
@@ -304,7 +303,8 @@
if (pos < 0 || pos >= mLength)
return '\0';
const char *src = address(pos);
- return fl_utf8decode(src, 0, 0);
+ const char *end = src + 6; // max number of bytes allowed in UTF-8 sequence
+ return fl_utf8decode(src, end, 0);
}
@@ -995,19 +995,14 @@
} else if (c == 127) {
sprintf(outStr, "<del>");
return 5;
- } else if ((c & 0x80) && !(c & 0x40)) {
-#ifdef DEBUG
- fprintf(stderr, "%s:%d - Error in UTF-8 encoding!\n", __FILE__, __LINE__);
-#endif
- *outStr = c;
- return 1;
} else if (c & 0x80) {
- int i, n = fl_utf8len(c);
- for (i=0; i<n; i++) *outStr++ = *src++;
- return n;
+ int len = fl_drg8len(src);
+ for (int i = 0; i < len; i++)
+ *outStr++ = *src++;
+ return len;
}
- /* Otherwise, just return the character */
+ /* Otherwise, it's plain ascii, so just return the character */
*outStr = c;
return 1;
}
@@ -1021,24 +1016,21 @@
int Fl_Text_Buffer::character_width(const char *src, int indent, int tabDist)
{
char c = *src;
- if ((c & 0x80) && (c & 0x40)) { // first byte of UTF-8 sequence
- int len = fl_utf8len(c);
- int ret = 0;
- unsigned int ucs = fl_utf8decode(src, src+len, &ret);
- int width = fl_wcwidth_(ucs); // FIXME
+ if (c & 0x80) {
+ const char* end = src + 6; // max number of bytes allowed in UTF-8 sequence
+ int len = 0;
+ unsigned int ucs = fl_utf8decode(src, end, &len);
+ int width = fl_wcwidth_(ucs); // FIXME with fl_wcwidth(src)
// fprintf(stderr, "mk_wcwidth(%x) -> %d (%d, %d, %s)\n", ucs, width, len,
ret, src);
return width;
}
- if ((c & 0x80) && !(c & 0x40)) { // other byte of UTF-8 sequence
- return 0;
- }
- return character_width(c, indent, tabDist);
+ return character_width0(c, indent, tabDist);
}
// FIXME: merge the following with the char* version above.
// but the question then is: how to reorganise expand_character()?
//
-int Fl_Text_Buffer::character_width(const char c, int indent, int tabDist)
+int Fl_Text_Buffer::character_width0(const char c, int indent, int tabDist)
{
/* Note, this code must parallel that in Fl_Text_Buffer::ExpandCharacter */
if (c == '\t') {
@@ -1046,15 +1038,7 @@
} else if (((unsigned char) c) <= 31) {
return strlen(ControlCodeTable[(unsigned char) c]) + 2;
} else if (c == 127) {
- return 5;
- } else if ((c & 0x80) && !(c & 0x40)) {
-#ifdef DEBUG
- fprintf(stderr, "%s:%d - Error in UTF-8 encoding!\n", __FILE__, __LINE__);
-#endif
- return 1;
- } else if (c & 0x80) {
- // return fl_utf8len(c);
- return 1;
+ return 5; // i.e. strlen("<del>");
}
return 1;
}
@@ -1084,7 +1068,9 @@
if (c == '\n')
return pos;
charCount += character_width(src, charCount, mTabDist);
- pos += fl_utf8len(c);
+
+ int len = fl_drg8len(src);
+ pos += len;
}
return pos;
}
@@ -1934,13 +1920,15 @@
for (int i = 0; i < mNModifyProcs; i++)
(*mModifyProcs[i]) (pos, nInserted, nDeleted, nRestyled,
deletedText, mCbArgs[i]);
-} void Fl_Text_Buffer::call_predelete_callbacks(int pos, int nDeleted) const {
+}
+
+void Fl_Text_Buffer::call_predelete_callbacks(int pos, int nDeleted) const {
for (int i = 0; i < mNPredeleteProcs; i++)
(*mPredeleteProcs[i]) (pos, nDeleted, mPredeleteCbArgs[i]);
-} void Fl_Text_Buffer::redisplay_selection(Fl_Text_Selection *
- oldSelection,
- Fl_Text_Selection *
- newSelection) const
+}
+
+void Fl_Text_Buffer::redisplay_selection(Fl_Text_Selection *oldSelection,
+ Fl_Text_Selection *newSelection) const
{
int oldStart, oldEnd, newStart, newEnd, ch1Start, ch1End, ch2Start,
ch2End;
Index: src/Fl_Text_Display.cxx
===================================================================
--- src/Fl_Text_Display.cxx (revision 7555)
+++ src/Fl_Text_Display.cxx (working copy)
@@ -443,6 +443,7 @@
endpos++;
}
}
+
if (damage_range1_start == -1 && damage_range1_end == -1) {
damage_range1_start = startpos;
damage_range1_end = endpos;
@@ -728,7 +729,7 @@
outIndex = 0;
for (charIndex = 0;
charIndex < lineLen && charIndex < pos - lineStartPos;
- charIndex += fl_utf8len(lineStr[charIndex]) )
+ charIndex += fl_drg8len(lineStr + charIndex) )
{
charLen = Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex,
expandedChar,
mBuffer->tab_distance());
@@ -1483,7 +1484,7 @@
that character */
X = text_area.x - mHorizOffset;
outIndex = 0;
- for ( charIndex = 0; ; charIndex += lineStr ? fl_utf8len(lineStr[charIndex])
: 1 ) {
+ for ( charIndex = 0; ; charIndex += lineStr ? fl_drg8len(lineStr+charIndex)
: 1 ) {
charLen = charIndex >= lineLen ? 1 :
Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex,
expandedChar,
buf->tab_distance());
@@ -1513,7 +1514,7 @@
X = startX;
for (charIndex = startIndex;
charIndex < rightCharIndex;
- charIndex += lineStr ? fl_utf8len(lineStr[charIndex]) : 1 )
+ charIndex += lineStr ? fl_drg8len(lineStr+charIndex) : 1 )
{
charLen = charIndex >= lineLen ? 1 :
Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex,
expandedChar,
@@ -1555,7 +1556,7 @@
X = startX;
for (charIndex = startIndex;
charIndex < rightCharIndex;
- charIndex += lineStr ? fl_utf8len(lineStr[charIndex]) : 0)
+ charIndex += lineStr ? fl_drg8len(lineStr+charIndex) : 0)
{
charLen = charIndex >= lineLen ? 1 :
Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex,
expandedChar,
@@ -1912,7 +1913,7 @@
outIndex = 0;
for (charIndex = 0;
charIndex < lineLen;
- charIndex += fl_utf8len(lineStr[charIndex]) )
+ charIndex += fl_drg8len(lineStr+charIndex) )
{
charLen = Fl_Text_Buffer::expand_character( lineStr+charIndex, outIndex,
expandedChar,
mBuffer->tab_distance());
Index: src/fl_utf.c
===================================================================
--- src/fl_utf.c (revision 7555)
+++ src/fl_utf.c (working copy)
@@ -894,13 +894,29 @@
characters before calling fl_wcwidth(), and handle them separately.
*/
int fl_wcwidth(const char* src) {
- int len = fl_utf8len(*src);
- int ret = 0;
- unsigned int ucs = fl_utf8decode(src, src+len, &ret);
+ const char* end = src + 6; // max number of bytes allowed in UTF-8 sequence
+ int len = 0;
+ unsigned int ucs = fl_utf8decode(src, end, &len);
int width = fl_wcwidth_(ucs);
return width;
}
+/** number of bytes in next character according to fl_utf8decode().
+ * \param[in] src pointer to start of character
+ * \returns number of bytes
+ *
+ * Use this function in preference to fl_utf8len(char c) because it can
+ * handle the mapping of C1 control characters (0x80 to 0x9f) to CP1252
+ * if that has been enabled in the build options.
+ */
+int fl_drg8len(const char* src) {
+ const char* end = src + 6; // max number of bytes allowed in UTF-8 sequence
+ int len = 0;
+ unsigned int ucs = fl_utf8decode(src, end, &len);
+ ucs = ucs + 1; // keep compiler quiet for the moment
+ return len;
+}
+
/** @} */
/*
Index: FL/fl_utf8.h
===================================================================
--- FL/fl_utf8.h (revision 7555)
+++ FL/fl_utf8.h (working copy)
@@ -146,6 +146,9 @@
* for internal use only */
FL_EXPORT int fl_wcwidth_(unsigned int ucs);
+/* XX: return number of bytes in next character - uses fl_utf8decode() */
+FL_EXPORT int fl_drg8len(const char *src);
+
/* XX: return width of utf-8 character string in columns.
* NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252
mapping,
* depending on original build options */
Index: FL/Fl_Text_Buffer.H
===================================================================
--- FL/Fl_Text_Buffer.H (revision 7555)
+++ FL/Fl_Text_Buffer.H (working copy)
@@ -693,7 +693,7 @@
\return number of byte in substitution
*/
static int character_width(const char *src, int indent, int tabDist);
- static int character_width(const char c, int indent, int tabDist);
+ static int character_width0(const char c, int indent, int tabDist);
/**
Count the number of displayed characters between buffer position
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs