diff options
Diffstat (limited to 'core/ustring.h')
-rw-r--r-- | core/ustring.h | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/core/ustring.h b/core/ustring.h index ee7e3b1e16..d37346fbd6 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -51,8 +51,9 @@ class CharProxy { public: _FORCE_INLINE_ operator T() const { - if (unlikely(_index == _cowdata.size())) + if (unlikely(_index == _cowdata.size())) { return _null; + } return _cowdata.get(_index); } @@ -71,7 +72,6 @@ public: }; class CharString { - CowData<char> _cowdata; static const char _null; @@ -84,8 +84,9 @@ public: _FORCE_INLINE_ char get(int p_index) const { return _cowdata.get(p_index); } _FORCE_INLINE_ void set(int p_index, const char &p_elem) { _cowdata.set(p_index, p_elem); } _FORCE_INLINE_ const char &operator[](int p_index) const { - if (unlikely(p_index == _cowdata.size())) + if (unlikely(p_index == _cowdata.size())) { return _null; + } return _cowdata.get(p_index); } @@ -113,7 +114,6 @@ protected: typedef wchar_t CharType; struct StrRange { - const CharType *c_str; int len; @@ -124,7 +124,6 @@ struct StrRange { }; class String { - CowData<CharType> _cowdata; static const CharType _null; @@ -154,8 +153,9 @@ public: Error resize(int p_size) { return _cowdata.resize(p_size); } _FORCE_INLINE_ const CharType &operator[](int p_index) const { - if (unlikely(p_index == _cowdata.size())) + if (unlikely(p_index == _cowdata.size())) { return _null; + } return _cowdata.get(p_index); } @@ -202,7 +202,6 @@ public: int find(const String &p_str, int p_from = 0) const; ///< return <0 if failed int find(const char *p_str, int p_from = 0) const; ///< return <0 if failed int find_char(const CharType &p_char, int p_from = 0) const; ///< return <0 if failed - int find_last(const String &p_str) const; ///< return <0 if failed int findn(const String &p_str, int p_from = 0) const; ///< return <0 if failed, case insensitive int rfind(const String &p_str, int p_from = -1) const; ///< return <0 if failed int rfindn(const String &p_str, int p_from = -1) const; ///< return <0 if failed, case insensitive @@ -243,18 +242,15 @@ public: static String md5(const uint8_t *p_md5); static String hex_encode_buffer(const uint8_t *p_buffer, int p_len); bool is_numeric() const; - double to_double() const; - float to_float() const; - int hex_to_int(bool p_with_prefix = true) const; - int to_int() 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 double to_double(const char *p_str); - 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); + double to_float() const; + + int64_t hex_to_int(bool p_with_prefix = true) const; + int64_t bin_to_int(bool p_with_prefix = true) const; + int64_t to_int() const; + static int64_t to_int(const char *p_str, int p_len = -1); + static double to_float(const char *p_str); + static double to_float(const CharType *p_str, const CharType **r_end = nullptr); + static int64_t to_int(const CharType *p_str, int p_len = -1, bool p_clamp = false); String capitalize() const; String camelcase_to_underscore(bool lowercase = true) const; @@ -377,36 +373,31 @@ String rtos(double p_val); String rtoss(double p_val); //scientific version struct NoCaseComparator { - bool operator()(const String &p_a, const String &p_b) const { - return p_a.nocasecmp_to(p_b) < 0; } }; struct NaturalNoCaseComparator { - bool operator()(const String &p_a, const String &p_b) const { - return p_a.naturalnocasecmp_to(p_b) < 0; } }; 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) + if (*l_ptr == 0 && *r_ptr == 0) { return false; - else if (*l_ptr == 0) + } else if (*l_ptr == 0) { return true; - else if (*r_ptr == 0) + } else if (*r_ptr == 0) { return false; - else if (*l_ptr < *r_ptr) + } else if (*l_ptr < *r_ptr) { return true; - else if (*l_ptr > *r_ptr) + } else if (*l_ptr > *r_ptr) { return false; + } l_ptr++; r_ptr++; |