~ubuntu-branches/ubuntu/precise/open-vm-tools/precise

« back to all changes in this revision

Viewing changes to services/plugins/dndcp/stringxx/string.hh

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2008 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation version 2.1 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 
11
 * License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/*
 
20
 * string.hh --
 
21
 *
 
22
 *     A string wrapper for bora/lib/unicode. This class is intended to provide
 
23
 *     more c++ features such as operator overloading, automatic string conversion
 
24
 *     between different types of string classes.
 
25
 *
 
26
 *     This class uses glib::ustring as the underlying storage for its data,
 
27
 *     we chose this object because of its internal support for unicode.
 
28
 *
 
29
 */
 
30
 
 
31
#ifndef UTF_STRING_HH
 
32
#define UTF_STRING_HH
 
33
 
 
34
#include <string>
 
35
#include <vector>
 
36
#include <algorithm>
 
37
 
 
38
#ifdef _WIN32
 
39
#pragma pack(push, 8)
 
40
#endif // _WIN32
 
41
 
 
42
#include <glibmm/ustring.h>
 
43
 
 
44
#ifdef _WIN32
 
45
#pragma pack(pop)
 
46
#endif // _WIN32
 
47
 
 
48
#ifdef _WIN32
 
49
#include "ubstr_t.hh"
 
50
#endif
 
51
 
 
52
#include "libExport.hh"
 
53
extern "C" {
 
54
#include "unicodeTypes.h"
 
55
}
 
56
 
 
57
#ifdef _WIN32
 
58
/*
 
59
 * Disabling Windows warning 4251
 
60
 *    This is a warning msg about requiring Glib::ustring to be DLL
 
61
 *    exportable.
 
62
 */
 
63
#pragma warning(push)
 
64
#pragma warning(disable:4251)
 
65
#endif
 
