Add constant for escaped <

This commit is contained in:
Twan van Laarhoven
2020-05-12 21:10:01 +02:00
parent 48dcdb8e59
commit 7781a428f6
6 changed files with 40 additions and 25 deletions
+26 -16
View File
@@ -12,36 +12,46 @@
// ----------------------------------------------------------------------------- : Conversion to/from normal string
Char untag_char(Char c) {
if (c == _('\1')) return _('<');
wxUniChar untag_char(wxUniChar c) {
if (c == ESCAPED_LANGLE) return _('<');
else if (c == CONNECTION_SPACE) return _(' ');
else return c;
}
Char tag_char(Char c) {
if (c == _('<')) return _('\1');
wxUniChar tag_char(wxUniChar c) {
if (c == _('<')) return ESCAPED_LANGLE;
else return c;
}
String untag(const String& str) {
bool intag = false;
String ret; ret.reserve(str.size());
FOR_EACH_CONST(c, str) {
if (c==_('<')) intag = true;
if (!intag) ret += untag_char(c);
if (c==_('>')) intag = false;
bool in_tag = false;
String ret;
ret.reserve(str.size());
for(wxUniChar c : str) {
if (c == _('<')) {
in_tag = true;
} else if (!in_tag) {
ret += untag_char(c);
} else if (c == _('>')) {
in_tag = false;
}
}
return ret;
}
String untag_no_escape(const String& str) {
bool intag = false;
String ret; ret.reserve(str.size());
FOR_EACH_CONST(c, str) {
if (c==_('<')) intag = true;
if (!intag) ret += c;
if (c==_('>')) intag = false;
bool in_tag = false;
String ret;
ret.reserve(str.size());
for (wxUniChar c : str) {
if (c == _('<')) {
in_tag = true;
} else if (!in_tag) {
ret += c;
} else if (c == _('>')) {
in_tag = false;
}
}
return ret;
}
+6 -3
View File
@@ -17,8 +17,11 @@
// ----------------------------------------------------------------------------- : Conversion to/from normal string
Char untag_char(Char c);
Char tag_char(Char c);
/// Escaped '<'
const Char ESCAPED_LANGLE = _('\1');
wxUniChar untag_char(wxUniChar c);
wxUniChar tag_char(wxUniChar c);
/// Remove all tags from a string and convert escaped '<' back to normal '<'
/** e.g. "<sym>R</> something <i>(note)</>"
@@ -35,7 +38,7 @@ String untag_no_escape(const String&);
*/
String untag_hide_sep(const String&);
/// Escapes a String by converting '>' to '\1'
/// Escapes a String by converting '>' to ESCAPED_LANGLE
String escape(const String&);
/// Convert old style </> close tags to new style </tag> tags