|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_STRING_STRING_H
22 #define ELM_STRING_STRING_H
24 #include <elm/PreIterator.h>
25 #include <elm/string/CString.h>
35 typedef struct buffer_t {
39 static buffer_t empty_buf;
40 static const int zero_off =
sizeof(
unsigned short);
41 mutable const char *buf;
42 mutable unsigned short off, len;
45 void copy(
const char *
str,
int _len);
46 void lock(
void)
const { ((buffer_t *)buf)->use++; }
48 void unlock(
void)
const {
49 ((buffer_t *)buf)->use--;
50 if(!((buffer_t *)buf)->use && buf != (
char *)&empty_buf)
53 inline String(
const char *_buf,
int _off,
int _len): buf(_buf), off(_off), len(_len) { lock(); };
54 static String concat(
const char *s1,
int l1,
const char *s2,
int l2);
56 : buf((char *)buffer), off(
offset), len(
length) { lock(); };
62 inline String(
void): buf((char *)&empty_buf), off(zero_off), len(0) { lock(); };
69 {
str.lock(); unlock(); buf =
str.buf; off =
str.off; len =
str.len;
return *
this; };
73 {
if(!
str)
str =
""; unlock(); copy(
str, strlen(
str));
return *
this; };
75 inline int length(
void)
const {
return len; };
76 inline const char *
chars(
void)
const {
return buf + off; };
79 return res ? res : len -
str.len;
83 int res = memcmp(
chars(),
str.
chars(), len > slen ? slen : len);
84 return res ? res : len - slen;
87 inline bool isEmpty(
void)
const {
return !len; };
94 inline char charAt(
int index)
const {
return buf[index + off]; };
104 {
for(
const char *
p =
chars() + pos;
p <
chars() + len;
p++)
if(*
p == chr)
return p -
chars();
return -1; };
108 {
for(
const char *
p =
chars() + pos - 1;
p >=
chars();
p--)
if(*
p == chr)
return p -
chars();
return -1; };
134 inline char item()
const {
return _s[_i]; }
136 inline bool equals(
const Iter& i)
const {
return _i == i._i; }
144 template <
class C>
inline String join(
const C& coll);
148 #ifndef ELM_NO_STRING_SHORTCUT
155 #endif // ELM_STRING_STRING_H
int lastIndexOf(char chr) const
Definition: String.h:106
static String make(char chr)
Definition: string_String.cpp:171
bool endsWith(const char *str) const
Definition: String.h:118
char operator[](int index) const
Definition: String.h:95
const char * chars(void) const
Definition: String.h:76
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
Iter(const String &s, int i=0)
Definition: String.h:132
Iter end() const
Definition: String.h:142
Definition: StringBuffer.h:18
String(const char *str)
Definition: String.h:64
bool startsWith(const CString str) const
Definition: String.h:114
char charAt(int index) const
Definition: String.h:94
Iter begin() const
Definition: String.h:141
int indexOf(char chr, int pos) const
Definition: String.h:103
int indexOf(char chr) const
Definition: String.h:102
bool atEnd() const
Definition: String.h:133
bool endsWith(const CString str) const
Definition: String.h:120
String(const String &str)
Definition: String.h:66
String replace(String pat, String sub)
Definition: string_String.cpp:565
bool endsWith(const String &str) const
Definition: String.h:122
String join(const C &coll)
Definition: string.h:106
String string
Definition: String.h:149
String(void)
Definition: String.h:62
int lastIndexOf(char chr, int pos) const
Definition: String.h:107
void next()
Definition: String.h:135
String concat(const String &str) const
Definition: String.h:100
int length(void) const
Definition: String.h:75
const char * chars(void) const
Definition: CString.h:27
String(cstring str)
Definition: String.h:65
String trim(void) const
Definition: string_String.cpp:533
String substring(int _off) const
Definition: String.h:96
int compare(const String &str) const
Definition: String.h:77
String rtrim(void) const
Definition: string_String.cpp:554
int lastIndexOf(const String &str)
Definition: String.h:109
bool equals(const Iter &i) const
Definition: String.h:136
const char * asSysString() const
Definition: String.h:92
String substring(int _off, int _len) const
Definition: String.h:97
bool startsWith(const String &str) const
Definition: String.h:116
char item() const
Definition: String.h:134
String & operator=(const String &str)
Definition: String.h:68
String ltrim(void) const
Definition: string_String.cpp:542
const char * asNullTerminated() const
Definition: String.h:91
bool startsWith(const char *str) const
Definition: String.h:112
string str(const char *s)
Definition: String.h:150
CString toCString(void) const
Definition: String.h:90
bool isEmpty(void) const
Definition: String.h:87
String(const char *str, int _len)
Definition: String.h:63
String & operator=(const CString str)
Definition: String.h:70
String & operator=(const char *str)
Definition: String.h:72
~String(void)
Definition: String.h:67
uint64 offset
Definition: arch.h:36
friend class CString
Definition: String.h:31
String concat(const CString str) const
Definition: String.h:99
int compare(const CString str) const
Definition: String.h:81