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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-06-20 15:59:51 UTC
  • mfrom: (1.4.8)
  • Revision ID: package-import@ubuntu.com-20120620155951-6rupmpb0f70b52zr
Tags: 2012.05.21-724730-0ubuntu1
* Merging upstream version 2012.05.21-724730.
  - Fixes building against the current Quantal kernel. (LP: #1000344)
  - Fixes Quantal installation issues. (LP: #1019031)

* Sync with Debian
  - Updating to debhelper version 9.
  - Updating to standards version 3.9.3.
  - Updating copyright file machine-readable format version 1.0.
  - Building without multiarch paths for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
 
98
98
#ifdef _WIN32
99
 
 
100
 
/*
101
 
 *-----------------------------------------------------------------------------
102
 
 *
103
 
 * utf::string::init_bstr_t --
104
 
 *
105
 
 *      Utility function to construct from a _bstr_t object.
106
 
 *      Copies the UTF-16 representation of the _bstr_t.
107
 
 *
108
 
 * Results:
109
 
 *      None.
110
 
 *
111
 
 * Side effects:
112
 
 *      Makes a copy of the _bstr_t data and frees that data when
113
 
 *      the utf::string is destroyed.
114
 
 *
115
 
 * Note:
116
 
 *      WIN32 only call
117
 
 *
118
 
 *-----------------------------------------------------------------------------
119
 
 */
120
 
 
121
 
void
122
 
string::init_bstr_t(const _bstr_t &s) // IN
123
 
{
124
 
   // If the input is empty, then there's nothing to do.
125
 
   if (s.length() == 0) {
126
 
      return;
127
 
   }
128
 
 
129
 
   Unicode utf8 = Unicode_AllocWithUTF16(static_cast<const utf16_t *>(s));
130
 
 
131
 
   try {
132
 
      mUstr = utf8;
133
 
      Unicode_Free(utf8);
134
 
   } catch (...) {
135
 
      Unicode_Free(utf8);
136
 
      throw;
137
 
   }
138
 
 
139
 
   ASSERT(Validate(mUstr));
140
 
}
141
 
 
142
 
 
143
99
/*
144
100
 *-----------------------------------------------------------------------------
145
101
 *
202
158
     mUtf16Cache(NULL),
203
159
     mUtf16Length(npos)
204
160
{
205
 
   init_bstr_t(s);
206
 
}
207
 
 
208
 
 
209
 
/*
210
 
 *-----------------------------------------------------------------------------
211
 
 *
212
 
 * utf::string::string --
213
 
 *
214
 
 *      Constructor from a uvariant_t object. Copies the UTF-16 representation
215
 
 *      of the ubstr_t interface.
216
 
 *
217
 
 * Results:
218
 
 *      None.
219
 
 *
220
 
 * Side effects:
221
 
 *      Makes a copy of the uvariant_t data and frees that data when the
222
 
 *      utf::string is destroyed.
223
 
 *
224
 
 * Note:
225
 
 *      WIN32 only call
226
 
 *
227
 
 *-----------------------------------------------------------------------------
228
 
 */
229
 
 
230
 
string::string(const uvariant_t &v) // IN
231
 
   : mUstr(),
232
 
     mUtf16Cache(NULL),
233
 
     mUtf16Length(npos)
234
 
{
235
 
   ubstr_t s;
236
 
 
237
 
   try {
238
 
      s = v;
239
 
   } catch (...) {
240
 
      Warning("Invalid uvariant_t to ubstr_t conversion.\n");
241
 
      throw;
242
 
   }
243
 
 
244
161
   // If the input is empty, then there's nothing to do.
245
162
   if (s.length() == 0) {
246
163
      return;
247
164
   }
248
165
 
249
 
   mUstr = static_cast<const char *>(s);
 
166
   Unicode utf8 = Unicode_AllocWithUTF16(static_cast<const utf16_t *>(s));
 
167
 
 
168
   try {
 
169
      mUstr = utf8;
 
170
      Unicode_Free(utf8);
 
171
   } catch (...) {
 
172
      Unicode_Free(utf8);
 
173
      throw;
 
174
   }
 
175
 
250
176
   ASSERT(Validate(mUstr));
251
177
}
252
 
 
253
 
 
254
 
/*
255
 
 *-----------------------------------------------------------------------------
256
 
 *
257
 
 * utf::string::string --
258
 
 *
259
 
 *      Constructor from a _variant_t object. Copies the UTF-16 representation
260
 
 *      of the _variant_t.
261
 
 *
262
 
 * Results:
263
 
 *      None.
264
 
 *
265
 
 * Side effects:
266
 
 *      Makes a copy of the _variant_t data and frees that data when
267
 
 *      the utf::string is destroyed.
268
 
 *
269
 
 * Note:
270
 
 *      WIN32 only call
271
 
 *
272
 
 *-----------------------------------------------------------------------------
273
 
 */
274
 
 
275
 
string::string(const _variant_t &v) // IN
276
 
   : mUstr(),
277
 
     mUtf16Cache(NULL),
278
 
     mUtf16Length(npos)
279
 
{
280
 
   _bstr_t s;
281
 
 
282
 
   try {
283
 
      s = v;
284
 
   } catch (...) {
285
 
      Warning("Invalid _variant_t to _bstr_t conversion.\n");
286
 
      throw;
287
 
   }
288
 
 
289
 
   init_bstr_t(s);
290
 
}
291
 
 
292
178
#endif
293
179
 
294
180
 
1864
1750
 *
1865
1751
 *      Return a vector of utf::strings.  The vector contains the elements of
1866
1752
 *      the string split by the passed in separator. Empty tokens are not
1867
 
 *      skipped.
 
1753
 *      skipped. If maxStrings is zero, any number of strings will be returned,
 
1754
 *      otherwise parsing stops after maxStrings - 1 matches of the separator.
 
1755
 *      In that case, the last string returned includes the rest of the
 
1756
 *      original string.
1868
1757
 *
1869
1758
 *      "1,2,3".split(",") -> ["1", "2", "3"]
1870
1759
 *      "1,,".split(",") -> ["1", "", ""]
1871
1760
 *      "1".split(",") -> ["1"]
 
1761
 *      "1,2,3".split(",", 2) -> ["1", "2,3"]
1872
1762
 *
1873
1763
 *      XXX If this is to be used for things like command line parsing, support
1874
1764
 *      for quoted strings needs to be added.
1883
1773
 */
1884
1774
 
1885
1775
std::vector<string>
1886
 
string::split(const string &sep) // IN
 
1776
string::split(const string &sep, // IN
 
1777
              size_t maxStrings) // IN/OPT
1887
1778
   const
1888
1779
{
1889
1780
   std::vector<string> splitStrings;
1890
1781
   size_type sIndex = 0;
1891
1782
   size_type sepLen = sep.length();
 
1783
   size_t count = 0;
1892
1784
 
1893
1785
   ASSERT(sepLen > 0);
1894
1786
 
1895
1787
   while (true) {
1896
1788
      size_type index = find(sep, sIndex);
1897
 
      if (index == npos) {
 
1789
      count++;
 
1790
      if (count == maxStrings || index == npos) {
1898
1791
         splitStrings.push_back(substr(sIndex));
1899
1792
         break;
1900
1793
      }