1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-21 14:57:09 +00:00

String[size()] should return a default constructed CharType

As per the C++ standard 21.3.4.1 for std::string:
Returns: If pos < size(), returns data()[pos]. Otherwise, if pos ==
size(), the const version returns charT(). Otherwise, the behavior is
undefined.

Since the behavior is undefined Godot now does the same thing for const
and non-const versions of operator[].

This fixes #21242 and fixes #22221.
This commit is contained in:
Hein-Pieter van Braam
2019-01-04 16:01:54 +00:00
parent 1504c96112
commit ac99ed3cda
3 changed files with 49 additions and 2 deletions

View File

@@ -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 == ' ');
}