summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp/core/String.cpp
blob: af83f2e65a50a826a6a4ef90094f1faa289bb391 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "String.hpp"

namespace godot {


#include <godot/godot_string.h>

#include <string.h>


godot::String::String()
{
	godot_string_new(&_godot_string);
}

String::String(const char *contents)
{
	godot_string_new_data(&_godot_string, contents, strlen(contents));
}

String::String(const wchar_t *contents)
{
	// @Todo
	// godot_string_new_data(&_godot_string, contents, strlen(contents));
	godot_string_new(&_godot_string);
}

String::String(const wchar_t c)
{
	// @Todo
	godot_string_new(&_godot_string);
}

String::String(const String& other)
{
	godot_string_new(&_godot_string);
	godot_string_copy_string(&_godot_string, &other._godot_string);
}

String::~String()
{
	godot_string_destroy(&_godot_string);
}


String String::substr(int p_from,int p_chars) const
{
	return String(); // @Todo
}


wchar_t &String::operator [](const int idx)
{
	return *godot_string_operator_index(&_godot_string, idx);
}

wchar_t String::operator [](const int idx) const
{
	return *godot_string_operator_index((godot_string *) &_godot_string, idx);
}

int String::length() const
{
	int len = 0;
	godot_string_get_data(&_godot_string, nullptr, &len);
	return len;
}

void String::operator =(const String &s)
{
	godot_string_copy_string(&_godot_string, &s._godot_string);
}

bool String::operator ==(const String &s)
{
	return godot_string_operator_equal(&_godot_string, &s._godot_string);
}

bool String::operator !=(const String &s)
{
	return !(*this == s);
}

String String::operator +(const String &s)
{
	String new_string;
	godot_string_operator_plus(&new_string._godot_string, &_godot_string, &s._godot_string);

	return new_string;
}

void String::operator +=(const String &s)
{
	godot_string_operator_plus(&_godot_string, &_godot_string, &s._godot_string);
}

void String::operator +=(const wchar_t c)
{
	// @Todo
}

bool String::operator <(const String &s)
{
	return godot_string_operator_less(&_godot_string, &s._godot_string);
}

bool String::operator <=(const String &s)
{
	return godot_string_operator_less(&_godot_string, &s._godot_string) || (*this == s);
}

bool String::operator >(const String &s)
{
	return !(*this <= s);
}

bool String::operator >=(const String &s)
{
	return !(*this < s);
}

const wchar_t *String::c_string() const
{
	return godot_string_c_str(&_godot_string);
}


String operator +(const char *a, const String& b)
{
	return String(a) + b;
}



}