summaryrefslogtreecommitdiff
path: root/core/ustring.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/ustring.h')
-rw-r--r--core/ustring.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/core/ustring.h b/core/ustring.h
index 9288c1526e..dfc5044942 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -36,10 +36,6 @@
#include "core/typedefs.h"
#include "core/vector.h"
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-
template <class T>
class CharProxy {
friend class CharString;
@@ -101,12 +97,17 @@ public:
_cowdata._ref(p_str._cowdata);
return *this;
}
+ _FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); }
+ CharString &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; }
const char *get_data() const;
operator const char *() const { return get_data(); };
+
+protected:
+ void copy_from(const char *p_cstr);
};
typedef wchar_t CharType;
@@ -132,6 +133,7 @@ class String {
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 {
@@ -196,7 +198,7 @@ public:
}
/* complex helpers */
- String substr(int p_from, int p_chars) const;
+ String substr(int p_from, int p_chars = -1) const;
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
@@ -221,6 +223,7 @@ public:
String replace(const String &p_key, const String &p_with) const;
String replace(const char *p_key, const char *p_with) const;
String replacen(const String &p_key, const String &p_with) const;
+ String repeat(int p_count) const;
String insert(int p_at_pos, const String &p_string) const;
String pad_decimals(int p_digits) const;
String pad_zeros(int p_digits) const;
@@ -246,6 +249,7 @@ public:
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);
@@ -273,6 +277,9 @@ public:
String to_upper() const;
String to_lower() const;
+ int count(const String &p_string, int p_from = 0, int p_to = 0) const;
+ int countn(const String &p_string, int p_from = 0, int p_to = 0) const;
+
String left(int p_pos) const;
String right(int p_pos) const;
String dedent() const;
@@ -299,8 +306,10 @@ public:
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;
Vector<uint8_t> md5_buffer() const;
+ Vector<uint8_t> sha1_buffer() const;
Vector<uint8_t> sha256_buffer() const;
_FORCE_INLINE_ bool empty() const { return length() == 0; }
@@ -313,7 +322,7 @@ public:
String path_to_file(const String &p_path) const;
String get_base_dir() const;
String get_file() const;
- static String humanize_size(size_t p_size);
+ static String humanize_size(uint64_t p_size);
String simplify_path() const;
String xml_escape(bool p_escape_quotes = false) const;
@@ -335,6 +344,7 @@ public:
bool is_valid_hex_number(bool p_with_prefix) const;
bool is_valid_html_color() const;
bool is_valid_ip_address() const;
+ bool is_valid_filename() const;
/**
* The constructors must not depend on other overloads
@@ -359,6 +369,7 @@ String operator+(const char *p_chr, const String &p_str);
String operator+(CharType p_chr, const String &p_str);
String itos(int64_t p_val);
+String uitos(uint64_t p_val);
String rtos(double p_val);
String rtoss(double p_val); //scientific version
@@ -397,8 +408,6 @@ _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
l_ptr++;
r_ptr++;
}
-
- CRASH_COND(true); // unreachable
}
/* end of namespace */
@@ -406,11 +415,18 @@ _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
//tool translate
#ifdef TOOLS_ENABLED
+//gets parsed
String TTR(const String &);
+//use for C strings
+#define TTRC(m_value) (m_value)
+//use to avoid parsing (for use later with C strings)
+#define TTRGET(m_value) TTR(m_value)
#else
-#define TTR(m_val) (String())
+#define TTR(m_value) (String())
+#define TTRC(m_value) (m_value)
+#define TTRGET(m_value) (m_value)
#endif