diff options
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 3f017fa985..c1888c87a7 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -58,6 +58,9 @@ #define IS_DIGIT(m_d) ((m_d) >= '0' && (m_d) <= '9') #define IS_HEX_DIGIT(m_d) (((m_d) >= '0' && (m_d) <= '9') || ((m_d) >= 'a' && (m_d) <= 'f') || ((m_d) >= 'A' && (m_d) <= 'F')) +const char CharString::_null = 0; +const CharType String::_null = 0; + bool is_symbol(CharType c) { return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' '); } @@ -179,7 +182,7 @@ void String::copy_from_unchecked(const CharType *p_char, const int p_length) { resize(p_length + 1); set(p_length, 0); - CharType *dst = &operator[](0); + CharType *dst = ptrw(); for (int i = 0; i < p_length; i++) { dst[i] = p_char[i]; @@ -250,7 +253,7 @@ String &String::operator+=(const String &p_str) { resize(length() + p_str.size()); const CharType *src = p_str.c_str(); - CharType *dst = &operator[](0); + CharType *dst = ptrw(); set(length(), 0); @@ -289,7 +292,7 @@ String &String::operator+=(const char *p_str) { resize(from + src_len + 1); - CharType *dst = &operator[](0); + CharType *dst = ptrw(); set(length(), 0); @@ -1431,7 +1434,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) { } resize(str_size + 1); - CharType *dst = &operator[](0); + CharType *dst = ptrw(); dst[str_size] = 0; while (cstr_size) { @@ -2390,6 +2393,10 @@ int String::find(const char *p_str, int p_from) const { return -1; } +int String::find_char(CharType p_char, int p_from) const { + return _cowdata.find(p_char, p_from); +} + int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { if (p_from < 0) @@ -3060,7 +3067,7 @@ String String::lstrip(const String &p_chars) const { for (beg = 0; beg < len; beg++) { - if (p_chars.find(&ptr()[beg]) == -1) + if (p_chars.find_char(get(beg)) == -1) break; } @@ -3077,7 +3084,7 @@ String String::rstrip(const String &p_chars) const { for (end = len - 1; end >= 0; end--) { - if (p_chars.find(&ptr()[end]) == -1) + if (p_chars.find_char(get(end)) == -1) break; } @@ -3476,7 +3483,7 @@ String String::xml_unescape() const { if (len == 0) return String(); str.resize(len + 1); - _xml_unescape(c_str(), l, &str[0]); + _xml_unescape(c_str(), l, str.ptrw()); str[len] = 0; return str; } @@ -3578,9 +3585,12 @@ bool String::is_valid_integer() const { bool String::is_valid_hex_number(bool p_with_prefix) const { - int from = 0; int len = length(); + if (len == 0) + return false; + + int from = 0; if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) from++; |