]> Dogcows Code - chaz/openbox/blob - otk/userstring.hh
check for shutdown before waiting for timers
[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 namespace otk {
13
14 //! userstring is a std::string with an extra flag specifying if the string is
15 //! UTF-8 encoded.
16 class userstring : public std::string
17 {
18 public:
19 //! A vector of userstrings
20 typedef std::vector<userstring> vector;
21
22 private:
23 bool _utf8;
24
25 public:
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),
31 _utf8(utf8) {}
32 userstring(size_type n, char c, bool utf8) : std::string(n, c),
33 _utf8(utf8) {}
34 userstring(const_iterator first, const_iterator last, bool utf8) :
35 std::string(first, last), _utf8(utf8) {}
36
37 //! Returns if the string is encoded in UTF-8 or not
38 inline bool utf8() const { return _utf8; }
39
40 inline void setUtf8(bool u) { _utf8 = u; }
41
42 inline userstring& insert(size_type pos, const userstring& s) {
43 assert(s._utf8 == _utf8);
44 std::string::insert(pos, s);
45 return *this;
46 }
47
48 inline userstring& insert(size_type pos,
49 const userstring& s,
50 size_type pos1, size_type n) {
51 assert(s._utf8 == _utf8);
52 std::string::insert(pos, s, pos1, n);
53 return *this;
54 }
55
56 inline userstring& append(const userstring& s) {
57 assert(s._utf8 == _utf8);
58 std::string::append(s);
59 return *this;
60 }
61
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);
66 return *this;
67 }
68
69 inline userstring& assign(const userstring& s) {
70 assert(s._utf8 == _utf8);
71 std::string::assign(s);
72 return *this;
73 }
74
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);
79 return *this;
80 }
81
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);
86 return *this;
87 }
88
89 inline userstring& replace(size_type pos, size_type n,
90 const userstring& s,
91 size_type pos1, size_type n1) {
92 assert(s._utf8 == _utf8);
93 std::string::replace(pos, n, s, pos1, n1);
94 return *this;
95 }
96
97 inline userstring& operator=(const userstring& s) {
98 return assign(s);
99 }
100
101 inline userstring& operator+=(const userstring& s) {
102 return append(s);
103 }
104 };
105
106 }
107
108 #endif // __userstring_hh
This page took 0.039828 seconds and 4 git commands to generate.