mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-10 00:52:11 +01:00
Added a few wchar_t based helper methods to string.
This commit is contained in:
parent
f5d525948b
commit
db531000c1
@ -15,6 +15,13 @@ void String::push_back(const char element) {
|
||||
_data[_size] = '\0';
|
||||
}
|
||||
|
||||
void String::push_back(const wchar_t element) {
|
||||
ensure_capacity(_size + 1);
|
||||
|
||||
_data[_size++] = element;
|
||||
_data[_size] = '\0';
|
||||
}
|
||||
|
||||
void String::pop_back() {
|
||||
if (_size == 0) {
|
||||
return;
|
||||
@ -884,6 +891,18 @@ void String::append_str(const char *str) {
|
||||
}
|
||||
}
|
||||
|
||||
void String::append_str(const wchar_t *str) {
|
||||
if (str == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (str[i] != '\0') {
|
||||
push_back(str[i++]);
|
||||
}
|
||||
}
|
||||
|
||||
void String::append_str(const String &other) {
|
||||
ensure_capacity(_size + other._size + 1); // +1 for the null terminator
|
||||
|
||||
@ -2066,6 +2085,14 @@ String &String::operator=(const char *other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
String &String::operator=(const wchar_t *other) {
|
||||
clear();
|
||||
|
||||
append_str(other);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
String::String() {
|
||||
_data = nullptr;
|
||||
_actual_size = 0;
|
||||
@ -2129,6 +2156,15 @@ String::String(const char *p_c_str, const int grow_by) {
|
||||
append_str(p_c_str);
|
||||
}
|
||||
|
||||
String::String(const wchar_t *p_c_str) {
|
||||
_data = nullptr;
|
||||
_actual_size = 0;
|
||||
_size = 0;
|
||||
_grow_by = 100;
|
||||
|
||||
append_str(p_c_str);
|
||||
}
|
||||
|
||||
String::String(int prealloc) {
|
||||
_data = nullptr;
|
||||
_actual_size = 0;
|
||||
|
@ -10,6 +10,7 @@
|
||||
class String {
|
||||
public:
|
||||
void push_back(const char element);
|
||||
void push_back(const wchar_t element);
|
||||
void pop_back();
|
||||
void remove(const int index);
|
||||
void erase(const char element);
|
||||
@ -91,6 +92,7 @@ public:
|
||||
void append_double_bytes(const double val);
|
||||
|
||||
void append_str(const char* str);
|
||||
void append_str(const wchar_t* str);
|
||||
void append_str(const String &other);
|
||||
void append_str(const std::string &str);
|
||||
|
||||
@ -197,12 +199,14 @@ public:
|
||||
String& operator=(const String &other);
|
||||
String& operator=(const std::string &other);
|
||||
String& operator=(const char* other);
|
||||
String& operator=(const wchar_t* other);
|
||||
|
||||
String();
|
||||
String(const String &other);
|
||||
String(const String &other, const int grow_by);
|
||||
String(const char* p_c_str);
|
||||
String(const char* p_c_str, const int grow_by);
|
||||
String(const wchar_t* p_c_str);
|
||||
String(const int prealloc);
|
||||
String(const int prealloc, const int grow_by);
|
||||
String(const std::string &str);
|
||||
|
Loading…
Reference in New Issue
Block a user