[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pan-devel] patch for minor utf8 issue
From: |
K. Haley |
Subject: |
[Pan-devel] patch for minor utf8 issue |
Date: |
Sat, 15 Apr 2006 23:26:16 -0600 |
User-agent: |
Thunderbird 1.5 (Windows/20051201) |
There is a potential problem in handling bold,italic,underline text when
there are multibyte characters in the text. This patch fixes the
problem by properly iterating over characters instead of bytes. The
actuall tests remain the same, only the iteration is changed to prevent
a false positive. Besides, does anyone know what would happen if you
set a tag in the middle of a multibyte character?
--- old/pan/gui/body-pane.cc Fri Apr 14 18:17:33 2006
+++ new/pan/gui/body-pane.cc Sat Apr 15 23:13:40 2006
@@ -456,18 +456,20 @@
const char * e (v_all.end());
enum { NORMAL, UNDERLINE, BOLD, ITALIC };
int mode = NORMAL;
- for (const char * pch(b); pch!=e; ++pch) {
- if (*pch=='_' && mode==UNDERLINE && (pch+1==e || ::isspace(pch[1]) ||
::ispunct(pch[1])))
- set_section_tag (buffer, &start, v_all,
StringView(mode_begin,pch+1-mode_begin), "underline");
- if (*pch=='/' && mode==ITALIC && (pch+1==e || ::isspace(pch[1]) ||
::ispunct(pch[1])))
- set_section_tag (buffer, &start, v_all,
StringView(mode_begin,pch+1-mode_begin), "italic");
- if (*pch=='*' && mode==BOLD && (pch+1==e || ::isspace(pch[1]) ||
::ispunct(pch[1])))
- set_section_tag (buffer, &start, v_all,
StringView(mode_begin,pch+1-mode_begin), "bold");
- else if (*pch=='_' && (pch==b ||isspace(pch[-1])))
+ for (const char * pch(b),*p(b),*n(b); pch!=e;p=pch,pch=n) {
+ if(n!=e)
+ n=g_utf8_next_char(n);
+ if (*pch=='_' && mode==UNDERLINE && (n==e || ::isspace(*n) ||
::ispunct(*n)))
+ set_section_tag (buffer, &start, v_all,
StringView(mode_begin,n-mode_begin), "underline");
+ if (*pch=='/' && mode==ITALIC && (n==e || ::isspace(*n) ||
::ispunct(*n)))
+ set_section_tag (buffer, &start, v_all,
StringView(mode_begin,n-mode_begin), "italic");
+ if (*pch=='*' && mode==BOLD && (n==e || ::isspace(*n) ||
::ispunct(*n)))
+ set_section_tag (buffer, &start, v_all,
StringView(mode_begin,n-mode_begin), "bold");
+ else if (*pch=='_' && (pch==b ||isspace(*p)))
{ mode = UNDERLINE; mode_begin=pch; }
- else if (*pch=='*' && (pch==b ||isspace(pch[-1])))
+ else if (*pch=='*' && (pch==b ||isspace(*p)))
{ mode = BOLD; mode_begin=pch; }
- else if (*pch=='/' && (pch==b ||isspace(pch[-1])))
+ else if (*pch=='/' && (pch==b ||isspace(*p)))
{ mode = ITALIC; mode_begin=pch; }
else if (isspace(*pch))
{ mode = NORMAL; mode_begin=pch; }
signature.asc
Description: OpenPGP digital signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pan-devel] patch for minor utf8 issue,
K. Haley <=