]> Dogcows Code - chaz/openbox/blob - otk/userstring.hh
use "userstring" for all user viewable strings
[chaz/openbox] / otk / userstring.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __userstring_hh
3 #define __userstring_hh
4
5 #include <string>
6 #include <vector>
7
8 extern "C" {
9 #include <assert.h>
10 }
11
12 //! userstring is a std::string with an extra flag specifying if the string is
13 //! UTF-8 encoded.
14 class userstring : public std::string
15 {
16 public:
17 //! A vector of userstrings
18 typedef std::vector<userstring> vector;
19
20 private:
21 bool _utf8;
22
23 public:
24 userstring(bool utf8) : std::string(), _utf8(utf8) {}
25 userstring(const userstring& s, size_type pos = 0,
26 size_type n = npos) : std::string(s, pos, n), _utf8(s._utf8) {}
27 userstring(const char *s, bool utf8) : std::string(s), _utf8(utf8) {}
28 userstring(const char *s, size_type n, bool utf8) : std::string(s, n),
29 _utf8(utf8) {}
30 userstring(size_type n, char c, bool utf8) : std::string(n, c),
31 _utf8(utf8) {}
32 userstring(const_iterator first, const_iterator last, bool utf8) :
33 std::string(first, last), _utf8(utf8) {}
34
35 //! Returns if the string is encoded in UTF-8 or not
36 inline bool utf8() const { return _utf8; }
37
38 inline void setUtf8(bool u) { _utf8 = u; }
39
40 inline userstring& insert(size_type pos, const userstring& s) {
41 assert(s._utf8 == _utf8);
42 std::string::insert(pos, s);
43 return *this;
44 }
45
46 inline userstring& insert(size_type pos,
47 const userstring& s,
48 size_type pos1, size_type n) {
49 assert(s._utf8 == _utf8);
50 std::string::insert(pos, s, pos1, n);
51 return *this;
52 }
53
54 inline userstring& append(const userstring& s) {
55 assert(s._utf8 == _utf8);
56 std::string::append(s);
57 return *this;
58 }
59
60 inline userstring& append(const userstring& s,
61 size_type pos, size_type n) {
62 assert(s._utf8 == _utf8);
63 std::string::append(s, pos, n);
64 return *this;
65 }
66
67 inline userstring& assign(const userstring& s) {
68 assert(s._utf8 == _utf8);
69 std::string::assign(s);
70 return *this;
71 }
72
73 inline userstring& assign(const userstring& s,
74 size_type pos, size_type n) {
75 assert(s._utf8 == _utf8);
76 std::string::assign(s, pos, n);
77 return *this;
78 }
79
80 inline userstring& replace(size_type pos, size_type n,
81 const userstring& s) {
82 assert(s._utf8 == _utf8);
83 std::string::replace(pos, n, s);
84 return *this;
85 }
86
87 inline userstring& replace(size_type pos, size_type n,
88 const userstring& s,
89 size_type pos1, size_type n1) {
90 assert(s._utf8 == _utf8);
91 std::string::replace(pos, n, s, pos1, n1);
92 return *this;
93 }
94
95 inline userstring& operator=(const userstring& s) {
96 return assign(s);
97 }
98
99 inline userstring& operator+=(const userstring& s) {
100 return append(s);
101 }
102 };
103
104 #endif // __userstring_hh
This page took 0.03663 seconds and 4 git commands to generate.