29 #define _unused(x) ((void)(x)) 31 #include "SUAPI-CppWrapper/String.hpp" 41 m_string(create_string_ref()),
42 m_encoding(StringEncoding::UTF8)
46 String::String(SUStringRef string_ref):
48 m_encoding(StringEncoding::UTF8)
52 String::String(
const std::string &string_input, StringEncoding enc):
53 m_string(create_string_ref(string_input, enc)),
58 String::String(
const char string_input[]):
59 m_string(create_string_ref(&string_input[0])),
60 m_encoding(StringEncoding::UTF8)
64 String::String(
const unichar string_input[]):
65 m_string(create_string_ref(&string_input[0])),
66 m_encoding(StringEncoding::UTF16)
71 m_string(create_string_ref(other.std_string(), StringEncoding::UTF8))
79 if (SUIsValid(m_string)) {
80 SUResult res = SUStringRelease(&m_string);
81 assert(res == SU_ERROR_NONE); _unused(res);
83 m_string = SU_INVALID;
84 m_string = create_string_ref(other.std_string(), StringEncoding::UTF8);
92 if (lhs.m_encoding != rhs.m_encoding) {
96 if (lhs.std_string() == rhs.std_string()) {
103 SUStringRef String::create_string_ref() {
104 SUStringRef string_ref = SU_INVALID;
105 SUResult res = SUStringCreate(&string_ref);
106 assert(res == SU_ERROR_NONE); _unused(res);
111 SUStringRef String::create_string_ref(std::string string_input, StringEncoding enc) {
112 SUStringRef string_ref = SU_INVALID;
113 if (enc == StringEncoding::UTF8) {
116 SUStringCreateFromUTF8(&string_ref, &string_input[0]);
126 SUStringRef String::create_string_ref(
const char string_input[]) {
127 SUStringRef string_ref = SU_INVALID;
128 SUStringCreateFromUTF8(&string_ref, &string_input[0]);
133 SUStringRef String::create_string_ref(
const unichar string_input[]) {
134 SUStringRef string_ref = SU_INVALID;
142 if (SUIsValid(m_string)) {
143 SUResult res = SUStringRelease(&m_string);
144 assert(res == SU_ERROR_NONE); _unused(res);
149 SUStringRef String::ref()
const {
154 std::string String::std_string()
const {
155 size_t out_length = 0;
156 SUResult res = SUStringGetUTF8Length(m_string, &out_length);
157 assert(res == SU_ERROR_NONE);
159 std::vector<char> char_array(out_length, 0);
160 res = SUStringGetUTF8(m_string, out_length, char_array.data(), &out_length);
161 assert(res == SU_ERROR_NONE); _unused(res);
162 std::string str(char_array.data());
167 String::operator std::string()
const {
172 size_t String::size()
const {
173 size_t out_length = 0;
174 SUResult res = SUStringGetUTF8Length(m_string, &out_length);
175 assert(res == SU_ERROR_NONE); _unused(res);
String & operator=(String &other)
friend bool operator==(const String &lhs, const String &rhs)