| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
#ifndef ___VBox_com_string_h |
|---|
| 34 |
#define ___VBox_com_string_h |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
#ifndef __STDC_LIMIT_MACROS |
|---|
| 38 |
# define __STDC_LIMIT_MACROS |
|---|
| 39 |
#endif |
|---|
| 40 |
#ifndef __STDC_CONSTANT_MACROS |
|---|
| 41 |
# define __STDC_CONSTANT_MACROS |
|---|
| 42 |
#endif |
|---|
| 43 |
|
|---|
| 44 |
#if defined (VBOX_WITH_XPCOM) |
|---|
| 45 |
# include <nsMemory.h> |
|---|
| 46 |
#endif |
|---|
| 47 |
|
|---|
| 48 |
#include "VBox/com/defs.h" |
|---|
| 49 |
#include "VBox/com/assert.h" |
|---|
| 50 |
|
|---|
| 51 |
#include <iprt/string.h> |
|---|
| 52 |
#include <iprt/cpputils.h> |
|---|
| 53 |
#include <iprt/alloc.h> |
|---|
| 54 |
|
|---|
| 55 |
namespace com |
|---|
| 56 |
{ |
|---|
| 57 |
|
|---|
| 58 |
class Utf8Str; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
class Bstr |
|---|
| 74 |
{ |
|---|
| 75 |
public: |
|---|
| 76 |
|
|---|
| 77 |
typedef BSTR String; |
|---|
| 78 |
typedef CBSTR ConstString; |
|---|
| 79 |
|
|---|
| 80 |
Bstr () : bstr (NULL) {} |
|---|
| 81 |
|
|---|
| 82 |
Bstr (const Bstr &that) : bstr (NULL) { raw_copy (bstr, that.bstr); } |
|---|
| 83 |
Bstr (CBSTR that) : bstr (NULL) { raw_copy (bstr, that); } |
|---|
| 84 |
|
|---|
| 85 |
#if defined (VBOX_WITH_XPCOM) |
|---|
| 86 |
Bstr (const wchar_t *that) : bstr (NULL) |
|---|
| 87 |
{ |
|---|
| 88 |
AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR)); |
|---|
| 89 |
raw_copy (bstr, (CBSTR) that); |
|---|
| 90 |
} |
|---|
| 91 |
#endif |
|---|
| 92 |
|
|---|
| 93 |
Bstr (const Utf8Str &that); |
|---|
| 94 |
Bstr (const char *that); |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
Bstr (size_t aSize) : bstr (NULL) { alloc (aSize); } |
|---|
| 98 |
|
|---|
| 99 |
~Bstr () { setNull(); } |
|---|
| 100 |
|
|---|
| 101 |
Bstr &operator = (const Bstr &that) { safe_assign (that.bstr); return *this; } |
|---|
| 102 |
Bstr &operator = (CBSTR that) { safe_assign (that); return *this; } |
|---|
| 103 |
|
|---|
| 104 |
Bstr &operator = (const Utf8Str &that); |
|---|
| 105 |
Bstr &operator = (const char *that); |
|---|
| 106 |
|
|---|
| 107 |
Bstr &setNull() |
|---|
| 108 |
{ |
|---|
| 109 |
if (bstr) |
|---|
| 110 |
{ |
|---|
| 111 |
::SysFreeString (bstr); |
|---|
| 112 |
bstr = NULL; |
|---|
| 113 |
} |
|---|
| 114 |
return *this; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
Bstr &setNullIfEmpty() |
|---|
| 118 |
{ |
|---|
| 119 |
if (bstr && *bstr == 0) |
|---|
| 120 |
{ |
|---|
| 121 |
::SysFreeString (bstr); |
|---|
| 122 |
bstr = NULL; |
|---|
| 123 |
} |
|---|
| 124 |
return *this; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
Bstr &alloc (size_t aSize) |
|---|
| 133 |
{ |
|---|
| 134 |
setNull(); |
|---|
| 135 |
if (aSize) |
|---|
| 136 |
{ |
|---|
| 137 |
unsigned int size = (unsigned int) aSize; Assert (size == aSize); |
|---|
| 138 |
bstr = ::SysAllocStringLen (NULL, size - 1); |
|---|
| 139 |
if (bstr) |
|---|
| 140 |
bstr [0] = 0; |
|---|
| 141 |
} |
|---|
| 142 |
return *this; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
int compare (CBSTR str) const |
|---|
| 146 |
{ |
|---|
| 147 |
return ::RTUtf16Cmp ((PRTUTF16) bstr, (PRTUTF16) str); |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
int compare (BSTR str) const |
|---|
| 151 |
{ |
|---|
| 152 |
return ::RTUtf16Cmp ((PRTUTF16) bstr, (PRTUTF16) str); |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
bool operator == (const Bstr &that) const { return !compare (that.bstr); } |
|---|
| 156 |
bool operator != (const Bstr &that) const { return !!compare (that.bstr); } |
|---|
| 157 |
bool operator == (CBSTR that) const { return !compare (that); } |
|---|
| 158 |
bool operator == (BSTR that) const { return !compare (that); } |
|---|
| 159 |
|
|---|
| 160 |
#if defined (VBOX_WITH_XPCOM) |
|---|
| 161 |
bool operator != (const wchar_t *that) const |
|---|
| 162 |
{ |
|---|
| 163 |
AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR)); |
|---|
| 164 |
return !!compare ((CBSTR) that); |
|---|
| 165 |
} |
|---|
| 166 |
bool operator == (const wchar_t *that) const |
|---|
| 167 |
{ |
|---|
| 168 |
AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR)); |
|---|
| 169 |
return !compare ((CBSTR) that); |
|---|
| 170 |
} |
|---|
| 171 |
#endif |
|---|
| 172 |
|
|---|
| 173 |
bool operator != (CBSTR that) const { return !!compare (that); } |
|---|
| 174 |
bool operator != (BSTR that) const { return !!compare (that); } |
|---|
| 175 |
bool operator < (const Bstr &that) const { return compare (that.bstr) < 0; } |
|---|
| 176 |
bool operator < (CBSTR that) const { return compare (that) < 0; } |
|---|
| 177 |
bool operator < (BSTR that) const { return compare (that) < 0; } |
|---|
| 178 |
#if defined (VBOX_WITH_XPCOM) |
|---|
| 179 |
bool operator < (const wchar_t *that) const |
|---|
| 180 |
{ |
|---|
| 181 |
AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR)); |
|---|
| 182 |
return compare ((CBSTR) that) < 0; |
|---|
| 183 |
} |
|---|
| 184 |
#endif |
|---|
| 185 |
|
|---|
| 186 |
int compareIgnoreCase (CBSTR str) const |
|---|
| 187 |
{ |
|---|
| 188 |
return ::RTUtf16LocaleICmp (bstr, str); |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
bool isNull() const { return bstr == NULL; } |
|---|
| 192 |
operator bool() const { return !isNull(); } |
|---|
| 193 |
|
|---|
| 194 |
bool isEmpty() const { return isNull() || *bstr == 0; } |
|---|
| 195 |
|
|---|
| 196 |
size_t length() const { return isNull() ? 0 : ::RTUtf16Len ((PRTUTF16) bstr); } |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
operator CBSTR () const { return bstr; } |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
operator BSTR () { return bstr; } |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
CBSTR raw() const { return bstr; } |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
BSTR mutableRaw() { return bstr; } |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
const Bstr &cloneTo (BSTR *pstr) const |
|---|
| 229 |
{ |
|---|
| 230 |
if (pstr) |
|---|
| 231 |
{ |
|---|
| 232 |
*pstr = NULL; |
|---|
| 233 |
raw_copy (*pstr, bstr); |
|---|
| 234 |
} |
|---|
| 235 |
return *this; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
Bstr &detachTo (BSTR *pstr) |
|---|
| 247 |
{ |
|---|
| 248 |
*pstr = bstr; |
|---|
| 249 |
bstr = NULL; |
|---|
| 250 |
return *this; |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
const Bstr &cloneTo (char **pstr) const; |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
BSTR *asOutParam() { setNull(); return &bstr; } |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
static const Bstr Null; |
|---|
| 270 |
|
|---|
| 271 |
protected: |
|---|
| 272 |
|
|---|
| 273 |
void safe_assign (CBSTR str) |
|---|
| 274 |
{ |
|---|
| 275 |
if (bstr != str) |
|---|
| 276 |
{ |
|---|
| 277 |
setNull(); |
|---|
| 278 |
raw_copy (bstr, str); |
|---|
| 279 |
} |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
inline static void raw_copy (BSTR &ls, CBSTR rs) |
|---|
| 283 |
{ |
|---|
| 284 |
if (rs) |
|---|
| 285 |
ls = ::SysAllocString ((const OLECHAR *) rs); |
|---|
| 286 |
} |
|---|
| 287 |
|
|---|
| 288 |
inline static void raw_copy (BSTR &ls, const char *rs) |
|---|
| 289 |
{ |
|---|
| 290 |
if (rs) |
|---|
| 291 |
{ |
|---|
| 292 |
PRTUTF16 s = NULL; |
|---|
| 293 |
::RTStrToUtf16 (rs, &s); |
|---|
| 294 |
raw_copy (ls, (BSTR) s); |
|---|
| 295 |
::RTUtf16Free (s); |
|---|
| 296 |
} |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
BSTR bstr; |
|---|
| 300 |
|
|---|
| 301 |
friend class Utf8Str; |
|---|
| 302 |
}; |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
inline bool operator== (CBSTR l, const Bstr &r) { return r.operator== (l); } |
|---|
| 306 |
inline bool operator!= (CBSTR l, const Bstr &r) { return r.operator!= (l); } |
|---|
| 307 |
inline bool operator== (BSTR l, const Bstr &r) { return r.operator== (l); } |
|---|
| 308 |
inline bool operator!= (BSTR l, const Bstr &r) { return r.operator!= (l); } |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
class Utf8Str |
|---|
| 327 |
{ |
|---|
| 328 |
public: |
|---|
| 329 |
|
|---|
| 330 |
typedef char *String; |
|---|
| 331 |
typedef const char *ConstString; |
|---|
| 332 |
|
|---|
| 333 |
Utf8Str () : str (NULL) {} |
|---|
| 334 |
|
|---|
| 335 |
Utf8Str (const Utf8Str &that) : str (NULL) { raw_copy (str, that.str); } |
|---|
| 336 |
Utf8Str (const char *that) : str (NULL) { raw_copy (str, that); } |
|---|
| 337 |
|
|---|
| 338 |
Utf8Str (const Bstr &that) : str (NULL) { raw_copy (str, that); } |
|---|
| 339 |
Utf8Str (CBSTR that) : str (NULL) { raw_copy (str, that); } |
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
Utf8Str (size_t aSize) : str (NULL) { alloc(aSize); } |
|---|
| 343 |
|
|---|
| 344 |
virtual ~Utf8Str () { setNull(); } |
|---|
| 345 |
|
|---|
| 346 |
Utf8Str &operator = (const Utf8Str &that) { safe_assign (that.str); return *this; } |
|---|
| 347 |
Utf8Str &operator = (const char *that) { safe_assign (that); return *this; } |
|---|
| 348 |
|
|---|
| 349 |
Utf8Str &operator = (const Bstr &that) |
|---|
| 350 |
{ |
|---|
| 351 |
setNull(); |
|---|
| 352 |
raw_copy (str, that); |
|---|
| 353 |
return *this; |
|---|
| 354 |
} |
|---|
| 355 |
Utf8Str &operator = (CBSTR that) |
|---|
| 356 |
{ |
|---|
| 357 |
setNull(); |
|---|
| 358 |
raw_copy (str, that); |
|---|
| 359 |
return *this; |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
Utf8Str &setNull() |
|---|
| 363 |
{ |
|---|
| 364 |
if (str) |
|---|
| 365 |
{ |
|---|
| 366 |
#if !defined (VBOX_WITH_XPCOM) |
|---|
| 367 |
::RTStrFree (str); |
|---|
| 368 |
#else |
|---|
| 369 |
nsMemory::Free (str); |
|---|
| 370 |
#endif |
|---|
| 371 |
str = NULL; |
|---|
| 372 |
} |
|---|
| 373 |
return *this; |
|---|
| 374 |
} |
|---|
| 375 |
|
|---|
| 376 |
Utf8Str &setNullIfEmpty() |
|---|
| 377 |
{ |
|---|
| 378 |
if (str && *str == 0) |
|---|
| 379 |
{ |
|---|
| 380 |
#if !defined (VBOX_WITH_XPCOM) |
|---|
| 381 |
::RTStrFree (str); |
|---|
| 382 |
#else |
|---|
| 383 |
nsMemory::Free (str); |
|---|
| 384 |
#endif |
|---|
| 385 |
str = NULL; |
|---|
| 386 |
} |
|---|
| 387 |
return *this; |
|---|
| 388 |
} |
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
|
|---|
| 395 |
Utf8Str &alloc (size_t aSize) |
|---|
| 396 |
{ |
|---|
| 397 |
setNull(); |
|---|
| 398 |
if (aSize) |
|---|
| 399 |
{ |
|---|
| 400 |
#if !defined (VBOX_WITH_XPCOM) |
|---|
| 401 |
str = (char *) ::RTMemTmpAlloc (aSize); |
|---|
| 402 |
#else |
|---|
| 403 |
str = (char *) nsMemory::Alloc (aSize); |
|---|
| 404 |
#endif |
|---|
| 405 |
if (str) |
|---|
| 406 |
str [0] = 0; |
|---|
| 407 |
} |
|---|
| 408 |
return *this; |
|---|
| 409 |
} |
|---|
| 410 |
|
|---|
| 411 |
int compare (const char *s) const |
|---|
| 412 |
{ |
|---|
| 413 |
if (str == s) |
|---|
| 414 |
return 0; |
|---|
| 415 |
if (str == NULL) |
|---|
| 416 |
return -1; |
|---|
| 417 |
if (s == NULL) |
|---|
| 418 |
return 1; |
|---|
| 419 |
|
|---|
| 420 |
return ::strcmp (str, s); |
|---|
| 421 |
} |
|---|
| 422 |
|
|---|
| 423 |
bool operator == (const Utf8Str &that) const { return !compare (that.str); } |
|---|
| 424 |
bool operator != (const Utf8Str &that) const { return !!compare (that.str); } |
|---|
| 425 |
bool operator == (const char *that) const { return !compare (that); } |
|---|
| 426 |
bool operator != (const char *that) const { return !!compare (that); } |
|---|
| 427 |
bool operator < (const Utf8Str &that) const { return compare (that.str) < 0; } |
|---|
| 428 |
bool operator < (const char *that) const { return compare (that) < 0; } |
|---|
| 429 |
|
|---|
| 430 |
bool isNull() const { return str == NULL; } |
|---|
| 431 |
operator bool() const { return !isNull(); } |
|---|
| 432 |
|
|---|
| 433 |
bool isEmpty() const { return isNull() || *str == 0; } |
|---|
| 434 |
|
|---|
| 435 |
size_t length() const { return isNull() ? 0 : ::strlen (str); } |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
operator const char *() const { return str; } |
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
const char *raw() const { return str; } |
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
char *mutableRaw() { return str; } |
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
const Utf8Str &cloneTo (char **pstr) const |
|---|
| 459 |
{ |
|---|
| 460 |
if (pstr) |
|---|
| 461 |
{ |
|---|
| 462 |
*pstr = NULL; |
|---|
| 463 |
raw_copy (*pstr, str); |
|---|
| 464 |
} |
|---|
| 465 |
return *this; |
|---|
| 466 |
} |
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
Utf8Str &detachTo (char **pstr) |
|---|
| 477 |
{ |
|---|
| 478 |
*pstr = str; |
|---|
| 479 |
str = NULL; |
|---|
| 480 |
return *this; |
|---|
| 481 |
} |
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
const Utf8Str &cloneTo (BSTR *pstr) const |
|---|
| 489 |
{ |
|---|
| 490 |
if (pstr) |
|---|
| 491 |
{ |
|---|
| 492 |
*pstr = NULL; |
|---|
| 493 |
Bstr::raw_copy (*pstr, str); |
|---|
| 494 |
} |
|---|
| 495 |
return *this; |
|---|
| 496 |
} |
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
char **asOutParam() { setNull(); return &str; } |
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
static const Utf8Str Null; |
|---|
| 508 |
|
|---|
| 509 |
protected: |
|---|
| 510 |
|
|---|
| 511 |
void safe_assign (const char *s) |
|---|
| 512 |
{ |
|---|
| 513 |
if (str != s) |
|---|
| 514 |
{ |
|---|
| 515 |
setNull(); |
|---|
| 516 |
raw_copy (str, s); |
|---|
| 517 |
} |
|---|
| 518 |
} |
|---|
| 519 |
|
|---|
| 520 |
inline static void raw_copy (char *&ls, const char *rs) |
|---|
| 521 |
{ |
|---|
| 522 |
if (rs) |
|---|
| 523 |
#if !defined (VBOX_WITH_XPCOM) |
|---|
| 524 |
::RTStrDupEx (&ls, rs); |
|---|
| 525 |
#else |
|---|
| 526 |
ls = (char *) nsMemory::Clone (rs, strlen (rs) + 1); |
|---|
| 527 |
#endif |
|---|
| 528 |
} |
|---|
| 529 |
|
|---|
| 530 |
inline static void raw_copy (char *&ls, CBSTR rs) |
|---|
| 531 |
{ |
|---|
| 532 |
if (rs) |
|---|
| 533 |
{ |
|---|
| 534 |
#if !defined (VBOX_WITH_XPCOM) |
|---|
| 535 |
::RTUtf16ToUtf8 ((PRTUTF16) rs, &ls); |
|---|
| 536 |
#else |
|---|
| 537 |
char *s = NULL; |
|---|
| 538 |
::RTUtf16ToUtf8 ((PRTUTF16) rs, &s); |
|---|
| 539 |
raw_copy (ls, s); |
|---|
| 540 |
::RTStrFree (s); |
|---|
| 541 |
#endif |
|---|
| 542 |
} |
|---|
| 543 |
} |
|---|
| 544 |
|
|---|
| 545 |
char *str; |
|---|
| 546 |
|
|---|
| 547 |
friend class Bstr; |
|---|
| 548 |
}; |
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
inline bool operator== (const char *l, const Utf8Str &r) { return r.operator== (l); } |
|---|
| 552 |
inline bool operator!= (const char *l, const Utf8Str &r) { return r.operator!= (l); } |
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP (Bstr) |
|---|
| 556 |
WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP (Utf8Str) |
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
inline Bstr::Bstr (const Utf8Str &that) : bstr (NULL) { raw_copy (bstr, that); } |
|---|
| 563 |
inline Bstr::Bstr (const char *that) : bstr (NULL) { raw_copy (bstr, that); } |
|---|
| 564 |
|
|---|
| 565 |
inline Bstr &Bstr::operator = (const Utf8Str &that) |
|---|
| 566 |
{ |
|---|
| 567 |
setNull(); |
|---|
| 568 |
raw_copy (bstr, that); |
|---|
| 569 |
return *this; |
|---|
| 570 |
} |
|---|
| 571 |
inline Bstr &Bstr::operator = (const char *that) |
|---|
| 572 |
{ |
|---|
| 573 |
setNull(); |
|---|
| 574 |
raw_copy (bstr, that); |
|---|
| 575 |
return *this; |
|---|
| 576 |
} |
|---|
| 577 |
|
|---|
| 578 |
inline const Bstr &Bstr::cloneTo (char **pstr) const |
|---|
| 579 |
{ |
|---|
| 580 |
if (pstr) { |
|---|
| 581 |
*pstr = NULL; |
|---|
| 582 |
Utf8Str::raw_copy (*pstr, bstr); |
|---|
| 583 |
} |
|---|
| 584 |
return *this; |
|---|
| 585 |
} |
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
class Utf8StrFmt : public Utf8Str |
|---|
| 600 |
{ |
|---|
| 601 |
public: |
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
explicit Utf8StrFmt (const char *format, ...) |
|---|
| 611 |
{ |
|---|
| 612 |
va_list args; |
|---|
| 613 |
va_start (args, format); |
|---|
| 614 |
init (format, args); |
|---|
| 615 |
va_end (args); |
|---|
| 616 |
} |
|---|
| 617 |
|
|---|
| 618 |
protected: |
|---|
| 619 |
|
|---|
| 620 |
Utf8StrFmt() {} |
|---|
| 621 |
|
|---|
| 622 |
void init (const char *format, va_list args); |
|---|
| 623 |
|
|---|
| 624 |
private: |
|---|
| 625 |
|
|---|
| 626 |
static DECLCALLBACK(size_t) strOutput (void *pvArg, const char *pachChars, |
|---|
| 627 |
size_t cbChars); |
|---|
| 628 |
}; |
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
class Utf8StrFmtVA : public Utf8StrFmt |
|---|
| 645 |
{ |
|---|
| 646 |
public: |
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
Utf8StrFmtVA (const char *format, va_list args) { init (format, args); } |
|---|
| 656 |
}; |
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
class BstrFmt : public Bstr |
|---|
| 662 |
{ |
|---|
| 663 |
public: |
|---|
| 664 |
|
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
explicit BstrFmt (const char *aFormat, ...) |
|---|
| 673 |
{ |
|---|
| 674 |
va_list args; |
|---|
| 675 |
va_start (args, aFormat); |
|---|
| 676 |
raw_copy (bstr, Utf8StrFmtVA (aFormat, args)); |
|---|
| 677 |
va_end (args); |
|---|
| 678 |
} |
|---|
| 679 |
}; |
|---|
| 680 |
|
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 |
class BstrFmtVA : public Bstr |
|---|
| 685 |
{ |
|---|
| 686 |
public: |
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
BstrFmtVA (const char *aFormat, va_list aArgs) |
|---|
| 696 |
{ |
|---|
| 697 |
raw_copy (bstr, Utf8StrFmtVA (aFormat, aArgs)); |
|---|
| 698 |
} |
|---|
| 699 |
}; |
|---|
| 700 |
|
|---|
| 701 |
} |
|---|
| 702 |
|
|---|
| 703 |
#endif |
|---|