mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 05:36:59 -04:00
Add constant for escaped <
This commit is contained in:
@@ -114,7 +114,7 @@ void KeywordReminderTextValue::highlight(const String& code, const vector<Script
|
|||||||
// process a character
|
// process a character
|
||||||
Char c = code.GetChar(pos);
|
Char c = code.GetChar(pos);
|
||||||
if (c == _('<')) {
|
if (c == _('<')) {
|
||||||
new_value += _('\1'); // escape
|
new_value += ESCAPED_LANGLE; // escape
|
||||||
++pos;
|
++pos;
|
||||||
} else if (c == _('{')) {
|
} else if (c == _('{')) {
|
||||||
if (in_string) {
|
if (in_string) {
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ class TagStack {
|
|||||||
String html_escape(const String& str) {
|
String html_escape(const String& str) {
|
||||||
String ret;
|
String ret;
|
||||||
FOR_EACH_CONST(c, str) {
|
FOR_EACH_CONST(c, str) {
|
||||||
if (c == _('\1') || c == _('<')) { // escape <
|
if (c == ESCAPED_LANGLE || c == _('<')) { // escape <
|
||||||
ret += _("<");
|
ret += _("<");
|
||||||
} else if (c == _('>')) { // escape >
|
} else if (c == _('>')) { // escape >
|
||||||
ret += _(">");
|
ret += _(">");
|
||||||
@@ -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 str = remove_tag_contents(str_in,_("<sep-soft"));
|
||||||
String ret;
|
String ret;
|
||||||
Tag bold (_("<b>"), _("</b>")),
|
Tag bold (_("<b>"), _("</b>")),
|
||||||
italic(_("<i>"), _("</i>")),
|
italic(_("<i>"), _("</i>")),
|
||||||
symbol(_("<span class=\"symbol\">"), _("</span>"));
|
symbol(_("<span class=\"symbol\">"), _("</span>"));
|
||||||
TagStack tags;
|
TagStack tags;
|
||||||
String symbols;
|
String symbols;
|
||||||
for (size_t i = 0 ; i < str.size() ; ) {
|
for (size_t i = 0 ; i < str.size() ; ) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <script/parser.hpp>
|
#include <script/parser.hpp>
|
||||||
#include <script/to_value.hpp>
|
#include <script/to_value.hpp>
|
||||||
#include <util/error.hpp>
|
#include <util/error.hpp>
|
||||||
|
#include <util/tagged_string.hpp>
|
||||||
#include <util/io/package_manager.hpp> // for "include file" semi hack
|
#include <util/io/package_manager.hpp> // for "include file" semi hack
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
@@ -281,7 +282,7 @@ void TokenIterator::readStringToken(bool string_mode) {
|
|||||||
else if (c == _('r')) str += _('\r');
|
else if (c == _('r')) str += _('\r');
|
||||||
else if (c == _('t')) str += _('\t');
|
else if (c == _('t')) str += _('\t');
|
||||||
else if (c == _('&')); // escape for nothing
|
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 == _('}')) {
|
else if (c == _('\\') || c == _('"') || c == _('\'') || c == _('{') || c == _('}')) {
|
||||||
str += c; // \ or { or " or ', don't warn about these, since they look escape-worthy
|
str += c; // \ or { or " or ', don't warn about these, since they look escape-worthy
|
||||||
} else if (c >= '0' && c <= '9') {
|
} else if (c >= '0' && c <= '9') {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
// ----------------------------------------------------------------------------- : Includes
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
#include <util/prec.hpp>
|
#include <util/prec.hpp>
|
||||||
|
#include <util/tagged_string.hpp>
|
||||||
#include <script/value.hpp>
|
#include <script/value.hpp>
|
||||||
#include <script/to_value.hpp>
|
#include <script/to_value.hpp>
|
||||||
#include <script/context.hpp>
|
#include <script/context.hpp>
|
||||||
@@ -305,7 +306,7 @@ String quote_string(String const& str) {
|
|||||||
out += _('"');
|
out += _('"');
|
||||||
FOR_EACH_CONST(c, str) {
|
FOR_EACH_CONST(c, str) {
|
||||||
if (c == _('"') || c == _('\\')) { out += _('\\'); out += c; }
|
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 == _('\n')) out += _("\\n");
|
||||||
else if (c == _('\r')) out += _("\\r");
|
else if (c == _('\r')) out += _("\\r");
|
||||||
else if (c == _('\t')) out += _("\\t");
|
else if (c == _('\t')) out += _("\\t");
|
||||||
|
|||||||
+26
-16
@@ -12,36 +12,46 @@
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Conversion to/from normal string
|
// ----------------------------------------------------------------------------- : Conversion to/from normal string
|
||||||
|
|
||||||
Char untag_char(Char c) {
|
wxUniChar untag_char(wxUniChar c) {
|
||||||
if (c == _('\1')) return _('<');
|
if (c == ESCAPED_LANGLE) return _('<');
|
||||||
else if (c == CONNECTION_SPACE) return _(' ');
|
else if (c == CONNECTION_SPACE) return _(' ');
|
||||||
else return c;
|
else return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
Char tag_char(Char c) {
|
wxUniChar tag_char(wxUniChar c) {
|
||||||
if (c == _('<')) return _('\1');
|
if (c == _('<')) return ESCAPED_LANGLE;
|
||||||
else return c;
|
else return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String untag(const String& str) {
|
String untag(const String& str) {
|
||||||
bool intag = false;
|
bool in_tag = false;
|
||||||
String ret; ret.reserve(str.size());
|
String ret;
|
||||||
FOR_EACH_CONST(c, str) {
|
ret.reserve(str.size());
|
||||||
if (c==_('<')) intag = true;
|
for(wxUniChar c : str) {
|
||||||
if (!intag) ret += untag_char(c);
|
if (c == _('<')) {
|
||||||
if (c==_('>')) intag = false;
|
in_tag = true;
|
||||||
|
} else if (!in_tag) {
|
||||||
|
ret += untag_char(c);
|
||||||
|
} else if (c == _('>')) {
|
||||||
|
in_tag = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
String untag_no_escape(const String& str) {
|
String untag_no_escape(const String& str) {
|
||||||
bool intag = false;
|
bool in_tag = false;
|
||||||
String ret; ret.reserve(str.size());
|
String ret;
|
||||||
FOR_EACH_CONST(c, str) {
|
ret.reserve(str.size());
|
||||||
if (c==_('<')) intag = true;
|
for (wxUniChar c : str) {
|
||||||
if (!intag) ret += c;
|
if (c == _('<')) {
|
||||||
if (c==_('>')) intag = false;
|
in_tag = true;
|
||||||
|
} else if (!in_tag) {
|
||||||
|
ret += c;
|
||||||
|
} else if (c == _('>')) {
|
||||||
|
in_tag = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,11 @@
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Conversion to/from normal string
|
// ----------------------------------------------------------------------------- : Conversion to/from normal string
|
||||||
|
|
||||||
Char untag_char(Char c);
|
/// Escaped '<'
|
||||||
Char tag_char(Char c);
|
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 '<'
|
/// Remove all tags from a string and convert escaped '<' back to normal '<'
|
||||||
/** e.g. "<sym>R</> something <i>(note)</>"
|
/** e.g. "<sym>R</> something <i>(note)</>"
|
||||||
@@ -35,7 +38,7 @@ String untag_no_escape(const String&);
|
|||||||
*/
|
*/
|
||||||
String untag_hide_sep(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&);
|
String escape(const String&);
|
||||||
|
|
||||||
/// Convert old style </> close tags to new style </tag> tags
|
/// Convert old style </> close tags to new style </tag> tags
|
||||||
|
|||||||
Reference in New Issue
Block a user