1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __userstring_hh
3 #define __userstring_hh
14 //! userstring is a std::string with an extra flag specifying if the string is
16 class userstring : public std::string
19 //! A vector of userstrings
20 typedef std::vector<userstring> vector;
26 userstring(bool utf8) : std::string(), _utf8(utf8) {}
27 userstring(const userstring& s, size_type pos = 0,
28 size_type n = npos) : std::string(s, pos, n), _utf8(s._utf8) {}
29 userstring(const char *s, bool utf8) : std::string(s), _utf8(utf8) {}
30 userstring(const char *s, size_type n, bool utf8) : std::string(s, n),
32 userstring(size_type n, char c, bool utf8) : std::string(n, c),
34 userstring(const_iterator first, const_iterator last, bool utf8) :
35 std::string(first, last), _utf8(utf8) {}
37 //! Returns if the string is encoded in UTF-8 or not
38 inline bool utf8() const { return _utf8; }
40 inline void setUtf8(bool u) { _utf8 = u; }
42 inline userstring& insert(size_type pos, const userstring& s) {
43 assert(s._utf8 == _utf8);
44 std::string::insert(pos, s);
48 inline userstring& insert(size_type pos,
50 size_type pos1, size_type n) {
51 assert(s._utf8 == _utf8);
52 std::string::insert(pos, s, pos1, n);
56 inline userstring& append(const userstring& s) {
57 assert(s._utf8 == _utf8);
58 std::string::append(s);
62 inline userstring& append(const userstring& s,
63 size_type pos, size_type n) {
64 assert(s._utf8 == _utf8);
65 std::string::append(s, pos, n);
69 inline userstring& assign(const userstring& s) {
70 assert(s._utf8 == _utf8);
71 std::string::assign(s);
75 inline userstring& assign(const userstring& s,
76 size_type pos, size_type n) {
77 assert(s._utf8 == _utf8);
78 std::string::assign(s, pos, n);
82 inline userstring& replace(size_type pos, size_type n,
83 const userstring& s) {
84 assert(s._utf8 == _utf8);
85 std::string::replace(pos, n, s);
89 inline userstring& replace(size_type pos, size_type n,
91 size_type pos1, size_type n1) {
92 assert(s._utf8 == _utf8);
93 std::string::replace(pos, n, s, pos1, n1);
97 inline userstring& operator=(const userstring& s) {
101 inline userstring& operator+=(const userstring& s) {
108 #endif // __userstring_hh