Update of /cvsroot/mahogany/M/src/modules/viewflt
In directory sc8-pr-cvs1:/tmp/cvs-serv11340/src/modules/viewflt
Modified Files:
TextMarkup.cpp
Log Message:
try harder to avoid false positives and handle _stuff_like_this correctly
Index: TextMarkup.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/viewflt/TextMarkup.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -u -2 -r1.2 -r1.3
--- TextMarkup.cpp 6 Dec 2002 16:51:23 -0000 1.2
+++ TextMarkup.cpp 8 Dec 2002 01:11:58 -0000 1.3
@@ -63,5 +63,13 @@
"(c) 2002 Vadim Zeitlin <[EMAIL PROTECTED]>");
-// render all the words surrounded by asterisks/underscores in bold/italic font
+/*
+ render all the words surrounded by asterisks/underscores in bold/italic font
+
+ this is not as simple as it seems, however, because these characters may be
+ used not for markup purposes in the text and we try hard to avoid any false
+ positives while, OTOH, we want to highlight _stuff_like_this_ entirely
+ italicized.
+ */
+
void
TextMarkupFilter::DoProcess(String& text,
@@ -82,4 +90,8 @@
bool atWordStart = true;
+ // is the markup currently in progress continuation of the previous one,
+ // i.e. second or more highlighted word in a row?
+ bool isContinuation;
+
String textNormal,
textSpecial;
@@ -103,6 +115,7 @@
textNormal.clear();
- // change state
+ // change state and reset the associated info
chLastSpecial = *pc;
+ isContinuation = false;
state = chLastSpecial == _T('*') ? Bold : Italic;
}
@@ -115,9 +128,13 @@
else // ending markup tag?
{
- if ( *pc != chLastSpecial )
+ // should we highlight what we've got so far?
+ if ( *pc != chLastSpecial || textSpecial.empty() )
{
- // markup mismatch -- consider there was no intention to use
- // the last special character for markup at all
+ // markup mismatch or nothing between 2 delimiters --
+ // consider there was no intention to use the last special
+ // character for markup at all
textNormal = chLastSpecial + textSpecial + *pc;
+
+ state = Normal;
}
else // matching tag
@@ -132,11 +149,30 @@
font.SetStyle(wxFONTSTYLE_ITALIC);
+ if ( isContinuation )
+ {
+ // we should insert a space to separate the continuation
+ // word from the previous one
+ textSpecial.replace(0, 0, _T(" "));
+ }
+
style.SetFont(font);
m_next->Process(textSpecial, viewer, style);
style.SetFont(fontOld);
+
+ // to handle _the_multi_word_examples_ we suppose that the
+ // markup may continue after the "end" symbol if the next one
+ // is not a space
+ if ( pc[1] != _T('\0') && !wxIsspace(pc[1]) )
+ {
+ // maybe continuation, to be precise
+ isContinuation = true;
+ }
+ else // surely end of markup
+ {
+ state = Normal;
+ }
}
textSpecial.clear();
- state = Normal;
}
break;
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates