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
+1 -1
View File
@@ -114,7 +114,7 @@ void KeywordReminderTextValue::highlight(const String& code, const vector<Script
// process a character
Char c = code.GetChar(pos);
if (c == _('<')) {
new_value += _('\1'); // escape
new_value += ESCAPED_LANGLE; // escape
++pos;
} else if (c == _('{')) {
if (in_string) {
+3 -3
View File
@@ -160,7 +160,7 @@ class TagStack {
String html_escape(const String& str) {
String ret;
FOR_EACH_CONST(c, str) {
if (c == _('\1') || c == _('<')) { // escape <
if (c == ESCAPED_LANGLE || c == _('<')) { // escape <
ret += _("&lt;");
} else if (c == _('>')) { // escape >
ret += _("&gt;");
@@ -209,8 +209,8 @@ String to_html(const String& str_in, const SymbolFontP& symbol_font, double symb
String str = remove_tag_contents(str_in,_("<sep-soft"));
String ret;
Tag bold (_("<b>"), _("</b>")),
italic(_("<i>"), _("</i>")),
symbol(_("<span class=\"symbol\">"), _("</span>"));
italic(_("<i>"), _("</i>")),
symbol(_("<span class=\"symbol\">"), _("</span>"));
TagStack tags;
String symbols;
for (size_t i = 0 ; i < str.size() ; ) {
+2 -1
View File
@@ -11,6 +11,7 @@
#include <script/parser.hpp>
#include <script/to_value.hpp>
#include <util/error.hpp>
#include <util/tagged_string.hpp>
#include <util/io/package_manager.hpp> // for "include file" semi hack
#include <stack>
@@ -281,7 +282,7 @@ void TokenIterator::readStringToken(bool string_mode) {
else if (c == _('r')) str += _('\r');
else if (c == _('t')) str += _('\t');
else if (c == _('&')); // escape for nothing
else if (c == _('<')) str += _('\1'); // escape for < in tagged string
else if (c == _('<')) str += ESCAPED_LANGLE; // escape for < in tagged string
else if (c == _('\\') || c == _('"') || c == _('\'') || c == _('{') || c == _('}')) {
str += c; // \ or { or " or ', don't warn about these, since they look escape-worthy
} else if (c >= '0' && c <= '9') {
+2 -1
View File
@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/tagged_string.hpp>
#include <script/value.hpp>
#include <script/to_value.hpp>
#include <script/context.hpp>
@@ -305,7 +306,7 @@ String quote_string(String const& str) {
out += _('"');
FOR_EACH_CONST(c, str) {
if (c == _('"') || c == _('\\')) { out += _('\\'); out += c; }
else if (c == _('\1')) out += _("\\<");
else if (c == ESCAPED_LANGLE) out += _("\\<");
else if (c == _('\n')) out += _("\\n");
else if (c == _('\r')) out += _("\\r");
else if (c == _('\t')) out += _("\\t");
+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