summaryrefslogtreecommitdiff
path: root/core/variant_parser.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2020-02-20 18:58:05 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-02-21 14:25:29 +0100
commit3c0059650da3f1feb3c95364d571fe706826dec6 (patch)
treea36ba94f313e2dee88dc2eb253175849fb2d4138 /core/variant_parser.cpp
parent7ac0973e9abb308b91597dd8881aeed62682733c (diff)
Added StringName as a variant type.
Also changed all relevant properties defined manually to StringName.
Diffstat (limited to 'core/variant_parser.cpp')
-rw-r--r--core/variant_parser.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index f036e00ed5..059dc161c7 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -81,6 +81,7 @@ const char *VariantParser::tk_name[TK_MAX] = {
"')'",
"identifier",
"string",
+ "string_name",
"number",
"color",
"':'",
@@ -93,6 +94,8 @@ const char *VariantParser::tk_name[TK_MAX] = {
Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, String &r_err_str) {
+ bool string_name = false;
+
while (true) {
CharType cchar;
@@ -204,6 +207,17 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
r_token.type = TK_COLOR;
return OK;
};
+ case '@': {
+ cchar = p_stream->get_char();
+ if (cchar != '"') {
+ r_err_str = "Expected '\"' after '@'";
+ r_token.type = TK_ERROR;
+ return ERR_PARSE_ERROR;
+ }
+
+ string_name = true;
+ FALLTHROUGH;
+ }
case '"': {
String str;
@@ -285,8 +299,14 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
if (p_stream->is_utf8()) {
str.parse_utf8(str.ascii(true).get_data());
}
- r_token.type = TK_STRING;
- r_token.value = str;
+ if (string_name) {
+ r_token.type = TK_STRING_NAME;
+ r_token.value = StringName(str);
+ string_name = false; //reset
+ } else {
+ r_token.type = TK_STRING;
+ r_token.value = str;
+ }
return OK;
} break;
@@ -1498,6 +1518,14 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, "Color( " + rtosfix(c.r) + ", " + rtosfix(c.g) + ", " + rtosfix(c.b) + ", " + rtosfix(c.a) + " )");
} break;
+ case Variant::STRING_NAME: {
+
+ String str = p_variant;
+
+ str = "@\"" + str.c_escape() + "\"";
+ p_store_string_func(p_store_string_ud, str);
+
+ } break;
case Variant::NODE_PATH: {
String str = p_variant;