~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to vmware-user/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
 
#ifdef SUPPORT_UNICODE
144
 
   string toLower(const char *locale) const;
145
 
   string toUpper(const char *locale) const;
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& assign(const string &s);
153
 
   void push_back(value_type uc);
154
 
   void clear();
155
 
   void zero_clear();
156
 
   string& insert(size_type i, const string& s);
157
 
   string& insert(size_type i, size_type n, value_type uc);
158
 
   string& erase(size_type i, size_type n = npos);
159
 
   iterator erase(iterator p);
160
 
   iterator erase(iterator pbegin, iterator pend);
161
 
   string& replace(size_type i, size_type n, const string& s);
162
 
   string& replace(const string &from, const string &to);
163
 
   string replace_copy(const string& from, const string& to) const;
164
 
 
165
 
   int compare(const string &s, bool ignoreCase = false) const;
166
 
   int compare(size_type i, size_type n, const string &s) const;
167
 
   int compareLength(const string &s, size_type len, bool ignoreCase = false) const;
168
 
   int compareRange(size_type thisStart, size_type thisLength, const string &str,
169
 
                    size_type strStart, size_type strLength,
170
 
                    bool ignoreCase = false) const;
171
 
   size_type find(const string &s, size_type pos = 0) const;
172
 
   size_type rfind(const string &s, size_type pos = npos) const;
173
 
   size_type find_first_of(const string &s, size_type i = 0) const;
174
 
   size_type find_first_not_of(const string &s, size_type i = 0) const;
175
 
   size_type find_last_of(const string &s, size_type i = npos) const;
176
 
   size_type find_last_not_of(const string &s, size_type i = npos) const;
177
 
   string substr(size_type start = 0, size_type len = npos) const;
178
 
 
179
 
   // Character-level member methods.
180
 
   value_type operator[](size_type i) const;
181
 
   size_type find(value_type uc, size_type pos = 0) const;
182
 
   size_type rfind(value_type uc, size_type pos = npos) const;
183
 
   size_type find_first_of(value_type uc, size_type i = 0) const;
184
 
   size_type find_first_not_of(value_type uc, size_type i = 0) const;
185
 
   size_type find_last_of(value_type uc, size_type i = npos) const;
186
 
   size_type find_last_not_of(value_type uc, size_type i = npos) const;
187
 
 
188
 
   // Sequence accessor.
189
 
   iterator begin();
190
 
   iterator end();
191
 
   const_iterator begin() const;
192
 
   const_iterator end() const;
193
 
 
194
 
   // Operator overloads
195
 
   string& operator=(string copy);
196
 
   string& operator+=(const string &s);
197
 
   string& operator+=(value_type uc);
198
 
 
199
 
   // Some helper functions that are nice to have
200
 
   bool startsWith(const string &s, bool ignoreCase = false) const;
201
 
   bool endsWith(const string &s, bool ignoreCase = false) const;
202
 
   std::vector<string> split(const string &sep) const;
203
 
 
204
 
   // Overloaded operators
205
 
   string operator+(const string &rhs) const;
206
 
   string operator+(value_type uc) const;
207
 
   bool operator==(const string &rhs) 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
 
 
214
 
private:
215
 
   // Cache operations
216
 
   void InvalidateCache();
217
 
 
218
 
   // Cache accessors
219
 
   const utf16_t *GetUtf16Cache() const;
220
 
 
221
 
#ifdef _WIN32
222
 
   // Private utility constructor.
223
 
   void init_bstr_t(const _bstr_t &s);
224
 
#endif
225
 
 
226
 
   // utf::string is internally backed by Glib::ustring.
227
 
   Glib::ustring mUstr;
228
 
 
229
 
   // Cached representations.
230
 
   mutable utf16_t *mUtf16Cache;
231
 
   mutable size_type mUtf16Length;
232
 
 
233
 
   /*
234
 
    * All added members need to be initialized in all constructors and need
235
 
    * to be handled in swap().
236
 
    */
237
 
};
238
 
 
239
 
// Helper operators
240
 
 
241
 
string inline
242
 
operator+(ConstUnicode lhs, const string &rhs) {
243
 
   return string(lhs) + rhs;
244
 
}
245
 
 
246
 
string inline
247
 
operator+(const string& lhs, ConstUnicode rhs) {
248
 
   return lhs + string(rhs);
249
 
}
250
 
 
251
 
bool inline
252
 
operator==(ConstUnicode lhs, const string &rhs) {
253
 
   return string(lhs) == rhs;
254
 
}
255
 
 
256
 
bool inline
257
 
operator!=(ConstUnicode lhs, const string &rhs) {
258
 
   return string(lhs) != rhs;
259
 
}
260
 
 
261
 
bool inline
262
 
operator<(ConstUnicode lhs, const string &rhs) {
263
 
   return string(lhs) < rhs;
264
 
}
265
 
 
266
 
bool inline
267
 
operator>(ConstUnicode lhs, const string &rhs) {
268
 
   return string(lhs) > rhs;
269
 
}
270
 
 
271
 
bool inline
272
 
operator<=(ConstUnicode lhs, const string &rhs) {
273
 
   return string(lhs) <= rhs;
274
 
}
275
 
 
276
 
bool inline
277
 
operator>=(ConstUnicode lhs, const string &rhs) {
278
 
   return string(lhs) >= rhs;
279
 
}
280
 
 
281
 
 
282
 
// ConversionError class for exception
283
 
 
284
 
class ConversionError {};
285
 
 
286
 
 
287
 
// Helper functions
288
 
 
289
 
bool VMSTRING_EXPORT Validate(const Glib::ustring& s);
290
 
 
291
 
string VMSTRING_EXPORT
292
 
CreateWithLength(const void *buffer, ssize_t lengthInBytes, StringEncoding encoding);
293
 
 
294
 
string VMSTRING_EXPORT
295
 
CreateWithBOMBuffer(const void *buffer, ssize_t lengthInBytes);
296
 
 
297
 
string VMSTRING_EXPORT
298
 
IntToStr(int64 val);
299
 
 
300
 
void VMSTRING_EXPORT CreateWritableBuffer(const string& s,
301
 
                                          std::vector<char>& buf);
302
 
void VMSTRING_EXPORT CreateWritableBuffer(const string& s,
303
 
                                          std::vector<utf16_t>& buf);
304
 
 
305
 
 
306
 
} // namespace utf
307
 
 
308
 
 
309
 
 
310
 
// Template specializations for utf::string.
311
 
namespace std {
312
 
 
313
 
template<>
314
 
inline void
315
 
swap<utf::string>(utf::string& s1, // IN/OUT
316
 
                  utf::string& s2) // IN/OUT
317
 
{
318
 
   s1.swap(s2);
319
 
}
320
 
 
321
 
} // namespace std
322
 
 
323
 
 
324
 
#ifdef _WIN32
325
 
#pragma warning(pop)
326
 
#endif
327
 
 
328
 
#endif