Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing String operators #930

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>")
Expand Down
16 changes: 16 additions & 0 deletions src/variant/char_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down