mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-19 22:24:23 +01:00
Backported most of the improvements to String from Godot4.
This commit is contained in:
parent
d08526393e
commit
220954cf08
@ -39,6 +39,7 @@
|
||||
template <class T>
|
||||
class Vector;
|
||||
class String;
|
||||
class Char16String;
|
||||
class CharString;
|
||||
template <class T, class V>
|
||||
class VMap;
|
||||
@ -52,6 +53,7 @@ class CowData {
|
||||
template <class TV>
|
||||
friend class Vector;
|
||||
friend class String;
|
||||
friend class Char16String;
|
||||
friend class CharString;
|
||||
template <class TV, class VV>
|
||||
friend class VMap;
|
||||
|
@ -146,7 +146,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
|
||||
}
|
||||
|
||||
bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset = 0) {
|
||||
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
|
||||
//printf("opening zip pack %s, %i, %i\n", p_name.utf8().get_data(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
|
||||
// load with offset feature only supported for PCK files
|
||||
ERR_FAIL_COND_V_MSG(p_offset != 0, false, "Invalid PCK data. Note that loading files with a non-zero offset isn't supported with ZIP archives.");
|
||||
|
||||
@ -196,7 +196,7 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, uint6
|
||||
|
||||
uint8_t md5[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
PackedData::get_singleton()->add_path(p_path, fname, 1, 0, md5, this, p_replace_files);
|
||||
//printf("packed data add path %ls, %ls\n", p_name.c_str(), fname.c_str());
|
||||
//printf("packed data add path %s, %s\n", p_name.utf8().get_data(), fname.utf8().get_data());
|
||||
|
||||
if ((i + 1) < gi.number_entry) {
|
||||
unzGoToNextFile(zfile);
|
||||
|
@ -183,18 +183,18 @@ VARIANT_ENUM_CAST(Variant::Type);
|
||||
VARIANT_ENUM_CAST(Variant::Operator);
|
||||
|
||||
template <>
|
||||
struct VariantCaster<wchar_t> {
|
||||
static _FORCE_INLINE_ wchar_t cast(const Variant &p_variant) {
|
||||
return (wchar_t)p_variant.operator int();
|
||||
struct VariantCaster<char32_t> {
|
||||
static _FORCE_INLINE_ char32_t cast(const Variant &p_variant) {
|
||||
return (char32_t)p_variant.operator int();
|
||||
}
|
||||
};
|
||||
#ifdef PTRCALL_ENABLED
|
||||
template <>
|
||||
struct PtrToArg<wchar_t> {
|
||||
_FORCE_INLINE_ static wchar_t convert(const void *p_ptr) {
|
||||
return wchar_t(*reinterpret_cast<const int *>(p_ptr));
|
||||
struct PtrToArg<char32_t> {
|
||||
_FORCE_INLINE_ static char32_t convert(const void *p_ptr) {
|
||||
return char32_t(*reinterpret_cast<const int *>(p_ptr));
|
||||
}
|
||||
_FORCE_INLINE_ static void encode(wchar_t p_val, const void *p_ptr) {
|
||||
_FORCE_INLINE_ static void encode(char32_t p_val, const void *p_ptr) {
|
||||
*(int *)p_ptr = p_val;
|
||||
}
|
||||
};
|
||||
|
@ -497,12 +497,12 @@ Error OS::shell_open(String p_uri) {
|
||||
// implement these with the canvas?
|
||||
Error OS::dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object *p_obj, String p_callback) {
|
||||
while (true) {
|
||||
print("%ls\n--------\n%ls\n", p_title.c_str(), p_description.c_str());
|
||||
print("%s\n--------\n%s\n", p_title.utf8().get_data(), p_description.utf8().get_data());
|
||||
for (int i = 0; i < p_buttons.size(); i++) {
|
||||
if (i > 0) {
|
||||
print(", ");
|
||||
}
|
||||
print("%i=%ls", i + 1, p_buttons[i].c_str());
|
||||
print("%i=%s", i + 1, p_buttons[i].utf8().get_data());
|
||||
};
|
||||
print("\n");
|
||||
String res = get_stdin_string().strip_edges();
|
||||
@ -524,7 +524,7 @@ Error OS::dialog_show(String p_title, String p_description, Vector<String> p_but
|
||||
Error OS::dialog_input_text(String p_title, String p_description, String p_partial, Object *p_obj, String p_callback) {
|
||||
ERR_FAIL_COND_V(!p_obj, FAILED);
|
||||
ERR_FAIL_COND_V(p_callback == "", FAILED);
|
||||
print("%ls\n---------\n%ls\n[%ls]:\n", p_title.c_str(), p_description.c_str(), p_partial.c_str());
|
||||
print("%s\n---------\n%s\n[%s]:\n", p_title.utf8().get_data(), p_description.utf8().get_data(), p_partial.utf8().get_data());
|
||||
|
||||
String res = get_stdin_string().strip_edges();
|
||||
bool success = true;
|
||||
|
@ -91,7 +91,7 @@ StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(CharTyp
|
||||
|
||||
template <int SHORT_BUFFER_SIZE>
|
||||
StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const String &p_string) {
|
||||
return append(p_string.c_str());
|
||||
return append(p_string.get_data());
|
||||
}
|
||||
|
||||
template <int SHORT_BUFFER_SIZE>
|
||||
|
@ -131,7 +131,8 @@ MAKE_TYPE_INFO_WITH_META(uint32_t, Variant::INT, PandemoniumTypeInfo::METADATA_I
|
||||
MAKE_TYPE_INFO_WITH_META(int32_t, Variant::INT, PandemoniumTypeInfo::METADATA_INT_IS_INT32)
|
||||
MAKE_TYPE_INFO_WITH_META(uint64_t, Variant::INT, PandemoniumTypeInfo::METADATA_INT_IS_UINT64)
|
||||
MAKE_TYPE_INFO_WITH_META(int64_t, Variant::INT, PandemoniumTypeInfo::METADATA_INT_IS_INT64)
|
||||
MAKE_TYPE_INFO(wchar_t, Variant::INT)
|
||||
MAKE_TYPE_INFO(char16_t, Variant::INT)
|
||||
MAKE_TYPE_INFO(char32_t, Variant::INT)
|
||||
MAKE_TYPE_INFO_WITH_META(float, Variant::REAL, PandemoniumTypeInfo::METADATA_REAL_IS_FLOAT)
|
||||
MAKE_TYPE_INFO_WITH_META(double, Variant::REAL, PandemoniumTypeInfo::METADATA_REAL_IS_DOUBLE)
|
||||
|
||||
|
7532
core/ustring.cpp
7532
core/ustring.cpp
File diff suppressed because it is too large
Load Diff
186
core/ustring.h
186
core/ustring.h
@ -36,8 +36,13 @@
|
||||
#include "core/typedefs.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
/*************************************************************************/
|
||||
/* CharProxy */
|
||||
/*************************************************************************/
|
||||
|
||||
template <class T>
|
||||
class CharProxy {
|
||||
friend class Char16String;
|
||||
friend class CharString;
|
||||
friend class String;
|
||||
|
||||
@ -75,6 +80,51 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
/* Char16String */
|
||||
/*************************************************************************/
|
||||
|
||||
class Char16String {
|
||||
CowData<char16_t> _cowdata;
|
||||
static const char16_t _null;
|
||||
|
||||
public:
|
||||
_FORCE_INLINE_ char16_t *ptrw() { return _cowdata.ptrw(); }
|
||||
_FORCE_INLINE_ const char16_t *ptr() const { return _cowdata.ptr(); }
|
||||
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
|
||||
Error resize(int p_size) { return _cowdata.resize(p_size); }
|
||||
|
||||
_FORCE_INLINE_ char16_t get(int p_index) const { return _cowdata.get(p_index); }
|
||||
_FORCE_INLINE_ void set(int p_index, const char16_t &p_elem) { _cowdata.set(p_index, p_elem); }
|
||||
_FORCE_INLINE_ const char16_t &operator[](int p_index) const {
|
||||
if (unlikely(p_index == _cowdata.size())) {
|
||||
return _null;
|
||||
}
|
||||
|
||||
return _cowdata.get(p_index);
|
||||
}
|
||||
_FORCE_INLINE_ CharProxy<char16_t> operator[](int p_index) { return CharProxy<char16_t>(p_index, _cowdata); }
|
||||
|
||||
_FORCE_INLINE_ Char16String() {}
|
||||
_FORCE_INLINE_ Char16String(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); }
|
||||
|
||||
void operator=(const char16_t *p_cstr);
|
||||
bool operator<(const Char16String &p_right) const;
|
||||
Char16String &operator+=(char16_t p_char);
|
||||
int length() const { return size() ? size() - 1 : 0; }
|
||||
const char16_t *get_data() const;
|
||||
operator const char16_t *() const { return get_data(); };
|
||||
|
||||
protected:
|
||||
void copy_from(const char16_t *p_cstr);
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
/* CharString */
|
||||
/*************************************************************************/
|
||||
|
||||
class CharString {
|
||||
CowData<char> _cowdata;
|
||||
static const char _null;
|
||||
@ -98,13 +148,10 @@ public:
|
||||
|
||||
_FORCE_INLINE_ CharString() {}
|
||||
_FORCE_INLINE_ CharString(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ CharString operator=(const CharString &p_str) {
|
||||
_cowdata._ref(p_str._cowdata);
|
||||
return *this;
|
||||
}
|
||||
_FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); }
|
||||
|
||||
CharString &operator=(const char *p_cstr);
|
||||
void operator=(const char *p_cstr);
|
||||
bool operator<(const CharString &p_right) const;
|
||||
CharString &operator+=(char p_char);
|
||||
int length() const { return size() ? size() - 1 : 0; }
|
||||
@ -115,7 +162,11 @@ protected:
|
||||
void copy_from(const char *p_cstr);
|
||||
};
|
||||
|
||||
typedef wchar_t CharType;
|
||||
/*************************************************************************/
|
||||
/* String */
|
||||
/*************************************************************************/
|
||||
|
||||
typedef char32_t CharType;
|
||||
|
||||
struct StrRange {
|
||||
const CharType *c_str;
|
||||
@ -128,19 +179,8 @@ struct StrRange {
|
||||
};
|
||||
|
||||
class String {
|
||||
CowData<CharType> _cowdata;
|
||||
static const CharType _null;
|
||||
|
||||
void copy_from(const char *p_cstr);
|
||||
void copy_from(const CharType *p_cstr, const int p_clip_to = -1);
|
||||
void copy_from(const CharType &p_char);
|
||||
void copy_from_unchecked(const CharType *p_char, const int p_length);
|
||||
bool _base_is_subsequence_of(const String &p_string, bool case_insensitive) const;
|
||||
int _count(const String &p_string, int p_from, int p_to, bool p_case_insensitive) const;
|
||||
|
||||
public:
|
||||
enum {
|
||||
|
||||
npos = -1 ///<for "some" compatibility with std::string (npos is a huge value in std::string)
|
||||
};
|
||||
|
||||
@ -173,27 +213,39 @@ public:
|
||||
String &operator+=(const String &);
|
||||
String &operator+=(CharType p_char);
|
||||
String &operator+=(const char *p_str);
|
||||
String &operator+=(const wchar_t *p_str);
|
||||
String &operator+=(const CharType *p_str);
|
||||
|
||||
/* Compatibility Operators */
|
||||
|
||||
void operator=(const char *p_str);
|
||||
void operator=(const wchar_t *p_str);
|
||||
void operator=(const CharType *p_str);
|
||||
|
||||
bool operator==(const char *p_str) const;
|
||||
bool operator==(const wchar_t *p_str) const;
|
||||
bool operator==(const CharType *p_str) const;
|
||||
bool operator==(const StrRange &p_str_range) const;
|
||||
|
||||
bool operator!=(const char *p_str) const;
|
||||
bool operator!=(const wchar_t *p_str) const;
|
||||
bool operator!=(const CharType *p_str) const;
|
||||
|
||||
bool operator<(const CharType *p_str) const;
|
||||
bool operator<(const char *p_str) const;
|
||||
bool operator<(const wchar_t *p_str) const;
|
||||
|
||||
bool operator<(const String &p_str) const;
|
||||
bool operator<=(const String &p_str) const;
|
||||
bool operator>(const String &p_str) const;
|
||||
bool operator>=(const String &p_str) const;
|
||||
|
||||
signed char casecmp_to(const String &p_str) const;
|
||||
signed char nocasecmp_to(const String &p_str) const;
|
||||
signed char naturalnocasecmp_to(const String &p_str) const;
|
||||
|
||||
const CharType *c_str() const;
|
||||
const CharType *get_data() const;
|
||||
|
||||
/* standard size stuff */
|
||||
|
||||
_FORCE_INLINE_ int length() const {
|
||||
@ -201,6 +253,11 @@ public:
|
||||
return s ? (s - 1) : 0; // length does not include zero
|
||||
}
|
||||
|
||||
bool is_valid_string() const;
|
||||
|
||||
/* debug, error messages */
|
||||
void print_unicode_error(const String &p_message, bool p_critical = false) const;
|
||||
|
||||
/* complex helpers */
|
||||
String substr(int p_from, int p_chars = -1) const;
|
||||
String substr_index(const int p_start_index, const int p_end_index) const; //end_index is not included
|
||||
@ -256,7 +313,6 @@ public:
|
||||
String sprintf(const Array &values, bool *error) const;
|
||||
|
||||
String quote(String quotechar = "\"") const;
|
||||
|
||||
String unquote() const;
|
||||
|
||||
static String num(double p_num, int p_decimals = -1);
|
||||
@ -264,9 +320,13 @@ public:
|
||||
static String num_real(double p_num);
|
||||
static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
|
||||
static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false);
|
||||
|
||||
static String chr(CharType p_char);
|
||||
|
||||
static String md5(const uint8_t *p_md5);
|
||||
|
||||
static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
|
||||
|
||||
static String bool_num(bool p_val);
|
||||
static String bool_str(bool p_val);
|
||||
|
||||
@ -275,21 +335,31 @@ public:
|
||||
|
||||
double to_double() const;
|
||||
float to_float() const;
|
||||
int hex_to_int(bool p_with_prefix = true) const;
|
||||
int to_int() const;
|
||||
bool to_bool() const;
|
||||
uint32_t to_uint() const;
|
||||
|
||||
int hex_to_int(bool p_with_prefix = true) const;
|
||||
int64_t hex_to_int64(bool p_with_prefix = true) const;
|
||||
int64_t bin_to_int64(bool p_with_prefix = true) const;
|
||||
int64_t to_int64() const;
|
||||
static int to_int(const char *p_str, int p_len = -1);
|
||||
|
||||
static int64_t to_int(const char *p_str, int p_len = -1);
|
||||
static int64_t to_int(const wchar_t *p_str, int p_len = -1);
|
||||
static int64_t to_int(const CharType *p_str, int p_len = -1, bool p_clamp = false);
|
||||
|
||||
static double to_float(const char *p_str);
|
||||
static double to_float(const wchar_t *p_str, const wchar_t **r_end = nullptr);
|
||||
static double to_float(const CharType *p_str, const CharType **r_end = nullptr);
|
||||
|
||||
static double to_double(const char *p_str);
|
||||
static double to_double(const wchar_t *p_str, const wchar_t **r_end = nullptr);
|
||||
static double to_double(const CharType *p_str, const CharType **r_end = nullptr);
|
||||
static int64_t to_int(const CharType *p_str, int p_len = -1);
|
||||
|
||||
String capitalize() const;
|
||||
String camelcase_to_underscore(bool lowercase = true) const;
|
||||
|
||||
String get_with_code_lines() const;
|
||||
int get_slice_count(String p_splitter) const;
|
||||
String get_slice(String p_splitter, int p_slice) const;
|
||||
String get_slicec(CharType p_splitter, int p_slice) const;
|
||||
@ -316,28 +386,40 @@ public:
|
||||
String right(int p_pos) const;
|
||||
String indent(const String &p_prefix) const;
|
||||
String dedent() const;
|
||||
|
||||
String strip_edges(bool left = true, bool right = true) const;
|
||||
String strip_escapes() const;
|
||||
String lstrip(const String &p_chars) const;
|
||||
String rstrip(const String &p_chars) const;
|
||||
|
||||
String get_extension() const;
|
||||
String get_basename() const;
|
||||
String plus_file(const String &p_file) const;
|
||||
|
||||
CharType unicode_at(int p_idx) const;
|
||||
CharType ord_at(int p_idx) const;
|
||||
|
||||
void erase(int p_pos, int p_chars);
|
||||
|
||||
CharString ascii(bool p_allow_extended = false) const;
|
||||
CharString utf8() const;
|
||||
bool parse_utf8(const char *p_utf8, int p_len = -1, bool p_skip_cr = false); //return true on error
|
||||
Error parse_utf8(const char *p_utf8, int p_len = -1, bool p_skip_cr = false); //return true on error
|
||||
static String utf8(const char *p_utf8, int p_len = -1);
|
||||
|
||||
static uint32_t hash(const CharType *p_cstr, int p_len); /* hash the string */
|
||||
static uint32_t hash(const CharType *p_cstr); /* hash the string */
|
||||
static uint32_t hash(const char *p_cstr, int p_len); /* hash the string */
|
||||
Char16String utf16() const;
|
||||
Error parse_utf16(const char16_t *p_utf16, int p_len = -1);
|
||||
static String utf16(const char16_t *p_utf16, int p_len = -1);
|
||||
|
||||
static uint32_t hash(const char *p_cstr); /* hash the string */
|
||||
static uint32_t hash(const char *p_cstr, int p_len); /* hash the string */
|
||||
static uint32_t hash(const wchar_t *p_cstr); /* hash the string */
|
||||
static uint32_t hash(const wchar_t *p_cstr, int p_len); /* hash the string */
|
||||
static uint32_t hash(const CharType *p_cstr); /* hash the string */
|
||||
static uint32_t hash(const CharType *p_cstr, int p_len); /* hash the string */
|
||||
|
||||
uint32_t hash() const; /* hash the string */
|
||||
uint64_t hash64() const; /* hash the string */
|
||||
|
||||
String md5_text() const;
|
||||
String sha1_text() const;
|
||||
String sha256_text() const;
|
||||
@ -387,6 +469,7 @@ public:
|
||||
// node functions
|
||||
static const String invalid_node_name_characters;
|
||||
String validate_node_name() const;
|
||||
String validate_identifier() const; //!
|
||||
|
||||
bool is_valid_identifier() const;
|
||||
bool is_valid_integer() const;
|
||||
@ -405,19 +488,50 @@ public:
|
||||
|
||||
_FORCE_INLINE_ String() {}
|
||||
_FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
String operator=(const String &p_str) {
|
||||
//!!! why void
|
||||
void operator=(const String &p_str) {
|
||||
_cowdata._ref(p_str._cowdata);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector<uint8_t> to_ascii_buffer() const;
|
||||
Vector<uint8_t> to_utf8_buffer() const;
|
||||
Vector<uint8_t> to_utf16_buffer() const;
|
||||
Vector<uint8_t> to_utf32_buffer() const;
|
||||
|
||||
String(const char *p_str);
|
||||
String(const CharType *p_str, int p_clip_to_len = -1);
|
||||
String(const wchar_t *p_str);
|
||||
String(const CharType *p_str);
|
||||
String(const char *p_str, int p_clip_to_len);
|
||||
String(const wchar_t *p_str, int p_clip_to_len);
|
||||
String(const CharType *p_str, int p_clip_to_len);
|
||||
String(const StrRange &p_range);
|
||||
|
||||
private:
|
||||
CowData<CharType> _cowdata;
|
||||
static const CharType _null;
|
||||
|
||||
void copy_from(const char *p_cstr);
|
||||
void copy_from(const char *p_cstr, const int p_clip_to);
|
||||
void copy_from(const wchar_t *p_cstr);
|
||||
void copy_from(const wchar_t *p_cstr, const int p_clip_to);
|
||||
void copy_from(const CharType *p_cstr);
|
||||
void copy_from(const CharType *p_cstr, const int p_clip_to);
|
||||
|
||||
void copy_from(const CharType &p_char);
|
||||
|
||||
void copy_from_unchecked(const CharType *p_char, const int p_length);
|
||||
|
||||
bool _base_is_subsequence_of(const String &p_string, bool case_insensitive) const;
|
||||
int _count(const String &p_string, int p_from, int p_to, bool p_case_insensitive) const;
|
||||
};
|
||||
|
||||
bool operator==(const char *p_chr, const String &p_str);
|
||||
bool operator==(const wchar_t *p_chr, const String &p_str);
|
||||
bool operator!=(const char *p_chr, const String &p_str);
|
||||
bool operator!=(const wchar_t *p_chr, const String &p_str);
|
||||
|
||||
String operator+(const char *p_chr, const String &p_str);
|
||||
String operator+(const wchar_t *p_chr, const String &p_str);
|
||||
String operator+(CharType p_chr, const String &p_str);
|
||||
|
||||
String itos(int64_t p_val);
|
||||
@ -440,15 +554,18 @@ struct NaturalNoCaseComparator {
|
||||
template <typename L, typename R>
|
||||
_FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
|
||||
while (true) {
|
||||
if (*l_ptr == 0 && *r_ptr == 0) {
|
||||
const CharType l = *l_ptr;
|
||||
const CharType r = *r_ptr;
|
||||
|
||||
if (l == 0 && r == 0) {
|
||||
return false;
|
||||
} else if (*l_ptr == 0) {
|
||||
} else if (l == 0) {
|
||||
return true;
|
||||
} else if (*r_ptr == 0) {
|
||||
} else if (r == 0) {
|
||||
return false;
|
||||
} else if (*l_ptr < *r_ptr) {
|
||||
} else if (l < r) {
|
||||
return true;
|
||||
} else if (*l_ptr > *r_ptr) {
|
||||
} else if (l > r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -480,7 +597,6 @@ String DTR(const String &);
|
||||
// Runtime translate for the public node API.
|
||||
String RTR(const String &);
|
||||
|
||||
bool is_symbol(CharType c);
|
||||
bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end);
|
||||
|
||||
#endif // USTRING_H
|
||||
|
@ -418,6 +418,39 @@ struct _VariantCall {
|
||||
r_ret = retval;
|
||||
}
|
||||
|
||||
static void _call_String_to_utf16(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||
String *s = reinterpret_cast<String *>(p_self._data._mem);
|
||||
if (s->empty()) {
|
||||
r_ret = PoolByteArray();
|
||||
return;
|
||||
}
|
||||
Char16String charstr = s->utf16();
|
||||
|
||||
PoolByteArray retval;
|
||||
size_t len = charstr.length() * 2;
|
||||
retval.resize(len);
|
||||
PoolByteArray::Write w = retval.write();
|
||||
memcpy(w.ptr(), s->ptr(), len);
|
||||
|
||||
r_ret = retval;
|
||||
}
|
||||
|
||||
static void _call_String_to_utf32(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||
String *s = reinterpret_cast<String *>(p_self._data._mem);
|
||||
if (s->empty()) {
|
||||
r_ret = PoolByteArray();
|
||||
return;
|
||||
}
|
||||
|
||||
PoolByteArray retval;
|
||||
size_t len = s->length() * 4;
|
||||
retval.resize(len);
|
||||
PoolByteArray::Write w = retval.write();
|
||||
memcpy(w.ptr(), s->ptr(), len);
|
||||
|
||||
r_ret = retval;
|
||||
}
|
||||
|
||||
VCALL_LOCALMEM1(Vector2, set_all);
|
||||
VCALL_LOCALMEM0R(Vector2, min_axis);
|
||||
VCALL_LOCALMEM0R(Vector2, max_axis);
|
||||
@ -787,6 +820,26 @@ struct _VariantCall {
|
||||
r_ret = s;
|
||||
}
|
||||
|
||||
static void _call_PoolByteArray_get_string_from_utf16(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||
String s;
|
||||
if (ba->size() > 0) {
|
||||
PoolByteArray::Read r = ba->read();
|
||||
s.parse_utf16((const char16_t *)r.ptr(), ba->size()/ 2);
|
||||
}
|
||||
r_ret = s;
|
||||
}
|
||||
|
||||
static void _call_PoolByteArray_get_string_from_utf32(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||
String s;
|
||||
if (ba->size() > 0) {
|
||||
PoolByteArray::Read r = ba->read();
|
||||
s = String((const CharType *)r.ptr(), ba->size() / 4);
|
||||
}
|
||||
r_ret = s;
|
||||
}
|
||||
|
||||
static void _call_PoolByteArray_compress(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||
PoolByteArray compressed;
|
||||
@ -2267,6 +2320,8 @@ void register_variant_methods() {
|
||||
|
||||
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_ascii, varray());
|
||||
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_utf8, varray());
|
||||
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_utf16, varray());
|
||||
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_utf32, varray());
|
||||
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_wchar, varray());
|
||||
|
||||
ADDFUNC1(VECTOR2, NIL, Vector2, set_all, REAL, "value", varray());
|
||||
@ -2599,6 +2654,8 @@ void register_variant_methods() {
|
||||
|
||||
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_ascii, varray());
|
||||
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf8, varray());
|
||||
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf16, varray());
|
||||
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf32, varray());
|
||||
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, hex_encode, varray());
|
||||
ADDFUNC1R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, compress, INT, "compression_mode", varray(0));
|
||||
ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, decompress, INT, "buffer_size", INT, "compression_mode", varray(0));
|
||||
|
@ -98,13 +98,25 @@
|
||||
<method name="get_string_from_ascii">
|
||||
<return type="String" />
|
||||
<description>
|
||||
Returns a copy of the array's contents as [String]. Fast alternative to [method get_string_from_utf8] if the content is ASCII-only. Unlike the UTF-8 function this function maps every byte to a character in the array. Multibyte sequences will not be interpreted correctly. For parsing user input always use [method get_string_from_utf8].
|
||||
Converts ASCII/Latin-1 encoded array to [String]. Fast alternative to [method get_string_from_utf8] if the content is ASCII/Latin-1 only. Unlike the UTF-8 function this function maps every byte to a character in the array. Multibyte sequences will not be interpreted correctly. For parsing user input always use [method get_string_from_utf8].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_string_from_utf16">
|
||||
<return type="String">
|
||||
</return>
|
||||
<description>
|
||||
Converts UTF-16 encoded array to [String]. If the BOM is missing, system endianness is assumed. Returns empty string if source array is not vaild UTF-16 string.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_string_from_utf32">
|
||||
<return type="String">
|
||||
</return>
|
||||
<description>
|
||||
Converts UTF-32 encoded array to [String]. System endianness is assumed. Returns empty string if source array is not vaild UTF-32 string.
|
||||
<method name="get_string_from_utf8">
|
||||
<return type="String" />
|
||||
<description>
|
||||
Returns a copy of the array's contents as [String]. Slower than [method get_string_from_ascii] but supports UTF-8 encoded data. Use this function if you are unsure about the source of the data. For user input this function should always be preferred.
|
||||
Converts UTF-8 encoded array to [String]. Slower than [method get_string_from_ascii] but supports UTF-8 encoded data. Use this function if you are unsure about the source of the data. For user input this function should always be preferred. Returns empty string if source array is not vaild UTF-8 string.
|
||||
</description>
|
||||
</method>
|
||||
<method name="has">
|
||||
|
@ -583,6 +583,17 @@
|
||||
Returns the string's amount of characters.
|
||||
</description>
|
||||
</method>
|
||||
<method name="lpad">
|
||||
<return type="String">
|
||||
</return>
|
||||
<argument index="0" name="min_length" type="int">
|
||||
</argument>
|
||||
<argument index="1" name="character" type="String" default="" "">
|
||||
</argument>
|
||||
<description>
|
||||
Formats a string to be at least [code]min_length[/code] long by adding [code]character[/code]s to the left of the string.
|
||||
</description>
|
||||
</method>
|
||||
<method name="lstrip">
|
||||
<return type="String" />
|
||||
<argument index="0" name="chars" type="String" />
|
||||
@ -724,6 +735,17 @@
|
||||
Returns the right side of the string from a given position.
|
||||
</description>
|
||||
</method>
|
||||
<method name="rpad">
|
||||
<return type="String">
|
||||
</return>
|
||||
<argument index="0" name="min_length" type="int">
|
||||
</argument>
|
||||
<argument index="1" name="character" type="String" default="" "">
|
||||
</argument>
|
||||
<description>
|
||||
Formats a string to be at least [code]min_length[/code] long by adding [code]character[/code]s to the right of the string.
|
||||
</description>
|
||||
</method>
|
||||
<method name="rsplit">
|
||||
<return type="PoolStringArray" />
|
||||
<argument index="0" name="delimiter" type="String" />
|
||||
@ -848,7 +870,7 @@
|
||||
<method name="to_ascii">
|
||||
<return type="PoolByteArray" />
|
||||
<description>
|
||||
Converts the String (which is a character array) to [PoolByteArray] (which is an array of bytes). The conversion is faster compared to [method to_utf8], as this method assumes that all the characters in the String are ASCII characters.
|
||||
Converts the String (which is a character array) to ASCII/Latin-1 encoded [PoolByteArray] (which is an array of bytes). The conversion is faster compared to [method to_utf8], as this method assumes that all the characters in the String are ASCII/Latin-1 characters, unsupported characters are replaced with spaces.
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_float">
|
||||
@ -886,10 +908,24 @@
|
||||
Returns the string converted to uppercase.
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_utf16">
|
||||
<return type="PoolByteArray">
|
||||
</return>
|
||||
<description>
|
||||
Converts the String (which is an array of characters) to UTF-16 encoded [PoolByteArray] (which is an array of bytes).
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_utf32">
|
||||
<return type="PoolByteArray">
|
||||
</return>
|
||||
<description>
|
||||
Converts the String (which is an array of characters) to UTF-32 encoded [PoolByteArray] (which is an array of bytes).
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_utf8">
|
||||
<return type="PoolByteArray" />
|
||||
<description>
|
||||
Converts the String (which is an array of characters) to [PoolByteArray] (which is an array of bytes). The conversion is a bit slower than [method to_ascii], but supports all UTF-8 characters. Therefore, you should prefer this function over [method to_ascii].
|
||||
Converts the String (which is an array of characters) to UTF-8 encode [PoolByteArray] (which is an array of bytes). The conversion is a bit slower than [method to_ascii], but supports all UTF-8 characters. Therefore, you should prefer this function over [method to_ascii].
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_wchar">
|
||||
|
@ -78,7 +78,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
|
||||
|
||||
path_src = p_path;
|
||||
path = fix_path(p_path);
|
||||
//printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage());
|
||||
//printf("opening %s, %i\n", path.utf8().get_data(), Memory::get_static_mem_usage());
|
||||
|
||||
ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use.");
|
||||
const char *mode_string;
|
||||
|
@ -66,19 +66,20 @@ Error DirAccessWindows::list_dir_begin() {
|
||||
_cishidden = false;
|
||||
|
||||
list_dir_end();
|
||||
p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
|
||||
p->h = FindFirstFileExW((LPCWSTR)(String(current_dir + "\\*").utf16().get_data()), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
|
||||
|
||||
return (p->h == INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
|
||||
}
|
||||
|
||||
String DirAccessWindows::get_next() {
|
||||
if (p->h == INVALID_HANDLE_VALUE)
|
||||
if (p->h == INVALID_HANDLE_VALUE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
_cisdir = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
_cishidden = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
|
||||
|
||||
String name = p->fu.cFileName;
|
||||
String name = String::utf16((const char16_t *)(p->fu.cFileName));
|
||||
|
||||
if (FindNextFileW(p->h, &p->fu) == 0) {
|
||||
FindClose(p->h);
|
||||
@ -106,8 +107,9 @@ int DirAccessWindows::get_drive_count() {
|
||||
return drive_count;
|
||||
}
|
||||
String DirAccessWindows::get_drive(int p_drive) {
|
||||
if (p_drive < 0 || p_drive >= drive_count)
|
||||
if (p_drive < 0 || p_drive >= drive_count) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return String::chr(drives[p_drive]) + ":";
|
||||
}
|
||||
@ -117,18 +119,17 @@ Error DirAccessWindows::change_dir(String p_dir) {
|
||||
|
||||
p_dir = fix_path(p_dir);
|
||||
|
||||
wchar_t real_current_dir_name[2048];
|
||||
WCHAR real_current_dir_name[2048];
|
||||
GetCurrentDirectoryW(2048, real_current_dir_name);
|
||||
String prev_dir = real_current_dir_name;
|
||||
String prev_dir = String::utf16((const char16_t *)real_current_dir_name);
|
||||
|
||||
SetCurrentDirectoryW(current_dir.c_str());
|
||||
bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);
|
||||
SetCurrentDirectoryW((LPCWSTR)(current_dir.utf16().get_data()));
|
||||
bool worked = (SetCurrentDirectoryW((LPCWSTR)(p_dir.utf16().get_data())) != 0);
|
||||
|
||||
String base = _get_root_path();
|
||||
if (base != "") {
|
||||
GetCurrentDirectoryW(2048, real_current_dir_name);
|
||||
String new_dir;
|
||||
new_dir = String(real_current_dir_name).replace("\\", "/");
|
||||
String new_dir = String::utf16((const char16_t *)real_current_dir_name).replace("\\", "/");
|
||||
if (!new_dir.begins_with(base)) {
|
||||
worked = false;
|
||||
}
|
||||
@ -136,13 +137,11 @@ Error DirAccessWindows::change_dir(String p_dir) {
|
||||
|
||||
if (worked) {
|
||||
GetCurrentDirectoryW(2048, real_current_dir_name);
|
||||
current_dir = real_current_dir_name; // TODO, utf8 parser
|
||||
current_dir = String::utf16((const char16_t *)real_current_dir_name);
|
||||
current_dir = current_dir.replace("\\", "/");
|
||||
}
|
||||
|
||||
} //else {
|
||||
|
||||
SetCurrentDirectoryW(prev_dir.c_str());
|
||||
//}
|
||||
SetCurrentDirectoryW((LPCWSTR)(prev_dir.utf16().get_data()));
|
||||
|
||||
return worked ? OK : ERR_INVALID_PARAMETER;
|
||||
}
|
||||
@ -151,8 +150,10 @@ Error DirAccessWindows::make_dir(String p_dir) {
|
||||
GLOBAL_LOCK_FUNCTION
|
||||
|
||||
p_dir = fix_path(p_dir);
|
||||
if (p_dir.is_rel_path())
|
||||
|
||||
if (p_dir.is_rel_path()) {
|
||||
p_dir = current_dir.plus_file(p_dir);
|
||||
}
|
||||
|
||||
p_dir = p_dir.replace("/", "\\");
|
||||
|
||||
@ -165,16 +166,16 @@ Error DirAccessWindows::make_dir(String p_dir) {
|
||||
// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
|
||||
}
|
||||
|
||||
success = CreateDirectoryW(p_dir.c_str(), NULL);
|
||||
success = CreateDirectoryW((LPCWSTR)(p_dir.utf16().get_data()), NULL);
|
||||
err = GetLastError();
|
||||
|
||||
if (success) {
|
||||
return OK;
|
||||
};
|
||||
}
|
||||
|
||||
if (err == ERROR_ALREADY_EXISTS || err == ERROR_ACCESS_DENIED) {
|
||||
return ERR_ALREADY_EXISTS;
|
||||
};
|
||||
}
|
||||
|
||||
return ERR_CANT_CREATE;
|
||||
}
|
||||
@ -183,12 +184,11 @@ String DirAccessWindows::get_current_dir() {
|
||||
String base = _get_root_path();
|
||||
if (base != "") {
|
||||
String bd = current_dir.replace("\\", "/").replace_first(base, "");
|
||||
if (bd.begins_with("/"))
|
||||
if (bd.begins_with("/")) {
|
||||
return _get_root_string() + bd.substr(1, bd.length());
|
||||
else
|
||||
} else {
|
||||
return _get_root_string() + bd;
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
return current_dir;
|
||||
@ -210,20 +210,18 @@ String DirAccessWindows::get_current_dir_without_drive() {
|
||||
bool DirAccessWindows::file_exists(String p_file) {
|
||||
GLOBAL_LOCK_FUNCTION
|
||||
|
||||
if (!p_file.is_abs_path())
|
||||
if (!p_file.is_abs_path()) {
|
||||
p_file = get_current_dir().plus_file(p_file);
|
||||
}
|
||||
|
||||
p_file = fix_path(p_file);
|
||||
|
||||
//p_file.replace("/","\\");
|
||||
|
||||
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
|
||||
|
||||
DWORD fileAttr;
|
||||
|
||||
fileAttr = GetFileAttributesW(p_file.c_str());
|
||||
if (INVALID_FILE_ATTRIBUTES == fileAttr)
|
||||
fileAttr = GetFileAttributesW((LPCWSTR)(p_file.utf16().get_data()));
|
||||
if (INVALID_FILE_ATTRIBUTES == fileAttr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(fileAttr & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
@ -236,26 +234,26 @@ bool DirAccessWindows::dir_exists(String p_dir) {
|
||||
|
||||
p_dir = fix_path(p_dir);
|
||||
|
||||
//p_dir.replace("/","\\");
|
||||
|
||||
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
|
||||
|
||||
DWORD fileAttr;
|
||||
|
||||
fileAttr = GetFileAttributesW(p_dir.c_str());
|
||||
if (INVALID_FILE_ATTRIBUTES == fileAttr)
|
||||
fileAttr = GetFileAttributesW((LPCWSTR)(p_dir.utf16().get_data()));
|
||||
if (INVALID_FILE_ATTRIBUTES == fileAttr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (fileAttr & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
Error DirAccessWindows::rename(String p_path, String p_new_path) {
|
||||
if (p_path.is_rel_path())
|
||||
if (p_path.is_rel_path()) {
|
||||
p_path = get_current_dir().plus_file(p_path);
|
||||
}
|
||||
|
||||
p_path = fix_path(p_path);
|
||||
|
||||
if (p_new_path.is_rel_path())
|
||||
if (p_new_path.is_rel_path()) {
|
||||
p_new_path = get_current_dir().plus_file(p_new_path);
|
||||
}
|
||||
|
||||
p_new_path = fix_path(p_new_path);
|
||||
|
||||
@ -263,21 +261,22 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) {
|
||||
if (p_path.to_lower() == p_new_path.to_lower()) {
|
||||
if (dir_exists(p_path)) {
|
||||
// The path is a dir; just rename
|
||||
return ::_wrename(p_path.c_str(), p_new_path.c_str()) == 0 ? OK : FAILED;
|
||||
return ::_wrename((LPCWSTR)(p_path.utf16().get_data()), (LPCWSTR)(p_new_path.utf16().get_data())) == 0 ? OK : FAILED;
|
||||
}
|
||||
|
||||
// The path is a file; juggle
|
||||
WCHAR tmpfile[MAX_PATH];
|
||||
|
||||
if (!GetTempFileNameW(fix_path(get_current_dir()).c_str(), NULL, 0, tmpfile)) {
|
||||
if (!GetTempFileNameW((LPCWSTR)(fix_path(get_current_dir()).utf16().get_data()), NULL, 0, tmpfile)) {
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
if (!::ReplaceFileW(tmpfile, p_path.c_str(), NULL, 0, NULL, NULL)) {
|
||||
if (!::ReplaceFileW(tmpfile, (LPCWSTR)(p_path.utf16().get_data()), NULL, 0, NULL, NULL)) {
|
||||
DeleteFileW(tmpfile);
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
return ::_wrename(tmpfile, p_new_path.c_str()) == 0 ? OK : FAILED;
|
||||
return ::_wrename(tmpfile, (LPCWSTR)(p_new_path.utf16().get_data())) == 0 ? OK : FAILED;
|
||||
|
||||
} else {
|
||||
if (file_exists(p_new_path)) {
|
||||
@ -286,59 +285,61 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) {
|
||||
}
|
||||
}
|
||||
|
||||
return ::_wrename(p_path.c_str(), p_new_path.c_str()) == 0 ? OK : FAILED;
|
||||
return ::_wrename((LPCWSTR)(p_path.utf16().get_data()), (LPCWSTR)(p_new_path.utf16().get_data())) == 0 ? OK : FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
Error DirAccessWindows::remove(String p_path) {
|
||||
if (p_path.is_rel_path())
|
||||
if (p_path.is_rel_path()) {
|
||||
p_path = get_current_dir().plus_file(p_path);
|
||||
}
|
||||
|
||||
p_path = fix_path(p_path);
|
||||
|
||||
DWORD fileAttr;
|
||||
|
||||
fileAttr = GetFileAttributesW(p_path.c_str());
|
||||
if (INVALID_FILE_ATTRIBUTES == fileAttr)
|
||||
fileAttr = GetFileAttributesW((LPCWSTR)(p_path.utf16().get_data()));
|
||||
if (INVALID_FILE_ATTRIBUTES == fileAttr) {
|
||||
return FAILED;
|
||||
if ((fileAttr & FILE_ATTRIBUTE_DIRECTORY))
|
||||
return ::_wrmdir(p_path.c_str()) == 0 ? OK : FAILED;
|
||||
else
|
||||
return ::_wunlink(p_path.c_str()) == 0 ? OK : FAILED;
|
||||
}
|
||||
|
||||
if ((fileAttr & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
return ::_wrmdir((LPCWSTR)(p_path.utf16().get_data())) == 0 ? OK : FAILED;
|
||||
} else {
|
||||
return ::_wunlink((LPCWSTR)(p_path.utf16().get_data())) == 0 ? OK : FAILED;
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
FileType DirAccessWindows::get_file_type(const String& p_file) const {
|
||||
WCHAR real_current_dir_name[2048];
|
||||
GetCurrentDirectoryW(2048, real_current_dir_name);
|
||||
String prev_dir = Strong::utf16((const char16_t *)real_current_dir_name);
|
||||
|
||||
|
||||
wchar_t real_current_dir_name[2048];
|
||||
GetCurrentDirectoryW(2048,real_current_dir_name);
|
||||
String prev_dir=real_current_dir_name;
|
||||
|
||||
bool worked SetCurrentDirectoryW(current_dir.c_str());
|
||||
bool worked = SetCurrentDirectoryW((LPCWSTR)(current_dir.utf16().get_data()));
|
||||
|
||||
DWORD attr;
|
||||
if (worked) {
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fileInfo;
|
||||
attr = GetFileAttributesExW(p_file.c_str(), GetFileExInfoStandard, &fileInfo);
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fileInfo;
|
||||
attr = GetFileAttributesExW((LPCWSTR)(p_file.utf16().get_data()), GetFileExInfoStandard, &fileInfo);
|
||||
}
|
||||
|
||||
SetCurrentDirectoryW(prev_dir.c_str());
|
||||
SetCurrentDirectoryW((LPCWSTR)(prev_dir.utf16().get_data()));
|
||||
|
||||
if (!worked)
|
||||
if (!worked) {
|
||||
return FILE_TYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_
|
||||
return (attr & FILE_ATTRIBUTE_DIRECTORY) ? FILE_TYPE_
|
||||
}
|
||||
*/
|
||||
|
||||
uint64_t DirAccessWindows::get_space_left() {
|
||||
uint64_t bytes = 0;
|
||||
if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL))
|
||||
|
||||
if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//this is either 0 or a value in bytes.
|
||||
return bytes;
|
||||
@ -347,7 +348,7 @@ uint64_t DirAccessWindows::get_space_left() {
|
||||
String DirAccessWindows::get_filesystem_type() const {
|
||||
String path = fix_path(const_cast<DirAccessWindows *>(this)->get_current_dir());
|
||||
|
||||
if (path.is_network_share_path()) {
|
||||
if (path.is_network_share_path()) {
|
||||
return "Network Share";
|
||||
}
|
||||
|
||||
@ -361,7 +362,7 @@ String DirAccessWindows::get_filesystem_type() const {
|
||||
DWORD dwMaxFileNameLength = 0;
|
||||
DWORD dwFileSystemFlags = 0;
|
||||
|
||||
if (::GetVolumeInformationW(unit.c_str(),
|
||||
if (::GetVolumeInformationW((LPCWSTR)(unit.utf16().get_data()),
|
||||
szVolumeName,
|
||||
sizeof(szVolumeName),
|
||||
&dwSerialNumber,
|
||||
@ -369,7 +370,7 @@ String DirAccessWindows::get_filesystem_type() const {
|
||||
&dwFileSystemFlags,
|
||||
szFileSystemName,
|
||||
sizeof(szFileSystemName)) == TRUE) {
|
||||
return String(szFileSystemName);
|
||||
return String::utf16((const char16_t *)szFileSystemName);
|
||||
}
|
||||
|
||||
ERR_FAIL_V("");
|
||||
|
@ -61,29 +61,33 @@ void FileAccessWindows::check_errors() const {
|
||||
Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
|
||||
path_src = p_path;
|
||||
path = fix_path(p_path);
|
||||
if (f)
|
||||
|
||||
if (f) {
|
||||
close();
|
||||
}
|
||||
|
||||
const wchar_t *mode_string;
|
||||
const WCHAR *mode_string;
|
||||
|
||||
if (p_mode_flags == READ)
|
||||
if (p_mode_flags == READ) {
|
||||
mode_string = L"rb";
|
||||
else if (p_mode_flags == WRITE)
|
||||
} else if (p_mode_flags == WRITE) {
|
||||
mode_string = L"wb";
|
||||
else if (p_mode_flags == READ_WRITE)
|
||||
} else if (p_mode_flags == READ_WRITE) {
|
||||
mode_string = L"rb+";
|
||||
else if (p_mode_flags == WRITE_READ)
|
||||
} else if (p_mode_flags == WRITE_READ) {
|
||||
mode_string = L"wb+";
|
||||
else
|
||||
} else {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* pretty much every implementation that uses fopen as primary
|
||||
backend supports utf8 encoding */
|
||||
|
||||
struct _stat st;
|
||||
if (_wstat(path.c_str(), &st) == 0) {
|
||||
if (!S_ISREG(st.st_mode))
|
||||
if (_wstat((LPCWSTR)(path.utf16().get_data()), &st) == 0) {
|
||||
if (!S_ISREG(st.st_mode)) {
|
||||
return ERR_FILE_CANT_OPEN;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
@ -93,15 +97,18 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
|
||||
// platforms).
|
||||
if (p_mode_flags == READ) {
|
||||
WIN32_FIND_DATAW d;
|
||||
HANDLE f = FindFirstFileW(path.c_str(), &d);
|
||||
HANDLE f = FindFirstFileW((LPCWSTR)(path.utf16().get_data()), &d);
|
||||
|
||||
if (f != INVALID_HANDLE_VALUE) {
|
||||
String fname = d.cFileName;
|
||||
String fname = String::utf16((const char16_t *)(d.cFileName));
|
||||
|
||||
if (fname != String()) {
|
||||
String base_file = path.get_file();
|
||||
if (base_file != fname && base_file.findn(fname) == 0) {
|
||||
WARN_PRINT("Case mismatch opening requested file '" + base_file + "', stored as '" + fname + "' in the filesystem. This file will not open when exported to other case-sensitive platforms.");
|
||||
}
|
||||
}
|
||||
|
||||
FindClose(f);
|
||||
}
|
||||
}
|
||||
@ -112,7 +119,7 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
|
||||
path = path + ".tmp";
|
||||
}
|
||||
|
||||
f = _wfsopen((LPCWSTR)(path.c_str()), mode_string, _SH_DENYNO);
|
||||
f = _wfsopen((LPCWSTR)(path.utf16().get_data()), mode_string, _SH_DENYNO);
|
||||
|
||||
if (f == nullptr) {
|
||||
switch (errno) {
|
||||
@ -132,8 +139,9 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
|
||||
}
|
||||
|
||||
void FileAccessWindows::close() {
|
||||
if (!f)
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
@ -150,16 +158,16 @@ void FileAccessWindows::close() {
|
||||
// UWP has no PathFileExists, so we check attributes instead
|
||||
DWORD fileAttr;
|
||||
|
||||
fileAttr = GetFileAttributesW(save_path.c_str());
|
||||
fileAttr = GetFileAttributesW((LPCWSTR)(save_path.utf16().get_data()));
|
||||
if (INVALID_FILE_ATTRIBUTES == fileAttr) {
|
||||
#else
|
||||
if (!PathFileExistsW(save_path.c_str())) {
|
||||
if (!PathFileExistsW((LPCWSTR)(save_path.utf16().get_data()))) {
|
||||
#endif
|
||||
//creating new file
|
||||
rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0;
|
||||
rename_error = _wrename((LPCWSTR)((save_path + ".tmp").utf16().get_data()), (LPCWSTR)(save_path.utf16().get_data())) != 0;
|
||||
} else {
|
||||
//atomic replace for existing file
|
||||
rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), NULL, 2 | 4, NULL, NULL);
|
||||
rename_error = !ReplaceFileW((LPCWSTR)(save_path.utf16().get_data()), (LPCWSTR)((save_path + ".tmp").utf16().get_data()), NULL, 2 | 4, NULL, NULL);
|
||||
}
|
||||
if (rename_error) {
|
||||
attempts--;
|
||||
@ -195,23 +203,31 @@ void FileAccessWindows::seek(uint64_t p_position) {
|
||||
ERR_FAIL_COND(!f);
|
||||
|
||||
last_error = OK;
|
||||
if (_fseeki64(f, p_position, SEEK_SET))
|
||||
|
||||
if (_fseeki64(f, p_position, SEEK_SET)) {
|
||||
check_errors();
|
||||
}
|
||||
|
||||
prev_op = 0;
|
||||
}
|
||||
|
||||
void FileAccessWindows::seek_end(int64_t p_position) {
|
||||
ERR_FAIL_COND(!f);
|
||||
if (_fseeki64(f, p_position, SEEK_END))
|
||||
|
||||
if (_fseeki64(f, p_position, SEEK_END)) {
|
||||
check_errors();
|
||||
}
|
||||
|
||||
prev_op = 0;
|
||||
}
|
||||
|
||||
uint64_t FileAccessWindows::get_position() const {
|
||||
int64_t aux_position = _ftelli64(f);
|
||||
|
||||
if (aux_position < 0) {
|
||||
check_errors();
|
||||
}
|
||||
|
||||
return aux_position;
|
||||
}
|
||||
|
||||
@ -270,8 +286,10 @@ Error FileAccessWindows::get_error() const {
|
||||
void FileAccessWindows::flush() {
|
||||
ERR_FAIL_COND(!f);
|
||||
fflush(f);
|
||||
if (prev_op == WRITE)
|
||||
|
||||
if (prev_op == WRITE) {
|
||||
prev_op = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void FileAccessWindows::store_8(uint8_t p_dest) {
|
||||
@ -290,6 +308,7 @@ void FileAccessWindows::store_8(uint8_t p_dest) {
|
||||
void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
ERR_FAIL_COND(!f);
|
||||
ERR_FAIL_COND(!p_src && p_length > 0);
|
||||
|
||||
if (flags == READ_WRITE || flags == WRITE_READ) {
|
||||
if (prev_op == READ) {
|
||||
if (last_error != ERR_FILE_EOF) {
|
||||
@ -303,7 +322,9 @@ void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
|
||||
|
||||
bool FileAccessWindows::file_exists(const String &p_name) {
|
||||
String filename = fix_path(p_name);
|
||||
FILE *g = _wfsopen((LPCWSTR)(filename.c_str()), L"rb", _SH_DENYNO);
|
||||
|
||||
FILE *g = _wfsopen((LPCWSTR)(filename.utf16().get_data()), L"rb", _SH_DENYNO);
|
||||
|
||||
if (g == nullptr) {
|
||||
return false;
|
||||
} else {
|
||||
@ -318,7 +339,7 @@ uint64_t FileAccessWindows::_get_modified_time(const String &p_file) {
|
||||
file = file.substr(0, file.length() - 1);
|
||||
|
||||
struct _stat st;
|
||||
int rv = _wstat(file.c_str(), &st);
|
||||
int rv = _wstat((LPCWSTR)(file.utf16().get_data()), &st);
|
||||
|
||||
if (rv == 0) {
|
||||
return st.st_mtime;
|
||||
|
@ -506,8 +506,8 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S
|
||||
String cur_dir_no_prefix = cur_dir.replace("res://", "");
|
||||
|
||||
Vector<String> dirs;
|
||||
String f;
|
||||
while ((f = da->get_next()) != "") {
|
||||
String f = da->get_next();
|
||||
while (!f.empty()) {
|
||||
if (da->current_is_dir()) {
|
||||
dirs.push_back(f);
|
||||
} else {
|
||||
@ -524,6 +524,7 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S
|
||||
}
|
||||
}
|
||||
}
|
||||
f = da->get_next();
|
||||
}
|
||||
|
||||
da->list_dir_end();
|
||||
|
@ -787,10 +787,11 @@ void EditorFileDialog::update_file_list() {
|
||||
List<String> files;
|
||||
List<String> dirs;
|
||||
|
||||
String item;
|
||||
String item = dir_access->get_next();
|
||||
|
||||
while ((item = dir_access->get_next()) != "") {
|
||||
while (!item.empty()) {
|
||||
if (item == "." || item == "..") {
|
||||
item = dir_access->get_next();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -808,6 +809,8 @@ void EditorFileDialog::update_file_list() {
|
||||
files.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
item = dir_access->get_next();
|
||||
}
|
||||
|
||||
dirs.sort_custom<NaturalNoCaseComparator>();
|
||||
|
@ -241,9 +241,9 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
|
||||
}
|
||||
}
|
||||
|
||||
printf("Running: %ls", exec.c_str());
|
||||
printf("Running: %s", exec.utf8().get_data());
|
||||
for (List<String>::Element *E = args.front(); E; E = E->next()) {
|
||||
printf(" %ls", E->get().c_str());
|
||||
printf(" %s", E->get().utf8().get_data());
|
||||
};
|
||||
printf("\n");
|
||||
|
||||
|
@ -6601,7 +6601,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
|
||||
files_str += error_files[i].get_file().get_basename() + ",";
|
||||
}
|
||||
files_str = files_str.substr(0, files_str.length() - 1);
|
||||
accept->set_text(vformat(TTR("Error instancing scene from %s"), files_str.c_str()));
|
||||
accept->set_text(vformat(TTR("Error instancing scene from %s"), files_str));
|
||||
accept->popup_centered_minsize();
|
||||
}
|
||||
}
|
||||
|
@ -4266,7 +4266,7 @@ void SpatialEditorViewport::_perform_drop_data() {
|
||||
files_str += error_files[i].get_file().get_basename() + ",";
|
||||
}
|
||||
files_str = files_str.substr(0, files_str.length() - 1);
|
||||
accept->set_text(vformat(TTR("Error instancing scene from %s"), files_str.c_str()));
|
||||
accept->set_text(vformat(TTR("Error instancing scene from %s"), files_str));
|
||||
accept->popup_centered_minsize();
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ void ProjectSettingsEditor::_notification(int p_what) {
|
||||
}
|
||||
|
||||
static bool _validate_action_name(const String &p_name) {
|
||||
const CharType *cstr = p_name.c_str();
|
||||
const CharType *cstr = p_name.get_data();
|
||||
for (int i = 0; cstr[i]; i++) {
|
||||
if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' ||
|
||||
cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) {
|
||||
|
@ -165,15 +165,15 @@ bool test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
|
||||
Basis res = to_rotation.inverse() * rotation_from_computed_euler;
|
||||
|
||||
if ((res.get_axis(0) - Vector3(1.0, 0.0, 0.0)).length() > 0.1) {
|
||||
OS::get_singleton()->print("Fail due to X %ls\n", String(res.get_axis(0)).c_str());
|
||||
OS::get_singleton()->print("Fail due to X %s\n", String(res.get_axis(0)).utf8().get_data());
|
||||
pass = false;
|
||||
}
|
||||
if ((res.get_axis(1) - Vector3(0.0, 1.0, 0.0)).length() > 0.1) {
|
||||
OS::get_singleton()->print("Fail due to Y %ls\n", String(res.get_axis(1)).c_str());
|
||||
OS::get_singleton()->print("Fail due to Y %s\n", String(res.get_axis(1)).utf8().get_data());
|
||||
pass = false;
|
||||
}
|
||||
if ((res.get_axis(2) - Vector3(0.0, 0.0, 1.0)).length() > 0.1) {
|
||||
OS::get_singleton()->print("Fail due to Z %ls\n", String(res.get_axis(2)).c_str());
|
||||
OS::get_singleton()->print("Fail due to Z %s\n", String(res.get_axis(2)).utf8().get_data());
|
||||
pass = false;
|
||||
}
|
||||
|
||||
@ -186,15 +186,15 @@ bool test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
|
||||
res = to_rotation.inverse() * rotation_from_xyz_computed_euler;
|
||||
|
||||
if ((res.get_axis(0) - Vector3(1.0, 0.0, 0.0)).length() > 0.1) {
|
||||
OS::get_singleton()->print("Double check with XYZ rot order failed, due to X %ls\n", String(res.get_axis(0)).c_str());
|
||||
OS::get_singleton()->print("Double check with XYZ rot order failed, due to X %s\n", String(res.get_axis(0)).utf8().get_data());
|
||||
pass = false;
|
||||
}
|
||||
if ((res.get_axis(1) - Vector3(0.0, 1.0, 0.0)).length() > 0.1) {
|
||||
OS::get_singleton()->print("Double check with XYZ rot order failed, due to Y %ls\n", String(res.get_axis(1)).c_str());
|
||||
OS::get_singleton()->print("Double check with XYZ rot order failed, due to Y %s\n", String(res.get_axis(1)).utf8().get_data());
|
||||
pass = false;
|
||||
}
|
||||
if ((res.get_axis(2) - Vector3(0.0, 0.0, 1.0)).length() > 0.1) {
|
||||
OS::get_singleton()->print("Double check with XYZ rot order failed, due to Z %ls\n", String(res.get_axis(2)).c_str());
|
||||
OS::get_singleton()->print("Double check with XYZ rot order failed, due to Z %s\n", String(res.get_axis(2)).utf8().get_data());
|
||||
pass = false;
|
||||
}
|
||||
}
|
||||
@ -202,9 +202,9 @@ bool test_rotation(Vector3 deg_original_euler, RotOrder rot_order) {
|
||||
if (pass == false) {
|
||||
// Print phase only if not pass.
|
||||
OS *os = OS::get_singleton();
|
||||
os->print("Rotation order: %ls\n.", get_rot_order_name(rot_order).c_str());
|
||||
os->print("Original Rotation: %ls\n", String(deg_original_euler).c_str());
|
||||
os->print("Quaternionernion to rotation order: %ls\n", String(rad2deg(euler_from_rotation)).c_str());
|
||||
os->print("Rotation order: %s\n.", get_rot_order_name(rot_order).utf8().get_data());
|
||||
os->print("Original Rotation: %s\n", String(deg_original_euler).utf8().get_data());
|
||||
os->print("Quaternionernion to rotation order: %s\n", String(rad2deg(euler_from_rotation)).utf8().get_data());
|
||||
}
|
||||
|
||||
return pass;
|
||||
@ -302,9 +302,9 @@ void test_euler_conversion() {
|
||||
}
|
||||
|
||||
if (failed == 0) {
|
||||
OS::get_singleton()->print("%i passed tests for rotation order: %ls.\n", passed, get_rot_order_name(rotorder_to_test[h]).c_str());
|
||||
OS::get_singleton()->print("%i passed tests for rotation order: %s.\n", passed, get_rot_order_name(rotorder_to_test[h]).utf8().get_data());
|
||||
} else {
|
||||
OS::get_singleton()->print("%i FAILED tests for rotation order: %ls.\n", failed, get_rot_order_name(rotorder_to_test[h]).c_str());
|
||||
OS::get_singleton()->print("%i FAILED tests for rotation order: %s.\n", failed, get_rot_order_name(rotorder_to_test[h]).utf8().get_data());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
||||
|
||||
const char **tests_get_names() {
|
||||
static const char *test_names[] = {
|
||||
"string",
|
||||
//"string",
|
||||
"math",
|
||||
"basis",
|
||||
"transform",
|
||||
@ -78,9 +78,9 @@ const char **tests_get_names() {
|
||||
}
|
||||
|
||||
MainLoop *test_main(String p_test, const List<String> &p_args) {
|
||||
if (p_test == "string") {
|
||||
return TestString::test();
|
||||
}
|
||||
//if (p_test == "string") {
|
||||
// return TestString::test();
|
||||
//}
|
||||
|
||||
if (p_test == "math") {
|
||||
return TestMath::test();
|
||||
|
@ -43,16 +43,16 @@
|
||||
#include <wchar.h>
|
||||
|
||||
namespace TestString {
|
||||
|
||||
/*
|
||||
bool test_1() {
|
||||
OS::get_singleton()->print("\n\nTest 1: Assign from cstr\n");
|
||||
|
||||
String s = "Hello";
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Hello\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tResulted: %s\n", s.utf8().get_data());
|
||||
|
||||
return (wcscmp(s.c_str(), L"Hello") == 0);
|
||||
return (wcscmp(s.get_data(), U"Hello") == 0);
|
||||
}
|
||||
|
||||
bool test_2() {
|
||||
@ -62,9 +62,9 @@ bool test_2() {
|
||||
const String &t = s;
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Dolly\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
|
||||
OS::get_singleton()->print("\tResulted: %s\n", t.utf8().get_data());
|
||||
|
||||
return (wcscmp(t.c_str(), L"Dolly") == 0);
|
||||
return (wcscmp(t.get_data(), U"Dolly") == 0);
|
||||
}
|
||||
|
||||
bool test_3() {
|
||||
@ -74,9 +74,9 @@ bool test_3() {
|
||||
const String &t(s);
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Sheep\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
|
||||
OS::get_singleton()->print("\tResulted: %s\n", t.utf8().get_data());
|
||||
|
||||
return (wcscmp(t.c_str(), L"Sheep") == 0);
|
||||
return (wcscmp(t.get_data(), U"Sheep") == 0);
|
||||
}
|
||||
|
||||
bool test_4() {
|
||||
@ -85,9 +85,9 @@ bool test_4() {
|
||||
String s(L"Give me");
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Give me\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tResulted: %s\n", s.utf8().get_data());
|
||||
|
||||
return (wcscmp(s.c_str(), L"Give me") == 0);
|
||||
return (wcscmp(s.get_data(), U"Give me") == 0);
|
||||
}
|
||||
|
||||
bool test_5() {
|
||||
@ -96,9 +96,9 @@ bool test_5() {
|
||||
String s(L"Wool");
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Wool\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tResulted: %s\n", s.utf8().get_data());
|
||||
|
||||
return (wcscmp(s.c_str(), L"Wool") == 0);
|
||||
return (wcscmp(s.get_data(), U"Wool") == 0);
|
||||
}
|
||||
|
||||
bool test_6() {
|
||||
@ -112,7 +112,7 @@ bool test_6() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(s == L"Test Compare")) {
|
||||
if (!(s == U"Test Compare")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -247,9 +247,9 @@ bool test_13() {
|
||||
//static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 };
|
||||
String s = ustr;
|
||||
|
||||
OS::get_singleton()->print("\tUnicode: %ls\n", ustr);
|
||||
OS::get_singleton()->print("\tUnicode: %s\n", ustr);
|
||||
s.parse_utf8(s.utf8().get_data());
|
||||
OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tConvert/Parse UTF8: %s\n", s.get_data());
|
||||
|
||||
return (s == ustr);
|
||||
}
|
||||
@ -268,7 +268,7 @@ bool test_15() {
|
||||
OS::get_singleton()->print("\n\nTest 15: substr\n");
|
||||
|
||||
String s = "Killer Baby";
|
||||
OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n", s.c_str(), s.substr(3, 4).c_str());
|
||||
OS::get_singleton()->print("\tsubstr(3,4) of \"%s\" is \"%s\"\n", s.get_data(), s.substr(3, 4).get_data());
|
||||
|
||||
return (s.substr(3, 4) == "ler ");
|
||||
}
|
||||
@ -277,7 +277,7 @@ bool test_16() {
|
||||
OS::get_singleton()->print("\n\nTest 16: find\n");
|
||||
|
||||
String s = "Pretty Woman";
|
||||
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tString: %s\n", s.get_data());
|
||||
OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty"));
|
||||
OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck"));
|
||||
|
||||
@ -296,7 +296,7 @@ bool test_17() {
|
||||
OS::get_singleton()->print("\n\nTest 17: find no case\n");
|
||||
|
||||
String s = "Pretty Whale";
|
||||
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tString: %s\n", s.get_data());
|
||||
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
|
||||
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
|
||||
|
||||
@ -315,7 +315,7 @@ bool test_18() {
|
||||
OS::get_singleton()->print("\n\nTest 18: find no case\n");
|
||||
|
||||
String s = "Pretty Whale";
|
||||
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tString: %s\n", s.get_data());
|
||||
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
|
||||
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
|
||||
|
||||
@ -334,10 +334,10 @@ bool test_19() {
|
||||
OS::get_singleton()->print("\n\nTest 19: Search & replace\n");
|
||||
|
||||
String s = "Happy Birthday, Anna!";
|
||||
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tString: %s\n", s.get_data());
|
||||
|
||||
s = s.replace("Birthday", "Halloween");
|
||||
OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n", s.c_str());
|
||||
OS::get_singleton()->print("\tReplaced Birthday/Halloween: %s.\n", s.get_data());
|
||||
|
||||
return (s == "Happy Halloween, Anna!");
|
||||
}
|
||||
@ -347,9 +347,9 @@ bool test_20() {
|
||||
|
||||
String s = "Who is Frederic?";
|
||||
|
||||
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tString: %s\n", s.get_data());
|
||||
s = s.insert(s.find("?"), " Chopin");
|
||||
OS::get_singleton()->print("\tInserted Chopin: %ls.\n", s.c_str());
|
||||
OS::get_singleton()->print("\tInserted Chopin: %s.\n", s.get_data());
|
||||
|
||||
return (s == "Who is Frederic Chopin?");
|
||||
}
|
||||
@ -358,7 +358,7 @@ bool test_21() {
|
||||
OS::get_singleton()->print("\n\nTest 21: Number -> String\n");
|
||||
|
||||
OS::get_singleton()->print("\tPi is %f\n", 33.141593);
|
||||
OS::get_singleton()->print("\tPi String is %ls\n", String::num(3.141593).c_str());
|
||||
OS::get_singleton()->print("\tPi String is %s\n", String::num(3.141593).get_data());
|
||||
|
||||
return String::num(3.141593) == "3.141593";
|
||||
}
|
||||
@ -404,10 +404,10 @@ bool test_24() {
|
||||
|
||||
const char *slices[4] = { "Mars", "Jupiter", "Saturn", "Uranus" };
|
||||
|
||||
OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n", s.c_str(), ",");
|
||||
OS::get_singleton()->print("\tSlicing \"%s\" by \"%s\"..\n", s.get_data(), ",");
|
||||
|
||||
for (int i = 0; i < s.get_slice_count(","); i++) {
|
||||
OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str());
|
||||
OS::get_singleton()->print("\t\t%i- %s\n", i + 1, s.get_slice(",", i).get_data());
|
||||
|
||||
if (s.get_slice(",", i) != slices[i]) {
|
||||
return false;
|
||||
@ -422,11 +422,11 @@ bool test_25() {
|
||||
|
||||
String s = "Josephine is such a cute girl!";
|
||||
|
||||
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tString: %s\n", s.get_data());
|
||||
OS::get_singleton()->print("\tRemoving \"cute\"\n");
|
||||
|
||||
s.erase(s.find("cute "), String("cute ").length());
|
||||
OS::get_singleton()->print("\tResult: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tResult: %s\n", s.get_data());
|
||||
|
||||
return (s == "Josephine is such a girl!");
|
||||
}
|
||||
@ -440,13 +440,13 @@ bool test_26() {
|
||||
#else
|
||||
String s = "Double all the vowels.";
|
||||
|
||||
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tString: %s\n", s.get_data());
|
||||
OS::get_singleton()->print("\tRepeating instances of 'aeiou' once\n");
|
||||
|
||||
RegEx re("(?<vowel>[aeiou])");
|
||||
s = re.sub(s, "$0$vowel", true);
|
||||
|
||||
OS::get_singleton()->print("\tResult: %ls\n", s.c_str());
|
||||
OS::get_singleton()->print("\tResult: %s\n", s.get_data());
|
||||
|
||||
return (s == "Doouublee aall thee vooweels.");
|
||||
#endif
|
||||
@ -486,7 +486,7 @@ bool test_28() {
|
||||
OS::get_singleton()->print("\n\nTest 28: sprintf\n");
|
||||
|
||||
bool success, state = true;
|
||||
char output_format[] = "\tTest:\t%ls => %ls (%s)\n";
|
||||
char output_format[] = "\tTest:\t%s => %s (%s)\n";
|
||||
String format, output;
|
||||
Array args;
|
||||
bool error;
|
||||
@ -496,7 +496,7 @@ bool test_28() {
|
||||
args.clear();
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish % frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
//////// INTS
|
||||
@ -507,7 +507,7 @@ bool test_28() {
|
||||
args.push_back(5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Int left padded with zeroes.
|
||||
@ -516,7 +516,7 @@ bool test_28() {
|
||||
args.push_back(5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 00005 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Int left padded with spaces.
|
||||
@ -525,7 +525,7 @@ bool test_28() {
|
||||
args.push_back(5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Int right padded with spaces.
|
||||
@ -534,7 +534,7 @@ bool test_28() {
|
||||
args.push_back(5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Int with sign (positive).
|
||||
@ -543,7 +543,7 @@ bool test_28() {
|
||||
args.push_back(5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish +5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Negative int.
|
||||
@ -552,7 +552,7 @@ bool test_28() {
|
||||
args.push_back(-5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish -5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Negative int left padded with spaces.
|
||||
@ -561,7 +561,7 @@ bool test_28() {
|
||||
args.push_back(-5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish -5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Negative int left padded with zeros.
|
||||
@ -570,7 +570,7 @@ bool test_28() {
|
||||
args.push_back(-5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish -0005 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Negative int right padded with spaces.
|
||||
@ -579,7 +579,7 @@ bool test_28() {
|
||||
args.push_back(-5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish -5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Negative int right padded with zeros. (0 ignored)
|
||||
@ -588,7 +588,7 @@ bool test_28() {
|
||||
args.push_back(-5);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish -5 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Hex (lower)
|
||||
@ -597,7 +597,7 @@ bool test_28() {
|
||||
args.push_back(45);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 2d frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Hex (upper)
|
||||
@ -606,7 +606,7 @@ bool test_28() {
|
||||
args.push_back(45);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 2D frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Octal
|
||||
@ -615,7 +615,7 @@ bool test_28() {
|
||||
args.push_back(99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 143 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
////// REALS
|
||||
@ -626,7 +626,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 99.990000 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Real left-padded
|
||||
@ -635,7 +635,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 99.990000 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Real right-padded
|
||||
@ -644,7 +644,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 99.990000 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Real given int.
|
||||
@ -653,7 +653,7 @@ bool test_28() {
|
||||
args.push_back(99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 99.000000 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Real with sign (positive).
|
||||
@ -662,7 +662,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish +99.990000 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Real with 1 decimals.
|
||||
@ -671,7 +671,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 100.0 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Real with 12 decimals.
|
||||
@ -680,7 +680,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 99.990000000000 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Real with no decimals.
|
||||
@ -689,7 +689,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 100 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Negative real right padded with zeros. (0 ignored)
|
||||
@ -698,7 +698,7 @@ bool test_28() {
|
||||
args.push_back(-99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish -99.990000 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
/////// Strings.
|
||||
@ -709,7 +709,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish cheese frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// String left-padded
|
||||
@ -718,7 +718,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish cheese frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// String right-padded
|
||||
@ -727,7 +727,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish cheese frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
///// Characters
|
||||
@ -738,7 +738,7 @@ bool test_28() {
|
||||
args.push_back("A");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish A frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Character as int.
|
||||
@ -747,7 +747,7 @@ bool test_28() {
|
||||
args.push_back(65);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish A frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
///// Dynamic width
|
||||
@ -759,7 +759,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish cheese frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Int dynamic width
|
||||
@ -769,7 +769,7 @@ bool test_28() {
|
||||
args.push_back(99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 99 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Float dynamic width
|
||||
@ -780,7 +780,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == String("fish 99.990 frog") && !error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
///// Errors
|
||||
@ -791,7 +791,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "not enough arguments for format string" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// More arguments than formats.
|
||||
@ -801,7 +801,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "not all arguments converted during string formatting" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Incomplete format.
|
||||
@ -810,7 +810,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "incomplete format" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Bad character in format string
|
||||
@ -819,7 +819,7 @@ bool test_28() {
|
||||
args.push_back("cheese");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "unsupported format character" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Too many decimals.
|
||||
@ -828,7 +828,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "too many decimal points in format" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// * not a number
|
||||
@ -838,7 +838,7 @@ bool test_28() {
|
||||
args.push_back(99.99);
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "* wants number" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Character too long.
|
||||
@ -847,7 +847,7 @@ bool test_28() {
|
||||
args.push_back("sc");
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "%c requires number or single-character string" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
// Character bad type.
|
||||
@ -856,7 +856,7 @@ bool test_28() {
|
||||
args.push_back(Array());
|
||||
output = format.sprintf(args, &error);
|
||||
success = (output == "%c requires number or single-character string" && error);
|
||||
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print(output_format, format.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
return state;
|
||||
@ -866,50 +866,50 @@ bool test_29() {
|
||||
bool state = true;
|
||||
|
||||
IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
||||
OS::get_singleton()->print("ip0 is %ls\n", String(ip0).c_str());
|
||||
OS::get_singleton()->print("ip0 is %s\n", String(ip0).get_data());
|
||||
|
||||
IP_Address ip(0x0123, 0x4567, 0x89ab, 0xcdef, true);
|
||||
OS::get_singleton()->print("ip6 is %ls\n", String(ip).c_str());
|
||||
OS::get_singleton()->print("ip6 is %s\n", String(ip).get_data());
|
||||
|
||||
IP_Address ip2("fe80::52e5:49ff:fe93:1baf");
|
||||
OS::get_singleton()->print("ip6 is %ls\n", String(ip2).c_str());
|
||||
OS::get_singleton()->print("ip6 is %s\n", String(ip2).get_data());
|
||||
|
||||
IP_Address ip3("::ffff:192.168.0.1");
|
||||
OS::get_singleton()->print("ip6 is %ls\n", String(ip3).c_str());
|
||||
OS::get_singleton()->print("ip6 is %s\n", String(ip3).get_data());
|
||||
|
||||
String ip4 = "192.168.0.1";
|
||||
bool success = ip4.is_valid_ip_address();
|
||||
OS::get_singleton()->print("Is valid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Is valid ipv4: %s, %s\n", ip4.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
ip4 = "192.368.0.1";
|
||||
success = (!ip4.is_valid_ip_address());
|
||||
OS::get_singleton()->print("Is invalid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Is invalid ipv4: %s, %s\n", ip4.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
String ip6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
||||
success = ip6.is_valid_ip_address();
|
||||
OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Is valid ipv6: %s, %s\n", ip6.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
ip6 = "2001:0db8:85j3:0000:0000:8a2e:0370:7334";
|
||||
success = (!ip6.is_valid_ip_address());
|
||||
OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Is invalid ipv6: %s, %s\n", ip6.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
ip6 = "2001:0db8:85f345:0000:0000:8a2e:0370:7334";
|
||||
success = (!ip6.is_valid_ip_address());
|
||||
OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Is invalid ipv6: %s, %s\n", ip6.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
ip6 = "2001:0db8::0:8a2e:370:7334";
|
||||
success = (ip6.is_valid_ip_address());
|
||||
OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Is valid ipv6: %s, %s\n", ip6.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
ip6 = "::ffff:192.168.0.1";
|
||||
success = (ip6.is_valid_ip_address());
|
||||
OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Is valid ipv6: %s, %s\n", ip6.get_data(), success ? "OK" : "FAIL");
|
||||
state = state && success;
|
||||
|
||||
return state;
|
||||
@ -922,85 +922,85 @@ bool test_30() {
|
||||
String output = "Bytes 2 Var";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "linear2db";
|
||||
output = "Linear 2 Db";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "vector3";
|
||||
output = "Vector 3";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "sha256";
|
||||
output = "Sha 256";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "2db";
|
||||
output = "2 Db";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "PascalCase";
|
||||
output = "Pascal Case";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "PascalPascalCase";
|
||||
output = "Pascal Pascal Case";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "snake_case";
|
||||
output = "Snake Case";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "snake_snake_case";
|
||||
output = "Snake Snake Case";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "sha256sum";
|
||||
output = "Sha 256 Sum";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "cat2dog";
|
||||
output = "Cat 2 Dog";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "function(name)";
|
||||
output = "Function(name)";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls (existing incorrect behavior): %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s (existing incorrect behavior): %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "snake_case_function(snake_case_arg)";
|
||||
output = "Snake Case Function(snake Case Arg)";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls (existing incorrect behavior): %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s (existing incorrect behavior): %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
input = "snake_case_function( snake_case_arg )";
|
||||
output = "Snake Case Function( Snake Case Arg )";
|
||||
success = (input.capitalize() == output);
|
||||
state = state && success;
|
||||
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
|
||||
OS::get_singleton()->print("Capitalize %s: %s, %s\n", input.get_data(), output.get_data(), success ? "OK" : "FAIL");
|
||||
|
||||
return state;
|
||||
}
|
@ -85,9 +85,9 @@ bool test_aabb_regular() {
|
||||
|
||||
if (!pass) {
|
||||
String string = String("bb2 : ") + String(Variant(bb2));
|
||||
OS::get_singleton()->print("\t%ls\n", string.c_str());
|
||||
OS::get_singleton()->print("\t%s\n", string.utf8().get_data());
|
||||
string = String("bb3 : ") + String(Variant(bb3));
|
||||
OS::get_singleton()->print("\t%ls\n", string.c_str());
|
||||
OS::get_singleton()->print("\t%s\n", string.utf8().get_data());
|
||||
}
|
||||
|
||||
return pass;
|
||||
@ -133,9 +133,9 @@ bool test_aabb_non_uniform_scale() {
|
||||
|
||||
if (!pass) {
|
||||
String string = String("bb2 : ") + String(Variant(bb2));
|
||||
OS::get_singleton()->print("\t%ls\n", string.c_str());
|
||||
OS::get_singleton()->print("\t%s\n", string.utf8().get_data());
|
||||
string = String("bb3 : ") + String(Variant(bb3));
|
||||
OS::get_singleton()->print("\t%ls\n", string.c_str());
|
||||
OS::get_singleton()->print("\t%s\n", string.utf8().get_data());
|
||||
}
|
||||
|
||||
return pass;
|
||||
|
@ -288,7 +288,7 @@ void QueryBuilder::run_query() {
|
||||
}
|
||||
|
||||
void QueryBuilder::print() {
|
||||
//printf("%s\n", query_result.c_str());
|
||||
//printf("%s\n", query_result.get_data());
|
||||
ERR_PRINT(query_result);
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ void TableBuilder::run_query() {
|
||||
}
|
||||
|
||||
void TableBuilder::print() {
|
||||
//printf("%s\n", result.c_str());
|
||||
//printf("%s\n", result.get_data());
|
||||
print_error(result);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ void MysqlDatabase::connect(const String &connection_str) {
|
||||
String dbname = "testappdb";
|
||||
int port = 3306;
|
||||
|
||||
mysql = mysql_real_connect(mysql, host.c_str(), user.c_str(), password.c_str(), dbname.c_str(), port, NULL, 0);
|
||||
mysql = mysql_real_connect(mysql, host.get_data(), user.get_data(), password.get_data(), dbname.get_data(), port, NULL, 0);
|
||||
|
||||
if (mysql) {
|
||||
printf("mysql connected\n");
|
||||
@ -29,9 +29,9 @@ Ref<QueryResult> MysqlDatabase::query(const String &query) {
|
||||
if (!mysql)
|
||||
return nullptr;
|
||||
|
||||
//printf("%s\n", query.c_str());
|
||||
//printf("%s\n", query.get_data());
|
||||
|
||||
int error = mysql_real_query(mysql, query.c_str(), query.capacity());
|
||||
int error = mysql_real_query(mysql, query.get_data(), query.capacity());
|
||||
|
||||
if (error) {
|
||||
const char *merr = mysql_error(mysql);
|
||||
@ -55,9 +55,9 @@ void MysqlDatabase::query_run(const String &query) {
|
||||
if (!mysql)
|
||||
return;
|
||||
|
||||
//printf("%s\n", query.c_str());
|
||||
//printf("%s\n", query.get_data());
|
||||
|
||||
int error = mysql_real_query(mysql, query.c_str(), query.capacity());
|
||||
int error = mysql_real_query(mysql, query.get_data(), query.capacity());
|
||||
|
||||
if (error) {
|
||||
const char *merr = mysql_error(mysql);
|
||||
@ -104,7 +104,7 @@ String MysqlDatabase::escape(const String str) {
|
||||
//You must allocate the to buffer to be at least length*2+1 bytes long.
|
||||
res.ensure_capacity(str.size() * 2 + 1);
|
||||
|
||||
mysql_real_escape_string(mysql, res.dataw(), str.c_str(), str.size());
|
||||
mysql_real_escape_string(mysql, res.dataw(), str.get_data(), str.size());
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -113,7 +113,7 @@ void MysqlDatabase::escape(const String str, String *to) {
|
||||
//You must allocate the to buffer to be at least length*2+1 bytes long.
|
||||
to->ensure_capacity(str.size() * 2 + 1);
|
||||
|
||||
mysql_real_escape_string(mysql, to->dataw(), str.c_str(), str.size());
|
||||
mysql_real_escape_string(mysql, to->dataw(), str.get_data(), str.size());
|
||||
}
|
||||
|
||||
MysqlDatabase::MysqlDatabase() :
|
||||
|
@ -80,7 +80,7 @@ String SQLite3DatabaseConnection::escape(const String &str) {
|
||||
void SQLite3DatabaseConnection::escape_to(const String &str, String *to) {
|
||||
char *ret;
|
||||
|
||||
ret = sqlite3_mprintf("%q", str.c_str());
|
||||
ret = sqlite3_mprintf("%q", str.utf8().get_data());
|
||||
|
||||
if (ret) {
|
||||
to->operator=(ret);
|
||||
|
@ -156,26 +156,13 @@ void RegExMatch::_bind_methods() {
|
||||
}
|
||||
|
||||
void RegEx::_pattern_info(uint32_t what, void *where) const {
|
||||
if (sizeof(CharType) == 2) {
|
||||
pcre2_pattern_info_16((pcre2_code_16 *)code, what, where);
|
||||
|
||||
} else {
|
||||
pcre2_pattern_info_32((pcre2_code_32 *)code, what, where);
|
||||
}
|
||||
pcre2_pattern_info_32((pcre2_code_32 *)code, what, where);
|
||||
}
|
||||
|
||||
void RegEx::clear() {
|
||||
if (sizeof(CharType) == 2) {
|
||||
if (code) {
|
||||
pcre2_code_free_16((pcre2_code_16 *)code);
|
||||
code = nullptr;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (code) {
|
||||
pcre2_code_free_32((pcre2_code_32 *)code);
|
||||
code = nullptr;
|
||||
}
|
||||
if (code) {
|
||||
pcre2_code_free_32((pcre2_code_32 *)code);
|
||||
code = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,40 +174,22 @@ Error RegEx::compile(const String &p_pattern) {
|
||||
PCRE2_SIZE offset;
|
||||
uint32_t flags = PCRE2_DUPNAMES;
|
||||
|
||||
if (sizeof(CharType) == 2) {
|
||||
pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx;
|
||||
pcre2_compile_context_16 *cctx = pcre2_compile_context_create_16(gctx);
|
||||
PCRE2_SPTR16 p = (PCRE2_SPTR16)pattern.c_str();
|
||||
pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx;
|
||||
pcre2_compile_context_32 *cctx = pcre2_compile_context_create_32(gctx);
|
||||
PCRE2_SPTR32 p = (PCRE2_SPTR32)pattern.get_data();
|
||||
|
||||
code = pcre2_compile_16(p, pattern.length(), flags, &err, &offset, cctx);
|
||||
code = pcre2_compile_32(p, pattern.length(), flags, &err, &offset, cctx);
|
||||
|
||||
pcre2_compile_context_free_16(cctx);
|
||||
pcre2_compile_context_free_32(cctx);
|
||||
|
||||
if (!code) {
|
||||
PCRE2_UCHAR16 buf[256];
|
||||
pcre2_get_error_message_16(err, buf, 256);
|
||||
String message = String::num(offset) + ": " + String((const CharType *)buf);
|
||||
ERR_PRINT(message.utf8());
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
} else {
|
||||
pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx;
|
||||
pcre2_compile_context_32 *cctx = pcre2_compile_context_create_32(gctx);
|
||||
PCRE2_SPTR32 p = (PCRE2_SPTR32)pattern.c_str();
|
||||
|
||||
code = pcre2_compile_32(p, pattern.length(), flags, &err, &offset, cctx);
|
||||
|
||||
pcre2_compile_context_free_32(cctx);
|
||||
|
||||
if (!code) {
|
||||
PCRE2_UCHAR32 buf[256];
|
||||
pcre2_get_error_message_32(err, buf, 256);
|
||||
String message = String::num(offset) + ": " + String((const CharType *)buf);
|
||||
ERR_PRINT(message.utf8());
|
||||
return FAILED;
|
||||
}
|
||||
if (!code) {
|
||||
PCRE2_UCHAR32 buf[256];
|
||||
pcre2_get_error_message_32(err, buf, 256);
|
||||
String message = String::num(offset) + ": " + String((const CharType *)buf);
|
||||
ERR_PRINT(message.utf8());
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -234,41 +203,11 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end)
|
||||
length = p_end;
|
||||
}
|
||||
|
||||
if (sizeof(CharType) == 2) {
|
||||
pcre2_code_16 *c = (pcre2_code_16 *)code;
|
||||
pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx;
|
||||
pcre2_match_context_16 *mctx = pcre2_match_context_create_16(gctx);
|
||||
PCRE2_SPTR16 s = (PCRE2_SPTR16)p_subject.c_str();
|
||||
|
||||
pcre2_match_data_16 *match = pcre2_match_data_create_from_pattern_16(c, gctx);
|
||||
|
||||
int res = pcre2_match_16(c, s, length, p_offset, 0, match, mctx);
|
||||
|
||||
if (res < 0) {
|
||||
pcre2_match_data_free_16(match);
|
||||
pcre2_match_context_free_16(mctx);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t size = pcre2_get_ovector_count_16(match);
|
||||
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_16(match);
|
||||
|
||||
result->data.resize(size);
|
||||
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
result->data.write[i].start = ovector[i * 2];
|
||||
result->data.write[i].end = ovector[i * 2 + 1];
|
||||
}
|
||||
|
||||
pcre2_match_data_free_16(match);
|
||||
pcre2_match_context_free_16(mctx);
|
||||
|
||||
} else {
|
||||
{
|
||||
pcre2_code_32 *c = (pcre2_code_32 *)code;
|
||||
pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx;
|
||||
pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx);
|
||||
PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.c_str();
|
||||
PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.get_data();
|
||||
|
||||
pcre2_match_data_32 *match = pcre2_match_data_create_from_pattern_32(c, gctx);
|
||||
|
||||
@ -359,37 +298,12 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a
|
||||
length = p_end;
|
||||
}
|
||||
|
||||
if (sizeof(CharType) == 2) {
|
||||
pcre2_code_16 *c = (pcre2_code_16 *)code;
|
||||
pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx;
|
||||
pcre2_match_context_16 *mctx = pcre2_match_context_create_16(gctx);
|
||||
PCRE2_SPTR16 s = (PCRE2_SPTR16)p_subject.c_str();
|
||||
PCRE2_SPTR16 r = (PCRE2_SPTR16)p_replacement.c_str();
|
||||
PCRE2_UCHAR16 *o = (PCRE2_UCHAR16 *)output.ptrw();
|
||||
|
||||
pcre2_match_data_16 *match = pcre2_match_data_create_from_pattern_16(c, gctx);
|
||||
|
||||
int res = pcre2_substitute_16(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength);
|
||||
|
||||
if (res == PCRE2_ERROR_NOMEMORY) {
|
||||
output.resize(olength + safety_zone);
|
||||
o = (PCRE2_UCHAR16 *)output.ptrw();
|
||||
res = pcre2_substitute_16(c, s, length, p_offset, flags, match, mctx, r, p_replacement.length(), o, &olength);
|
||||
}
|
||||
|
||||
pcre2_match_data_free_16(match);
|
||||
pcre2_match_context_free_16(mctx);
|
||||
|
||||
if (res < 0) {
|
||||
return String();
|
||||
}
|
||||
|
||||
} else {
|
||||
{
|
||||
pcre2_code_32 *c = (pcre2_code_32 *)code;
|
||||
pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx;
|
||||
pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx);
|
||||
PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.c_str();
|
||||
PCRE2_SPTR32 r = (PCRE2_SPTR32)p_replacement.c_str();
|
||||
PCRE2_SPTR32 s = (PCRE2_SPTR32)p_subject.get_data();
|
||||
PCRE2_SPTR32 r = (PCRE2_SPTR32)p_replacement.get_data();
|
||||
PCRE2_UCHAR32 *o = (PCRE2_UCHAR32 *)output.ptrw();
|
||||
|
||||
pcre2_match_data_32 *match = pcre2_match_data_create_from_pattern_32(c, gctx);
|
||||
@ -455,20 +369,14 @@ Array RegEx::get_names() const {
|
||||
}
|
||||
|
||||
RegEx::RegEx() {
|
||||
if (sizeof(CharType) == 2) {
|
||||
general_ctx = pcre2_general_context_create_16(&_regex_malloc, &_regex_free, nullptr);
|
||||
|
||||
} else {
|
||||
{
|
||||
general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr);
|
||||
}
|
||||
code = nullptr;
|
||||
}
|
||||
|
||||
RegEx::RegEx(const String &p_pattern) {
|
||||
if (sizeof(CharType) == 2) {
|
||||
general_ctx = pcre2_general_context_create_16(&_regex_malloc, &_regex_free, nullptr);
|
||||
|
||||
} else {
|
||||
{
|
||||
general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr);
|
||||
}
|
||||
code = nullptr;
|
||||
@ -476,13 +384,7 @@ RegEx::RegEx(const String &p_pattern) {
|
||||
}
|
||||
|
||||
RegEx::~RegEx() {
|
||||
if (sizeof(CharType) == 2) {
|
||||
if (code) {
|
||||
pcre2_code_free_16((pcre2_code_16 *)code);
|
||||
}
|
||||
pcre2_general_context_free_16((pcre2_general_context_16 *)general_ctx);
|
||||
|
||||
} else {
|
||||
{
|
||||
if (code) {
|
||||
pcre2_code_free_32((pcre2_code_32 *)code);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ bool RTileSet::_set(const StringName &p_name, const Variant &p_value) {
|
||||
if (slash == -1) {
|
||||
return false;
|
||||
}
|
||||
int id = String::to_int(n.c_str(), slash);
|
||||
int id = String::to_int(n.get_data(), slash);
|
||||
|
||||
if (!tile_map.has(id)) {
|
||||
create_tile(id);
|
||||
@ -214,7 +214,7 @@ bool RTileSet::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
if (slash == -1) {
|
||||
return false;
|
||||
}
|
||||
int id = String::to_int(n.c_str(), slash);
|
||||
int id = String::to_int(n.get_data(), slash);
|
||||
|
||||
ERR_FAIL_COND_V(!tile_map.has(id), false);
|
||||
|
||||
|
@ -91,7 +91,7 @@ void InputMapEditor::_notification(int p_what) {
|
||||
}
|
||||
|
||||
static bool _validate_action_name(const String &p_name) {
|
||||
const CharType *cstr = p_name.c_str();
|
||||
const CharType *cstr = p_name.get_data();
|
||||
|
||||
for (int i = 0; cstr[i]; i++)
|
||||
if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' ||
|
||||
|
@ -49,13 +49,13 @@ void MessagePage::_migrate(const bool clear, const bool seed_db) {
|
||||
t->drop_table("message_page");
|
||||
db->query_run(t->result);
|
||||
|
||||
printf("%s\n", t->result.c_str());
|
||||
//printf("%s\n", t->result.utf8().get_data());
|
||||
|
||||
t->result.clear();
|
||||
|
||||
t->create_table("message_page")->integer("id")->auto_increment()->primary_key()->next_row()->varchar("text", 30)->ccreate_table();
|
||||
|
||||
printf("%s\n", t->result.c_str());
|
||||
//printf("%s\n", t->result.c_str());
|
||||
|
||||
db->query(t->result);
|
||||
|
||||
@ -63,14 +63,14 @@ void MessagePage::_migrate(const bool clear, const bool seed_db) {
|
||||
|
||||
b->insert("message_page")->values("default, 'aaewdwd'");
|
||||
|
||||
printf("%s\n", b->query_result.c_str());
|
||||
//printf("%s\n", b->query_result.c_str());
|
||||
|
||||
db->query_run(b->query_result);
|
||||
|
||||
b->query_result.clear();
|
||||
b->insert("message_page")->values("default, 'qqqqq'");
|
||||
|
||||
printf("%s\n", b->query_result.c_str());
|
||||
//printf("%s\n", b->query_result.c_str());
|
||||
|
||||
db->query_run(b->query_result);
|
||||
}
|
||||
|
@ -1040,10 +1040,10 @@ Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExp
|
||||
|
||||
Error EditorExportPlatformIOS::_walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata) {
|
||||
Vector<String> dirs;
|
||||
String path;
|
||||
String current_dir = p_da->get_current_dir();
|
||||
p_da->list_dir_begin();
|
||||
while ((path = p_da->get_next()).length() != 0) {
|
||||
String path = p_da->get_next();
|
||||
while (!path.empty()) {
|
||||
if (p_da->current_is_dir()) {
|
||||
if (path != "." && path != "..") {
|
||||
dirs.push_back(path);
|
||||
@ -1055,6 +1055,8 @@ Error EditorExportPlatformIOS::_walk_dir_recursive(DirAccess *p_da, FileHandler
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
path = p_da->get_next();
|
||||
}
|
||||
p_da->list_dir_end();
|
||||
|
||||
|
@ -173,7 +173,7 @@ String iOS::get_rate_url(int p_app_id) const {
|
||||
|
||||
String ret = app_url_path.replace("APP_ID", String::num(p_app_id));
|
||||
|
||||
printf("returning rate url %ls\n", ret.c_str());
|
||||
printf("returning rate url %s\n", ret.utf8().get_data());
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
@ -88,7 +88,7 @@ void OSIPhone::set_data_dir(String p_dir) {
|
||||
DirAccess *da = DirAccess::open(p_dir);
|
||||
|
||||
data_dir = da->get_current_dir();
|
||||
printf("setting data dir to %ls from %ls\n", data_dir.c_str(), p_dir.c_str());
|
||||
printf("setting data dir to %s from %s\n", data_dir.utf8().get_data(), p_dir.utf8().get_data());
|
||||
memdelete(da);
|
||||
};
|
||||
|
||||
|
@ -1298,11 +1298,13 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String
|
||||
|
||||
DirAccess *da = DirAccess::open(dir);
|
||||
da->list_dir_begin();
|
||||
String f;
|
||||
while ((f = da->get_next()) != "") {
|
||||
String f = da->get_next();
|
||||
while (f.empty()) {
|
||||
if (f == "." || f == "..") {
|
||||
f = da->get_next();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (da->is_link(f)) {
|
||||
OS::Time time = OS::get_singleton()->get_time();
|
||||
OS::Date date = OS::get_singleton()->get_date();
|
||||
@ -1391,6 +1393,7 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("ZIP Creation"), vformat(TTR("Could not open file to read from path \"%s\"."), dir.plus_file(f)));
|
||||
return;
|
||||
}
|
||||
|
||||
const int bufsize = 16384;
|
||||
uint8_t buf[bufsize];
|
||||
|
||||
@ -1404,7 +1407,10 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String
|
||||
|
||||
zipCloseFileInZip(p_zip);
|
||||
}
|
||||
|
||||
f = da->get_next();
|
||||
}
|
||||
|
||||
da->list_dir_end();
|
||||
memdelete(da);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ static String format_error_message(DWORD id) {
|
||||
size_t size = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
|
||||
|
||||
String msg = "Error " + itos(id) + ": " + String(messageBuffer, size);
|
||||
String msg = "Error " + itos(id) + ": " + String::utf16((const char16_t *)messageBuffer, size);
|
||||
|
||||
LocalFree(messageBuffer);
|
||||
|
||||
@ -1132,7 +1132,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
case WM_DROPFILES: {
|
||||
HDROP hDropInfo = (HDROP)wParam;
|
||||
const int buffsize = 4096;
|
||||
wchar_t buf[buffsize];
|
||||
WCHAR buf[buffsize];
|
||||
|
||||
int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF, NULL, 0);
|
||||
|
||||
@ -1140,7 +1140,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
for (int i = 0; i < fcount; i++) {
|
||||
DragQueryFileW(hDropInfo, i, buf, buffsize);
|
||||
String file = buf;
|
||||
String file = String::utf16((const char16_t *)buf);
|
||||
files.push_back(file);
|
||||
}
|
||||
|
||||
@ -1662,11 +1662,12 @@ void OS_Windows::set_clipboard(const String &p_text) {
|
||||
}
|
||||
EmptyClipboard();
|
||||
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (text.length() + 1) * sizeof(CharType));
|
||||
Char16String utf16 = text.utf16();
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (utf16.length() + 1) * sizeof(WCHAR));
|
||||
ERR_FAIL_COND_MSG(mem == NULL, "Unable to allocate memory for clipboard contents.");
|
||||
|
||||
LPWSTR lptstrCopy = (LPWSTR)GlobalLock(mem);
|
||||
memcpy(lptstrCopy, text.c_str(), (text.length() + 1) * sizeof(CharType));
|
||||
memcpy(lptstrCopy, utf16.get_data(), (utf16.length() + 1) * sizeof(WCHAR));
|
||||
GlobalUnlock(mem);
|
||||
|
||||
SetClipboardData(CF_UNICODETEXT, mem);
|
||||
@ -1697,7 +1698,7 @@ String OS_Windows::get_clipboard() const {
|
||||
if (mem != NULL) {
|
||||
LPWSTR ptr = (LPWSTR)GlobalLock(mem);
|
||||
if (ptr != NULL) {
|
||||
ret = String((CharType *)ptr);
|
||||
ret = String::utf16((const char16_t *)ptr);
|
||||
GlobalUnlock(mem);
|
||||
};
|
||||
};
|
||||
@ -1774,7 +1775,7 @@ void OS_Windows::alert(const String &p_alert, const String &p_title) {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageBoxW(NULL, p_alert.c_str(), p_title.c_str(), MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL);
|
||||
MessageBoxW(nullptr, (LPCWSTR)(p_alert.utf16().get_data()), (LPCWSTR)(p_title.utf16().get_data()), MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL);
|
||||
}
|
||||
|
||||
void OS_Windows::set_mouse_mode(MouseMode p_mode) {
|
||||
@ -1856,7 +1857,7 @@ int OS_Windows::get_mouse_button_state() const {
|
||||
}
|
||||
|
||||
void OS_Windows::set_window_title(const String &p_title) {
|
||||
SetWindowTextW(hWnd, p_title.c_str());
|
||||
SetWindowTextW(hWnd, (LPCWSTR)(p_title.utf16().get_data()));
|
||||
}
|
||||
|
||||
void OS_Windows::set_window_mouse_passthrough(const PoolVector2Array &p_region) {
|
||||
@ -2341,10 +2342,10 @@ Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_han
|
||||
DLL_DIRECTORY_COOKIE cookie = NULL;
|
||||
|
||||
if (p_also_set_library_path && has_dll_directory_api) {
|
||||
cookie = add_dll_directory(path.get_base_dir().c_str());
|
||||
cookie = add_dll_directory((LPCWSTR)(path.get_base_dir().utf16().get_data()));
|
||||
}
|
||||
|
||||
p_library_handle = (void *)LoadLibraryExW(path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
|
||||
p_library_handle = (void *)LoadLibraryExW((LPCWSTR)(path.utf16().get_data()), nullptr, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
|
||||
ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + format_error_message(GetLastError()) + ".");
|
||||
|
||||
if (cookie) {
|
||||
@ -2842,11 +2843,7 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
|
||||
ZeroMemory(&pi.pi, sizeof(pi.pi));
|
||||
LPSTARTUPINFOW si_w = (LPSTARTUPINFOW)&pi.si;
|
||||
|
||||
Vector<CharType> modstr; // Windows wants to change this no idea why.
|
||||
modstr.resize(cmdline.size());
|
||||
for (int i = 0; i < cmdline.size(); i++) {
|
||||
modstr.write[i] = cmdline[i];
|
||||
}
|
||||
Char16String modstr = cmdline.utf16(); // Windows wants to change this no idea why.
|
||||
|
||||
bool inherit_handles = false;
|
||||
HANDLE pipe[2] = { NULL, NULL };
|
||||
@ -2874,7 +2871,7 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
|
||||
creaton_flags |= CREATE_NO_WINDOW;
|
||||
}
|
||||
|
||||
int ret = CreateProcessW(NULL, modstr.ptrw(), NULL, NULL, inherit_handles, creaton_flags, NULL, NULL, si_w, &pi.pi);
|
||||
int ret = CreateProcessW(nullptr, (LPWSTR)(modstr.ptrw()), nullptr, nullptr, 0, NORMAL_PRIORITY_CLASS & CREATE_NO_WINDOW, nullptr, nullptr, si_w, &pi.pi);
|
||||
if (!ret && r_pipe) {
|
||||
CloseHandle(pipe[0]); // Cleanup pipe handles.
|
||||
CloseHandle(pipe[1]);
|
||||
@ -2983,16 +2980,17 @@ bool OS_Windows::is_process_running(const ProcessID &p_pid) const {
|
||||
}
|
||||
|
||||
Error OS_Windows::set_cwd(const String &p_cwd) {
|
||||
if (_wchdir(p_cwd.c_str()) != 0)
|
||||
if (_wchdir((LPCWSTR)(p_cwd.utf16().get_data())) != 0) {
|
||||
return ERR_CANT_OPEN;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
String OS_Windows::get_executable_path() const {
|
||||
wchar_t bufname[4096];
|
||||
WCHAR bufname[4096];
|
||||
GetModuleFileNameW(NULL, bufname, 4096);
|
||||
String s = bufname;
|
||||
String s = String::utf16((const char16_t *)bufname);
|
||||
return s.replace("\\", "/");
|
||||
}
|
||||
|
||||
@ -3142,11 +3140,11 @@ void OS_Windows::set_icon(const Ref<Image> &p_icon) {
|
||||
|
||||
bool OS_Windows::has_environment(const String &p_var) const {
|
||||
#ifdef MINGW_ENABLED
|
||||
return _wgetenv(p_var.c_str()) != NULL;
|
||||
return _wgetenv((LPCWSTR)(p_var.utf16().get_data())) != nullptr;
|
||||
#else
|
||||
wchar_t *env;
|
||||
WCHAR *env;
|
||||
size_t len;
|
||||
_wdupenv_s(&env, &len, p_var.c_str());
|
||||
_wdupenv_s(&env, &len, (LPCWSTR)(p_var.utf16().get_data()));
|
||||
const bool has_env = env != NULL;
|
||||
free(env);
|
||||
return has_env;
|
||||
@ -3154,16 +3152,16 @@ bool OS_Windows::has_environment(const String &p_var) const {
|
||||
};
|
||||
|
||||
String OS_Windows::get_environment(const String &p_var) const {
|
||||
wchar_t wval[0x7Fff]; // MSDN says 32767 char is the maximum
|
||||
int wlen = GetEnvironmentVariableW(p_var.c_str(), wval, 0x7Fff);
|
||||
WCHAR wval[0x7fff]; // MSDN says 32767 char is the maximum
|
||||
int wlen = GetEnvironmentVariableW((LPCWSTR)(p_var.utf16().get_data()), wval, 0x7fff);
|
||||
if (wlen > 0) {
|
||||
return wval;
|
||||
return String::utf16((const char16_t *)wval);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool OS_Windows::set_environment(const String &p_var, const String &p_value) const {
|
||||
return (bool)SetEnvironmentVariableW(p_var.c_str(), p_value.c_str());
|
||||
return (bool)SetEnvironmentVariableW((LPCWSTR)(p_var.utf16().get_data()), (LPCWSTR)(p_value.utf16().get_data()));
|
||||
}
|
||||
|
||||
String OS_Windows::get_stdin_string(bool p_block) {
|
||||
@ -3184,7 +3182,8 @@ void OS_Windows::move_window_to_foreground() {
|
||||
}
|
||||
|
||||
Error OS_Windows::shell_open(String p_uri) {
|
||||
INT_PTR ret = (INT_PTR)ShellExecuteW(nullptr, nullptr, p_uri.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
INT_PTR ret = (INT_PTR)ShellExecuteW(nullptr, nullptr, (LPCWSTR)(p_uri.utf16().get_data()), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
|
||||
if (ret > 32) {
|
||||
return OK;
|
||||
} else {
|
||||
@ -3265,7 +3264,7 @@ String OS_Windows::get_processor_name() const {
|
||||
const String id = "Hardware\\Description\\System\\CentralProcessor\\0";
|
||||
|
||||
HKEY hkey;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, (LPCWSTR)(id.c_str()), 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) {
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, (LPCWSTR)(id.utf16().get_data()), 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) {
|
||||
ERR_FAIL_V_MSG("", String("Couldn't get the CPU model name. Returning an empty string."));
|
||||
}
|
||||
|
||||
@ -3385,13 +3384,13 @@ String OS_Windows::keyboard_get_layout_language(int p_index) const {
|
||||
HKL *layouts = (HKL *)memalloc(layout_count * sizeof(HKL));
|
||||
GetKeyboardLayoutList(layout_count, layouts);
|
||||
|
||||
wchar_t buf[LOCALE_NAME_MAX_LENGTH];
|
||||
memset(buf, 0, LOCALE_NAME_MAX_LENGTH * sizeof(wchar_t));
|
||||
WCHAR buf[LOCALE_NAME_MAX_LENGTH];
|
||||
memset(buf, 0, LOCALE_NAME_MAX_LENGTH * sizeof(WCHAR));
|
||||
LCIDToLocaleName(MAKELCID(LOWORD(layouts[p_index]), SORT_DEFAULT), buf, LOCALE_NAME_MAX_LENGTH, 0);
|
||||
|
||||
memfree(layouts);
|
||||
|
||||
return String(buf).substr(0, 2);
|
||||
return String::utf16((const char16_t *)buf).substr(0, 2);
|
||||
}
|
||||
|
||||
uint32_t OS_Windows::keyboard_get_scancode_from_physical(uint32_t p_scancode) const {
|
||||
@ -3435,17 +3434,17 @@ String _get_full_layout_name_from_registry(HKL p_layout) {
|
||||
String ret;
|
||||
|
||||
HKEY hkey;
|
||||
wchar_t layout_text[1024];
|
||||
memset(layout_text, 0, 1024 * sizeof(wchar_t));
|
||||
WCHAR layout_text[1024];
|
||||
memset(layout_text, 0, 1024 * sizeof(WCHAR));
|
||||
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, (LPCWSTR)id.c_str(), 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) {
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, (LPCWSTR)(id.utf16().get_data()), 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
DWORD buffer = 1024;
|
||||
DWORD vtype = REG_SZ;
|
||||
if (RegQueryValueExW(hkey, L"Layout Text", NULL, &vtype, (LPBYTE)layout_text, &buffer) == ERROR_SUCCESS) {
|
||||
ret = String(layout_text);
|
||||
ret = String::utf16((const char16_t *)layout_text);
|
||||
}
|
||||
RegCloseKey(hkey);
|
||||
return ret;
|
||||
@ -3461,15 +3460,15 @@ String OS_Windows::keyboard_get_layout_name(int p_index) const {
|
||||
|
||||
String ret = _get_full_layout_name_from_registry(layouts[p_index]); // Try reading full name from Windows registry, fallback to locale name if failed (e.g. on Wine).
|
||||
if (ret == String()) {
|
||||
wchar_t buf[LOCALE_NAME_MAX_LENGTH];
|
||||
memset(buf, 0, LOCALE_NAME_MAX_LENGTH * sizeof(wchar_t));
|
||||
WCHAR buf[LOCALE_NAME_MAX_LENGTH];
|
||||
memset(buf, 0, LOCALE_NAME_MAX_LENGTH * sizeof(WCHAR));
|
||||
LCIDToLocaleName(MAKELCID(LOWORD(layouts[p_index]), SORT_DEFAULT), buf, LOCALE_NAME_MAX_LENGTH, 0);
|
||||
|
||||
wchar_t name[1024];
|
||||
memset(name, 0, 1024 * sizeof(wchar_t));
|
||||
WCHAR name[1024];
|
||||
memset(name, 0, 1024 * sizeof(WCHAR));
|
||||
GetLocaleInfoEx(buf, LOCALE_SLOCALIZEDDISPLAYNAME, (LPWSTR)&name, 1024);
|
||||
|
||||
ret = String(name);
|
||||
ret = String::utf16((const char16_t *)name);
|
||||
}
|
||||
memfree(layouts);
|
||||
|
||||
@ -3652,7 +3651,7 @@ String OS_Windows::get_system_dir(SystemDir p_dir, bool p_shared_storage) const
|
||||
PWSTR szPath;
|
||||
HRESULT res = SHGetKnownFolderPath(id, 0, NULL, &szPath);
|
||||
ERR_FAIL_COND_V(res != S_OK, String());
|
||||
String path = String(szPath).replace("\\", "/");
|
||||
String path = String::utf16((const char16_t *)szPath).replace("\\", "/");
|
||||
CoTaskMemFree(szPath);
|
||||
return path;
|
||||
}
|
||||
@ -3678,7 +3677,7 @@ String OS_Windows::get_user_data_dir() const {
|
||||
String OS_Windows::get_unique_id() const {
|
||||
HW_PROFILE_INFO HwProfInfo;
|
||||
ERR_FAIL_COND_V(!GetCurrentHwProfile(&HwProfInfo), "");
|
||||
return String(HwProfInfo.szHwProfileGuid);
|
||||
return String::utf16((const char16_t *)(HwProfInfo.szHwProfileGuid), HW_PROFILE_GUIDLEN);
|
||||
}
|
||||
|
||||
void OS_Windows::set_ime_active(const bool p_active) {
|
||||
@ -3759,9 +3758,11 @@ void OS_Windows::process_and_drop_events() {
|
||||
|
||||
Error OS_Windows::move_to_trash(const String &p_path) {
|
||||
SHFILEOPSTRUCTW sf;
|
||||
WCHAR *from = new WCHAR[p_path.length() + 2];
|
||||
wcscpy_s(from, p_path.length() + 1, p_path.c_str());
|
||||
from[p_path.length() + 1] = 0;
|
||||
|
||||
Char16String utf16 = p_path.utf16();
|
||||
WCHAR *from = new WCHAR[utf16.length() + 2];
|
||||
wcscpy_s(from, utf16.length() + 1, (LPCWSTR)(utf16.get_data()));
|
||||
from[utf16.length() + 1] = 0;
|
||||
|
||||
sf.hwnd = hWnd;
|
||||
sf.wFunc = FO_DELETE;
|
||||
|
@ -59,10 +59,11 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
|
||||
MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen);
|
||||
wbuf[wlen] = 0;
|
||||
|
||||
if (p_err)
|
||||
if (p_err) {
|
||||
fwprintf(stderr, L"%ls", wbuf);
|
||||
else
|
||||
} else {
|
||||
wprintf(L"%ls", wbuf);
|
||||
}
|
||||
|
||||
memfree(wbuf);
|
||||
|
||||
|
@ -912,9 +912,9 @@ float CanvasItem::draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const
|
||||
ERR_FAIL_COND_V(p_font.is_null(), 0);
|
||||
|
||||
if (p_font->has_outline()) {
|
||||
p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.c_str()[0], Color(1, 1, 1), true);
|
||||
p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.get_data()[0], Color(1, 1, 1), true);
|
||||
}
|
||||
return p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.c_str()[0], p_modulate);
|
||||
return p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.get_data()[0], p_modulate);
|
||||
}
|
||||
|
||||
void CanvasItem::_notify_transform(CanvasItem *p_node) {
|
||||
|
@ -432,10 +432,11 @@ void FileDialog::update_file_list() {
|
||||
List<String> dirs;
|
||||
|
||||
bool is_hidden;
|
||||
String item;
|
||||
String item = dir_access->get_next();
|
||||
|
||||
while ((item = dir_access->get_next()) != "") {
|
||||
while (!item.empty()) {
|
||||
if (item == "." || item == "..") {
|
||||
item = dir_access->get_next();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -448,6 +449,8 @@ void FileDialog::update_file_list() {
|
||||
dirs.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
item = dir_access->get_next();
|
||||
}
|
||||
|
||||
dirs.sort_custom<NaturalNoCaseComparator>();
|
||||
|
@ -357,7 +357,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
|
||||
font = p_base_font;
|
||||
}
|
||||
|
||||
const CharType *c = text->text.c_str();
|
||||
const CharType *c = text->text.get_data();
|
||||
const CharType *cf = c;
|
||||
int ascent = font->get_ascent();
|
||||
int descent = font->get_descent();
|
||||
|
@ -132,7 +132,7 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
|
||||
int w = 0;
|
||||
|
||||
int len = text[p_line].data.length();
|
||||
const CharType *str = text[p_line].data.c_str();
|
||||
const CharType *str = text[p_line].data.get_data();
|
||||
|
||||
// Update width.
|
||||
|
||||
@ -169,7 +169,7 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
|
||||
bool match;
|
||||
|
||||
if (lr != 0 && lr <= left) {
|
||||
kc = cr.begin_key.c_str();
|
||||
kc = cr.begin_key.get_data();
|
||||
|
||||
match = true;
|
||||
|
||||
@ -195,7 +195,7 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
|
||||
|
||||
lr = cr.end_key.length();
|
||||
if (lr != 0 && lr <= left) {
|
||||
kc = cr.end_key.c_str();
|
||||
kc = cr.end_key.get_data();
|
||||
|
||||
match = true;
|
||||
|
||||
@ -7368,7 +7368,7 @@ int TextEdit::get_line_width(int p_line, int p_wrap_index) const {
|
||||
|
||||
int w = 0;
|
||||
int len = rows[p_wrap_index].length();
|
||||
const CharType *str = rows[p_wrap_index].c_str();
|
||||
const CharType *str = rows[p_wrap_index].get_data();
|
||||
for (int i = 0; i < len; i++) {
|
||||
w += text.get_char_width(str[i], str[i + 1], w);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user