Merge pull request #930 from rune-scape/rune-missing-string-ops

Add missing String operators
pull/935/head
Rémi Verschelde 2022-11-22 10:25:02 +01:00 committed by GitHub
commit 4a4e2b0239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 16 deletions

View File

@ -570,22 +570,26 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
# Special cases.
if class_name == "String":
result.append("String &operator=(const char *p_str);")
result.append("String &operator=(const wchar_t *p_str);")
result.append("String &operator=(const char16_t *p_str);")
result.append("String &operator=(const char32_t *p_str);")
result.append("bool operator==(const char *p_str) const;")
result.append("bool operator==(const wchar_t *p_str) const;")
result.append("bool operator==(const char16_t *p_str) const;")
result.append("bool operator==(const char32_t *p_str) const;")
result.append("bool operator!=(const char *p_str) const;")
result.append("bool operator!=(const wchar_t *p_str) const;")
result.append("bool operator!=(const char16_t *p_str) const;")
result.append("bool operator!=(const char32_t *p_str) const;")
result.append(f"\tconst char32_t &operator[](int p_index) const;")
result.append(f"\tchar32_t &operator[](int p_index);")
result.append(f"\tconst char32_t *ptr() const;")
result.append(f"\tchar32_t *ptrw();")
result.append("\tString &operator=(const char *p_str);")
result.append("\tString &operator=(const wchar_t *p_str);")
result.append("\tString &operator=(const char16_t *p_str);")
result.append("\tString &operator=(const char32_t *p_str);")
result.append("\tbool operator==(const char *p_str) const;")
result.append("\tbool operator==(const wchar_t *p_str) const;")
result.append("\tbool operator==(const char16_t *p_str) const;")
result.append("\tbool operator==(const char32_t *p_str) const;")
result.append("\tbool operator!=(const char *p_str) const;")
result.append("\tbool operator!=(const wchar_t *p_str) const;")
result.append("\tbool operator!=(const char16_t *p_str) const;")
result.append("\tbool operator!=(const char32_t *p_str) const;")
result.append("\tString operator+(const char *p_chr);")
result.append("\tString operator+(const wchar_t *p_chr);")
result.append("\tString operator+(const char16_t *p_chr);")
result.append("\tString operator+(const char32_t *p_chr);")
result.append("\tconst char32_t &operator[](int p_index) const;")
result.append("\tchar32_t &operator[](int p_index);")
result.append("\tconst char32_t *ptr() const;")
result.append("\tchar32_t *ptrw();")
if class_name == "Array":
result.append("\ttemplate <class... Args>")

View File

@ -327,6 +327,22 @@ bool String::operator!=(const char32_t *p_str) const {
return *this != String(p_str);
}
String String::operator+(const char *p_chr) {
return *this + String(p_chr);
}
String String::operator+(const wchar_t *p_chr) {
return *this + String(p_chr);
}
String String::operator+(const char16_t *p_chr) {
return *this + String(p_chr);
}
String String::operator+(const char32_t *p_chr) {
return *this + String(p_chr);
}
const char32_t &String::operator[](int p_index) const {
return *internal::gdn_interface->string_operator_index_const((GDNativeStringPtr)this, p_index);
}