23 class String :
public std::basic_string<Char>
25 typedef std::basic_string<Char> Super;
29 typedef vector<String>
List;
31 using Super::basic_string;
34 String(
const std::basic_string<Char>& str) : Super(str) {}
36 String(std::basic_string<Char>&& str) : Super(move(str)) {}
38 String(
const std::string& str) : Super(str.begin(), str.end()) {}
40 String(
const ostream& os) :
String(static_cast<const ostringstream&>(os).str()) {}
65 template<
class InputIterator>
66 String&
append(InputIterator first, InputIterator last) {
insert(begin() + length(), first, last);
return *
this; }
77 template<
class InputIterator>
78 String&
assign(InputIterator first, InputIterator last) {
clear();
return append<InputIterator>(first, last); }
87 iterator
insert(const_iterator p, Char c) {
return Super::insert(p, c); }
88 iterator
insert(const_iterator p,
szt n, Char c) {
return Super::insert(p, n, c); }
89 template<
class InputIterator>
90 iterator
insert(const_iterator p, InputIterator first, InputIterator last) {
return Super::insert(p, first, last); }
94 iterator
erase(const_iterator first, const_iterator last) {
return Super::erase(first, last); }
97 String&
replace(const_iterator i1, const_iterator i2,
const String& str) { Super::replace(i1, i2, str);
return *
this; }
98 template<
class InputIterator>
99 String&
replace(const_iterator i1, const_iterator i2, InputIterator first, InputIterator last) { Super::replace(i1, i2, first, last);
return *
this; }
101 szt copy(Char* s,
szt len,
szt pos = 0)
const {
return Super::copy(s, len, pos); }
102 szt copy(
char* s,
szt len,
szt pos = 0)
const { std::string str(begin() + pos, begin() + pos + len);
return str.copy(s, str.length()); }
121 std::string
u8()
const {
return std::string(begin(), end()); }
124 operator std::string()
const {
return u8(); }
127 friend istream&
operator>>(istream& is,
String& str) { std::string str_; is >> str_; str = str_;
return is; }
146 inline bool operator< (
const String& lhs,
const Char* rhs) {
return lhs.compare(rhs) < 0; }
147 inline bool operator< (
const Char* lhs,
const String& rhs) {
return rhs.compare(lhs) > 0; }
149 inline bool operator> (
const String& lhs,
const Char* rhs) {
return lhs.compare(rhs) > 0; }
150 inline bool operator> (
const Char* lhs,
const String& rhs) {
return rhs.compare(lhs) < 0; }
152 inline bool operator<=(
const String& lhs,
const Char* rhs) {
return lhs.compare(rhs) <= 0; }
153 inline bool operator<=(
const Char* lhs,
const String& rhs) {
return rhs.compare(lhs) >= 0; }
155 inline bool operator>=(
const String& lhs,
const Char* rhs) {
return lhs.compare(rhs) >= 0; }
156 inline bool operator>=(
const Char* lhs,
const String& rhs) {
return rhs.compare(lhs) <= 0; }
159 inline const Char*
c_str(
const Char* str) {
return str ? str : u
""; }
160 inline const char*
c_str(
const char* str) {
return str ? str :
""; }
173 inline ostream&
operator<<(ostream& os,
const honey::Char* str) {
assert(str);
return os << std::string(str, str + std::char_traits<honey::Char>::length(str)); }
int icompare(const String &str) const
Case-insensitive compare.
Definition: String.h:107
String & append(const String &str, szt subpos=0, szt sublen=npos)
Definition: String.h:59
String & assign(const String &str, szt subpos=0, szt sublen=npos)
Definition: String.h:71
ostream & operator<<(ostream &os, const honey::Char val)
Definition: String.h:174
String & append(szt n, char c)
Definition: String.h:64
String(const char *str, szt len=npos)
Convert from UTF-8 string, pointer must not be null.
Definition: String.h:42
String & insert(szt pos, szt n, char c)
Definition: String.h:86
String & append(const Char *str, szt subpos=0, szt sublen=npos)
Definition: String.h:61
bool operator>(const String &lhs, const String &rhs)
Definition: String.h:148
String & assign(InputIterator first, InputIterator last)
Definition: String.h:78
iterator erase(const_iterator first, const_iterator last)
Definition: String.h:94
bool operator!=(const String &lhs, const String &rhs)
Definition: String.h:142
String & append(const char *str, szt subpos=0, szt sublen=npos)
Definition: String.h:62
List::reverse_iterator erase(List &list, const typename List::reverse_iterator &iter)
Erase using reverse iterator. Returns reverse iterator to element after erased element.
Definition: StdUtil.h:45
String(const ostream &os)
Convert from UTF-8 stringstream.
Definition: String.h:40
String & insert(szt pos, const String &str, szt subpos=0, szt sublen=npos)
Definition: String.cpp:9
String toUpper() const
Convert string to upper case.
Definition: String.cpp:77
const Char * c_str(const Char *str)
Ensures that str points to a valid C-string. If str is null then the result is an empty C-string (ie...
Definition: String.h:159
iterator insert(const_iterator p, InputIterator first, InputIterator last)
Definition: String.h:90
String toLower() const
Convert string to lower case.
Definition: String.cpp:70
String & assign(const Char *str, szt subpos=0, szt sublen=npos)
Definition: String.h:73
iterator erase(const_iterator position)
Definition: String.h:93
String substr(szt pos=0, szt len=npos) const
Definition: String.h:104
String & assign(const char *str, szt subpos=0, szt sublen=npos)
Definition: String.h:74
String & insert(szt pos, szt n, Char c)
Definition: String.h:85
String & replace(const_iterator i1, const_iterator i2, InputIterator first, InputIterator last)
Definition: String.h:99
vector< String > List
List of strings.
Definition: String.h:29
friend istream & operator>>(istream &is, String &str)
Definition: String.h:127
bool operator<(const String &lhs, const String &rhs)
Definition: String.h:145
List split(const String &delim=String(1, ' '), szt pos=0, szt count=npos) const
Split a string into a list of separate substrings delimited by delim.
Definition: String.cpp:140
String(std::basic_string< Char > &&str)
Move UTF-16 string.
Definition: String.h:36
char16_t Char
Represents a single code unit (not code point) for class String.
Definition: String.h:13
String & operator+=(T &&rhs)
Forwards to append()
Definition: String.h:51
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
std::string u8() const
Convert to UTF-8 string.
Definition: String.h:121
String & erase(szt pos=0, szt len=npos)
Definition: String.h:92
String & operator=(T &&rhs)
Forwards to assign()
Definition: String.h:48
String operator+(const String &lhs, const String &rhs)
Definition: String.h:132
Unicode UTF-16 string class, wrapper around std::u16string.
Definition: String.h:23
String & assign(const std::string &str, szt subpos=0, szt sublen=npos)
Definition: String.h:72
String & operator+=(Char rhs)
Definition: String.h:52
String(szt n, char c)
Convert from UTF-8 char repeated n times.
Definition: String.h:44
iterator insert(const_iterator p, Char c)
Definition: String.h:87
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
friend ostream & operator<<(ostream &os, const String &str)
Definition: String.h:126
String & append(szt n, Char c)
Definition: String.h:63
iterator insert(const_iterator p, szt n, Char c)
Definition: String.h:88
String & append(InputIterator first, InputIterator last)
Definition: String.h:66
bool operator<=(const String &lhs, const String &rhs)
Definition: String.h:151
szt copy(char *s, szt len, szt pos=0) const
Definition: String.h:102
String & assign(szt n, char c)
Definition: String.h:76
String & assign(szt n, Char c)
Definition: String.h:75
String & replace(const_iterator i1, const_iterator i2, const String &str)
Definition: String.h:97
String(const std::string &str)
Convert from UTF-8 string.
Definition: String.h:38
bool operator==(const String &lhs, const String &rhs)
Definition: String.h:139
String & operator+=(char rhs)
Definition: String.h:53
szt copy(Char *s, szt len, szt pos=0) const
Definition: String.h:101
bool operator>=(const String &lhs, const String &rhs)
Definition: String.h:154
static String join(const List &strings, const String &delim=String(1, ' '), szt start=npos, szt end=npos)
Join list into one string, separated by delim.
Definition: String.cpp:176
Global Honeycomb namespace.
String & append(const std::string &str, szt subpos=0, szt sublen=npos)
Definition: String.h:60
String & replace(szt pos, szt len, const String &str, szt subpos=0, szt sublen=npos)
Definition: String.cpp:39
String(const std::basic_string< Char > &str)
Copy UTF-16 string.
Definition: String.h:34
String & clear()
Definition: String.h:55