66
 
 
67
namespace utf {
 
68
 
 
69
 
 
70
/* utf8string should be replaced with an opaque type. It is temporarily used
 
71
 * to replace the std::string in our codebase.
 
72
 */
 
73
typedef std::string utf8string;
 
74
typedef std::basic_string<utf16_t> utf16string;
 
75
 
 
76
class VMSTRING_EXPORT string
 
77
{
 
78
public:
 
79
   // type definitions
 
80
   typedef Glib::ustring::size_type size_type;
 
81
   typedef Glib::ustring::value_type value_type;
 
82
   typedef Glib::ustring::iterator iterator;
 
83
   typedef Glib::ustring::const_iterator const_iterator;
 
84
 
 
85
   // constant definitions
 
86
   static const size_type npos;
 
87
 
 
88
   // Normalize mode map to Glib::NormalizeMode
 
89
   typedef enum {
 
90
      NORMALIZE_DEFAULT          = Glib::NORMALIZE_DEFAULT,
 
91
      NORMALIZE_NFD              = Glib::NORMALIZE_NFD,
 
92
      NORMALIZE_DEFAULT_COMPOSE  = Glib::NORMALIZE_DEFAULT_COMPOSE,
 
93
      NORMALIZE_NFC              = Glib::NORMALIZE_NFC,
 
94
      NORMALIZE_ALL              = Glib::NORMALIZE_ALL,
 
95
      NORMALIZE_NFKD             = Glib::NORMALIZE_NFKD,
 
96
      NORMALIZE_ALL_COMPOSE      = Glib::NORMALIZE_ALL_COMPOSE,
 
97
      NORMALIZE_NFKC             = Glib::NORMALIZE_NFKC
 
98
   } NormalizeMode;
 
99
 
 
100
   string();
 
101
   string(ConstUnicode s);
 
102
 
 
103
#ifdef _WIN32
 
104
   string(const ubstr_t &s);
 
105
   explicit string(const _bstr_t &s);
 
106
   string(const uvariant_t &v);
 
107
   explicit string(const _variant_t &v);
 
108
#endif
 
109
 
 
110
   string(const utf16string &s);
 
111
   string(const utf16_t *s);
 
112
   string(const char *s, StringEncoding encoding);
 
113
   string(const Glib::ustring &s);
 
114
   string(const string &s);
 
115
 
 
116
   ~string();
 
117
 
 
118
   // Implicit conversions
 
119
   operator const Glib::ustring& () const;
 
120
#ifdef _WIN32
 
121
   operator const ubstr_t() const;
 
122
#endif
 
123
 
 
124
   // Conversions to other i18n types (utf8, utf16, unicode)
 
125
   const char *c_str() const;
 
126
   const utf16_t *w_str() const;
 
127
   const Glib::ustring& ustr() const;
 
128
 
 
129
   // Mapping functions to Glib::ustring
 
130
   void swap(string &s);
 
131
   void resize(size_type n, value_type c = '\0');
 
132
   bool empty() const;
 
133
   size_type size() const;
 
134
   size_type w_size() const;
 
135
   size_type length() const;
 
136
   size_type bytes() const;
 
137
   string foldCase() const;
 
138
   string trim() const;
 
139
   string trimLeft() const;
 
140
   string trimRight() const;
 
141
   string normalize(NormalizeMode mode = NORMALIZE_DEFAULT_COMPOSE) const;
 
142
 
 
143
   string toLower(const char *locale) const;
 
144
   string toUpper(const char *locale) const;
 
145
#ifdef USE_ICU
 
146
   string toTitle(const char *locale) const;
 
147
#endif
 
148
 
 
149
   // String-level member methods.
 
150
   string& append(const string &s);
 
151
   string& append(const string &s, size_type i, size_type n);
 
152
   string& append(const char *s, size_type n);
 
153
   string& assign(const string &s);
 
154
   void push_back(value_type uc);
 
155
   void clear();
 
156
   void zero_clear();
 
157
   string& insert(size_type i, const string& s);
 
158
   string& insert(size_type i, size_type n, value_type uc);
 
159
   string& erase(size_type i, size_type n = npos);
 
160
   iterator erase(iterator p);
 
161
   iterator erase(iterator pbegin, iterator pend);
 
162
   string& replace(size_type i, size_type n, const string& s);
 
163
   string& replace(const string &from, const string &to);
 
164
   string replace_copy(const string& from, const string& to) const;
 
165
 
 
166
   int compare(const string &s, bool ignoreCase = false) const;
 
167
   int compare(size_type i, size_type n, const string &s) const;
 
168
   int compareLength(const string &s, size_type len, bool ignoreCase = false) const;
 
169
   int compareRange(size_type thisStart, size_type thisLength, const string &str,
 
170
                    size_type strStart, size_type strLength,
 
171
                    bool ignoreCase = false) const;
 
172
   size_type find(const string &s, size_type pos = 0) const;
 
173
   size_type rfind(const string &s, size_type pos = npos) const;
 
174
   size_type find_first_of(const string &s, size_type i = 0) const;
 
175
   size_type find_first_not_of(const string &s, size_type i = 0) const;
 
176
   size_type find_last_of(const string &s, size_type i = npos) const;
 
177
   size_type find_last_not_of(const string &s, size_type i = npos) const;
 
178
   string substr(size_type start = 0, size_type len = npos) const;
 
179
 
 
180
   // Character-level member methods.
 
181
   value_type operator[](size_type i) const;
 
182
   size_type find(value_type uc, size_type pos = 0) const;
 
183
   size_type rfind(value_type uc, size_type pos = npos) const;
 
184
   size_type find_first_of(value_type uc, size_type i = 0) const;
 
185
   size_type find_first_not_of(value_type uc, size_type i = 0) const;
 
186
   size_type find_last_of(value_type uc, size_type i = npos) const;
 
187
   size_type find_last_not_of(value_type uc, size_type i = npos) const;
 
188
 
 
189
   // Sequence accessor.
 
190
   iterator begin();
 
191
   iterator end();
 
192
   const_iterator begin() const;
 
193
   const_iterator end() const;
 
194
 
 
195
   // Operator overloads
 
196
   string& operator=(string copy);
 
197
   string& operator+=(const string &s);
 
198
   string& operator+=(value_type uc);
 
199
 
 
200
   // Some helper functions that are nice to have
 
201
   bool startsWith(const string &s, bool ignoreCase = false) const;
 
202
   bool endsWith(const string &s, bool ignoreCase = false) const;
 
203
   std::vector<string> split(const string &sep) const;
 
204
 
 
205
   // Overloaded operators
 
206
   string operator+(const string &rhs) const;
 
207
   string operator+(value_type uc) const;
 
208
   bool operator==(const string &rhs) const;
 
209
   bool operator!=(const string &rhs) const;
 
210
   bool operator<(const string &rhs) const;
 
211
   bool operator>(const string &rhs) const;
 
212
   bool operator<=(const string &rhs) const;
 
213
   bool operator>=(const string &rhs) const;
 
214
 
 
215
private:
 
216
   // Cache operations
 
217
   void InvalidateCache();
 
218
 
 
219
   // Cache accessors
 
220
   const utf16_t *GetUtf16Cache() const;
 
221
 
 
222
#ifdef _WIN32
 
223
   // Private utility constructor.
 
224
   void init_bstr_t(const _bstr_t &s);
 
225
#endif
 
226
 
 
227
   // utf::string is internally backed by Glib::ustring.
 
228
   Glib::ustring mUstr;
 
229
 
 
230
   // Cached representations.
 
231
   mutable utf16_t *mUtf16Cache;
 
232
   mutable size_type mUtf16Length;
 
233
 
 
234
   /*
 
235
    * All added members need to be initialized in all constructors and need
 
236
    * to be handled in swap().
 
237
    */
 
238
};
 
239
 
 
240
// Helper operators
 
241
 
 
242
string inline
 
243
operator+(ConstUnicode lhs, const string &rhs) {
 
244
   return string(lhs) + rhs;
 
245
}
 
246
 
 
247
string inline
 
248
operator+(const string& lhs, ConstUnicode rhs) {
 
249
   return lhs + string(rhs);
 
250
}
 
251
 
 
252
bool inline
 
253
operator==(ConstUnicode lhs, const string &rhs) {
 
254
   return string(lhs) == rhs;
 
255
}
 
256
 
 
257
bool inline
 
258
operator!=(ConstUnicode lhs, const string &rhs) {
 
259
   return string(lhs) != rhs;
 
260
}
 
261
 
 
262
bool inline
 
263
operator<(ConstUnicode lhs, const string &rhs) {
 
264
   return string(lhs) < rhs;
 
265
}
 
266
 
 
267
bool inline
 
268
operator>(ConstUnicode lhs, const string &rhs) {
 
269
   return string(lhs) > rhs;
 
270
}
 
271
 
 
272
bool inline
 
273
operator<=(ConstUnicode lhs, const string &rhs) {
 
274
   return string(lhs) <= rhs;
 
275
}
 
276
 
 
277
bool inline
 
278
operator>=(ConstUnicode lhs, const string &rhs) {
 
279
   return string(lhs) >= rhs;
 
280
}
 
281
 
 
282
// This lets a utf::string appear on the right side of a stream insertion operator.
 
283
inline std::ostream&
 
284
operator<<(std::ostream& strm, const string& s)
 
285
{
 
286
   strm << s.c_str();
 
287
   return strm;
 
288
}
 
289
 
 
290
// ConversionError class for exception
 
291
 
 
292
class ConversionError {};
 
293
 
 
294
 
 
295
// Helper functions
 
296
 
 
297
bool VMSTRING_EXPORT Validate(const Glib::ustring& s);
 
298
 
 
299
string VMSTRING_EXPORT
 
300
CreateWithLength(const void *buffer, ssize_t lengthInBytes, StringEncoding encoding);
 
301
 
 
302
string VMSTRING_EXPORT
 
303
CreateWithBOMBuffer(const void *buffer, ssize_t lengthInBytes);
 
304
 
 
305
string VMSTRING_EXPORT
 
306
IntToStr(int64 val);
 
307
 
 
308
void VMSTRING_EXPORT CreateWritableBuffer(const string& s,
 
309
                                          std::vector<char>& buf);
 
310
void VMSTRING_EXPORT CreateWritableBuffer(const string& s,
 
311
                                          std::vector<utf16_t>& buf);
 
312
 
 
313
 
 
314
} // namespace utf
 
315
 
 
316
 
 
317
 
 
318
// Template specializations for utf::string.
 
319
namespace std {
 
320
 
 
321
template<>
 
322
inline void
 
323
swap<utf::string>(utf::string& s1, // IN/OUT
 
324
                  utf::string& s2) // IN/OUT
 
325
{
 
326
   s1.swap(s2);
 
327
}
 
328
 
 
329
} // namespace std
 
330
 
 
331
 
 
332
#ifdef _WIN32
 
333
#pragma warning(pop)
 
334
#endif
 
335
 
 
336
#endif