VirtualBox

source: vbox/trunk/include/VBox/com/string.h@ 84287

最後變更 在這個檔案從84287是 84287,由 vboxsync 提交於 5 年 前

Glue/Bstr: Adding a base64Encode method using the new UTF-16 base64 encoding functions in IPRT. bugref:9224

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 45.0 KB
 
1/* $Id: string.h 84287 2020-05-13 13:59:34Z vboxsync $ */
2/** @file
3 * MS COM / XPCOM Abstraction Layer - Smart string classes declaration.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef VBOX_INCLUDED_com_string_h
28#define VBOX_INCLUDED_com_string_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33/* Make sure all the stdint.h macros are included - must come first! */
34#ifndef __STDC_LIMIT_MACROS
35# define __STDC_LIMIT_MACROS
36#endif
37#ifndef __STDC_CONSTANT_MACROS
38# define __STDC_CONSTANT_MACROS
39#endif
40
41#if defined(VBOX_WITH_XPCOM)
42# include <nsMemory.h>
43#endif
44
45#include "VBox/com/defs.h"
46#include "VBox/com/assert.h"
47
48#include <iprt/mem.h>
49#include <iprt/utf16.h>
50#include <iprt/cpp/ministring.h>
51
52
53/** @defgroup grp_com_str Smart String Classes
54 * @ingroup grp_com
55 * @{
56 */
57
58namespace com
59{
60
61class Utf8Str;
62
63// global constant in glue/string.cpp that represents an empty BSTR
64extern const BSTR g_bstrEmpty;
65
66/**
67 * String class used universally in Main for COM-style Utf-16 strings.
68 *
69 * Unfortunately COM on Windows uses UTF-16 everywhere, requiring conversions
70 * back and forth since most of VirtualBox and our libraries use UTF-8.
71 *
72 * To make things more obscure, on Windows, a COM-style BSTR is not just a
73 * pointer to a null-terminated wide character array, but the four bytes (32
74 * bits) BEFORE the memory that the pointer points to are a length DWORD. One
75 * must therefore avoid pointer arithmetic and always use SysAllocString and
76 * the like to deal with BSTR pointers, which manage that DWORD correctly.
77 *
78 * For platforms other than Windows, we provide our own versions of the Sys*
79 * functions in Main/xpcom/helpers.cpp which do NOT use length prefixes though
80 * to be compatible with how XPCOM allocates string parameters to public
81 * functions.
82 *
83 * The Bstr class hides all this handling behind a std::string-like interface
84 * and also provides automatic conversions to RTCString and Utf8Str instances.
85 *
86 * The one advantage of using the SysString* routines is that this makes it
87 * possible to use it as a type of member variables of COM/XPCOM components and
88 * pass their values to callers through component methods' output parameters
89 * using the #cloneTo() operation. Also, the class can adopt (take ownership
90 * of) string buffers returned in output parameters of COM methods using the
91 * #asOutParam() operation and correctly free them afterwards.
92 *
93 * Starting with VirtualBox 3.2, like Utf8Str, Bstr no longer differentiates
94 * between NULL strings and empty strings. In other words, Bstr("") and
95 * Bstr(NULL) behave the same. In both cases, Bstr allocates no memory,
96 * reports a zero length and zero allocated bytes for both, and returns an
97 * empty C wide string from raw().
98 *
99 * @note All Bstr methods ASSUMES valid UTF-16 or UTF-8 input strings.
100 * The VirtualBox policy in this regard is to validate strings coming
101 * from external sources before passing them to Bstr or Utf8Str.
102 */
103class Bstr
104{
105public:
106
107 Bstr()
108 : m_bstr(NULL)
109 { }
110
111 Bstr(const Bstr &that)
112 {
113 copyFrom((const OLECHAR *)that.m_bstr);
114 }
115
116 Bstr(CBSTR that)
117 {
118 copyFrom((const OLECHAR *)that);
119 }
120
121#if defined(VBOX_WITH_XPCOM)
122 Bstr(const wchar_t *that)
123 {
124 AssertCompile(sizeof(wchar_t) == sizeof(OLECHAR));
125 copyFrom((const OLECHAR *)that);
126 }
127#endif
128
129 Bstr(const RTCString &that)
130 {
131 copyFrom(that.c_str());
132 }
133
134 Bstr(const char *that)
135 {
136 copyFrom(that);
137 }
138
139 Bstr(const char *a_pThat, size_t a_cchMax)
140 {
141 copyFromN(a_pThat, a_cchMax);
142 }
143
144 ~Bstr()
145 {
146 setNull();
147 }
148
149 Bstr &operator=(const Bstr &that)
150 {
151 cleanupAndCopyFrom((const OLECHAR *)that.m_bstr);
152 return *this;
153 }
154
155 Bstr &operator=(CBSTR that)
156 {
157 cleanupAndCopyFrom((const OLECHAR *)that);
158 return *this;
159 }
160
161#if defined(VBOX_WITH_XPCOM)
162 Bstr &operator=(const wchar_t *that)
163 {
164 cleanupAndCopyFrom((const OLECHAR *)that);
165 return *this;
166 }
167#endif
168
169 Bstr &setNull()
170 {
171 cleanup();
172 return *this;
173 }
174
175#ifdef _MSC_VER
176# if _MSC_VER >= 1400
177 RTMEMEF_NEW_AND_DELETE_OPERATORS();
178# endif
179#else
180 RTMEMEF_NEW_AND_DELETE_OPERATORS();
181#endif
182
183 /** Case sensitivity selector. */
184 enum CaseSensitivity
185 {
186 CaseSensitive,
187 CaseInsensitive
188 };
189
190 /**
191 * Compares the member string to str.
192 * @param str
193 * @param cs Whether comparison should be case-sensitive.
194 * @return
195 */
196 int compare(CBSTR str, CaseSensitivity cs = CaseSensitive) const
197 {
198 if (cs == CaseSensitive)
199 return ::RTUtf16Cmp((PRTUTF16)m_bstr, (PRTUTF16)str);
200 return ::RTUtf16LocaleICmp((PRTUTF16)m_bstr, (PRTUTF16)str);
201 }
202
203 int compare(BSTR str, CaseSensitivity cs = CaseSensitive) const
204 {
205 return compare((CBSTR)str, cs);
206 }
207
208 int compare(const Bstr &that, CaseSensitivity cs = CaseSensitive) const
209 {
210 return compare(that.m_bstr, cs);
211 }
212
213 bool operator==(const Bstr &that) const { return !compare(that.m_bstr); }
214 bool operator==(CBSTR that) const { return !compare(that); }
215 bool operator==(BSTR that) const { return !compare(that); }
216 bool operator!=(const Bstr &that) const { return !!compare(that.m_bstr); }
217 bool operator!=(CBSTR that) const { return !!compare(that); }
218 bool operator!=(BSTR that) const { return !!compare(that); }
219 bool operator<(const Bstr &that) const { return compare(that.m_bstr) < 0; }
220 bool operator<(CBSTR that) const { return compare(that) < 0; }
221 bool operator<(BSTR that) const { return compare(that) < 0; }
222 bool operator<=(const Bstr &that) const { return compare(that.m_bstr) <= 0; }
223 bool operator<=(CBSTR that) const { return compare(that) <= 0; }
224 bool operator<=(BSTR that) const { return compare(that) <= 0; }
225 bool operator>(const Bstr &that) const { return compare(that.m_bstr) > 0; }
226 bool operator>(CBSTR that) const { return compare(that) > 0; }
227 bool operator>(BSTR that) const { return compare(that) > 0; }
228 bool operator>=(const Bstr &that) const { return compare(that.m_bstr) >= 0; }
229 bool operator>=(CBSTR that) const { return compare(that) >= 0; }
230 bool operator>=(BSTR that) const { return compare(that) >= 0; }
231
232 /**
233 * Compares this string to an UTF-8 C style string.
234 *
235 * @retval 0 if equal
236 * @retval -1 if this string is smaller than the UTF-8 one.
237 * @retval 1 if the UTF-8 string is smaller than this.
238 *
239 * @param a_pszRight The string to compare with.
240 * @param a_enmCase Whether comparison should be case-sensitive.
241 */
242 int compareUtf8(const char *a_pszRight, CaseSensitivity a_enmCase = CaseSensitive) const;
243
244 /** Java style compare method.
245 * @returns true if @a a_pszRight equals this string.
246 * @param a_pszRight The (UTF-8) string to compare with. */
247 bool equals(const char *a_pszRight) const { return compareUtf8(a_pszRight, CaseSensitive) == 0; }
248
249 /** Java style case-insensitive compare method.
250 * @returns true if @a a_pszRight equals this string.
251 * @param a_pszRight The (UTF-8) string to compare with. */
252 bool equalsIgnoreCase(const char *a_pszRight) const { return compareUtf8(a_pszRight, CaseInsensitive) == 0; }
253
254 /** Java style compare method.
255 * @returns true if @a a_rThat equals this string.
256 * @param a_rThat The other Bstr instance to compare with. */
257 bool equals(const Bstr &a_rThat) const { return compare(a_rThat.m_bstr, CaseSensitive) == 0; }
258 /** Java style case-insensitive compare method.
259 * @returns true if @a a_rThat equals this string.
260 * @param a_rThat The other Bstr instance to compare with. */
261 bool equalsIgnoreCase(const Bstr &a_rThat) const { return compare(a_rThat.m_bstr, CaseInsensitive) == 0; }
262
263 /** Java style compare method.
264 * @returns true if @a a_pThat equals this string.
265 * @param a_pThat The native const BSTR to compare with. */
266 bool equals(CBSTR a_pThat) const { return compare(a_pThat, CaseSensitive) == 0; }
267 /** Java style case-insensitive compare method.
268 * @returns true if @a a_pThat equals this string.
269 * @param a_pThat The native const BSTR to compare with. */
270 bool equalsIgnoreCase(CBSTR a_pThat) const { return compare(a_pThat, CaseInsensitive) == 0; }
271
272 /** Java style compare method.
273 * @returns true if @a a_pThat equals this string.
274 * @param a_pThat The native BSTR to compare with. */
275 bool equals(BSTR a_pThat) const { return compare(a_pThat, CaseSensitive) == 0; }
276 /** Java style case-insensitive compare method.
277 * @returns true if @a a_pThat equals this string.
278 * @param a_pThat The native BSTR to compare with. */
279 bool equalsIgnoreCase(BSTR a_pThat) const { return compare(a_pThat, CaseInsensitive) == 0; }
280
281 /**
282 * Returns true if the member string has no length.
283 * This is true for instances created from both NULL and "" input strings.
284 *
285 * @note Always use this method to check if an instance is empty. Do not
286 * use length() because that may need to run through the entire string
287 * (Bstr does not cache string lengths).
288 */
289 bool isEmpty() const { return m_bstr == NULL || *m_bstr == 0; }
290
291 /**
292 * Returns true if the member string has a length of one or more.
293 *
294 * @returns true if not empty, false if empty (NULL or "").
295 */
296 bool isNotEmpty() const { return m_bstr != NULL && *m_bstr != 0; }
297
298 size_t length() const { return isEmpty() ? 0 : ::RTUtf16Len((PRTUTF16)m_bstr); }
299
300 /**
301 * Assigns the output of the string format operation (RTStrPrintf).
302 *
303 * @param pszFormat Pointer to the format string,
304 * @see pg_rt_str_format.
305 * @param ... Ellipsis containing the arguments specified by
306 * the format string.
307 *
308 * @throws std::bad_alloc On allocation error. Object state is undefined.
309 *
310 * @returns Reference to the object.
311 */
312 Bstr &printf(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
313
314 /**
315 * Assigns the output of the string format operation (RTStrPrintf).
316 *
317 * @param pszFormat Pointer to the format string,
318 * @see pg_rt_str_format.
319 * @param ... Ellipsis containing the arguments specified by
320 * the format string.
321 *
322 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
323 */
324 HRESULT printfNoThrow(const char *pszFormat, ...) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 2);
325
326 /**
327 * Assigns the output of the string format operation (RTStrPrintfV).
328 *
329 * @param pszFormat Pointer to the format string,
330 * @see pg_rt_str_format.
331 * @param va Argument vector containing the arguments
332 * specified by the format string.
333 *
334 * @throws std::bad_alloc On allocation error. Object state is undefined.
335 *
336 * @returns Reference to the object.
337 */
338 Bstr &printfV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
339
340 /**
341 * Assigns the output of the string format operation (RTStrPrintfV).
342 *
343 * @param pszFormat Pointer to the format string,
344 * @see pg_rt_str_format.
345 * @param va Argument vector containing the arguments
346 * specified by the format string.
347 *
348 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
349 */
350 HRESULT printfVNoThrow(const char *pszFormat, va_list va) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 0);
351
352 /** @name Append methods and operators
353 * @{ */
354
355 /**
356 * Appends the string @a that to @a rThat.
357 *
358 * @param rThat The string to append.
359 * @throws std::bad_alloc On allocation error. The object is left unchanged.
360 * @returns Reference to the object.
361 */
362 Bstr &append(const Bstr &rThat);
363
364 /**
365 * Appends the string @a that to @a rThat.
366 *
367 * @param rThat The string to append.
368 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
369 */
370 HRESULT appendNoThrow(const Bstr &rThat) RT_NOEXCEPT;
371
372 /**
373 * Appends the UTF-8 string @a that to @a rThat.
374 *
375 * @param rThat The string to append.
376 * @throws std::bad_alloc On allocation error. The object is left unchanged.
377 * @returns Reference to the object.
378 */
379 Bstr &append(const RTCString &rThat);
380
381 /**
382 * Appends the UTF-8 string @a that to @a rThat.
383 *
384 * @param rThat The string to append.
385 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
386 */
387 HRESULT appendNoThrow(const RTCString &rThat) RT_NOEXCEPT;
388
389 /**
390 * Appends the UTF-16 string @a pszSrc to @a this.
391 *
392 * @param pwszSrc The C-style UTF-16 string to append.
393 * @throws std::bad_alloc On allocation error. The object is left unchanged.
394 * @returns Reference to the object.
395 */
396 Bstr &append(CBSTR pwszSrc);
397
398 /**
399 * Appends the UTF-16 string @a pszSrc to @a this.
400 *
401 * @param pwszSrc The C-style UTF-16 string to append.
402 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
403 */
404 HRESULT appendNoThrow(CBSTR pwszSrc) RT_NOEXCEPT;
405
406 /**
407 * Appends the UTF-8 string @a pszSrc to @a this.
408 *
409 * @param pszSrc The C-style string to append.
410 * @throws std::bad_alloc On allocation error. The object is left unchanged.
411 * @returns Reference to the object.
412 */
413 Bstr &append(const char *pszSrc);
414
415 /**
416 * Appends the UTF-8 string @a pszSrc to @a this.
417 *
418 * @param pszSrc The C-style string to append.
419 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
420 */
421 HRESULT appendNoThrow(const char *pszSrc) RT_NOEXCEPT;
422
423 /**
424 * Appends the a substring from @a rThat to @a this.
425 *
426 * @param rThat The string to append a substring from.
427 * @param offStart The start of the substring to append (UTF-16
428 * offset, not codepoint).
429 * @param cwcMax The maximum number of UTF-16 units to append.
430 * @throws std::bad_alloc On allocation error. The object is left unchanged.
431 * @returns Reference to the object.
432 */
433 Bstr &append(const Bstr &rThat, size_t offStart, size_t cwcMax = RTSTR_MAX);
434
435 /**
436 * Appends the a substring from @a rThat to @a this.
437 *
438 * @param rThat The string to append a substring from.
439 * @param offStart The start of the substring to append (UTF-16
440 * offset, not codepoint).
441 * @param cwcMax The maximum number of UTF-16 units to append.
442 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
443 */
444 HRESULT appendNoThrow(const Bstr &rThat, size_t offStart, size_t cwcMax = RTSTR_MAX) RT_NOEXCEPT;
445
446 /**
447 * Appends the a substring from UTF-8 @a rThat to @a this.
448 *
449 * @param rThat The string to append a substring from.
450 * @param offStart The start of the substring to append (byte offset,
451 * not codepoint).
452 * @param cchMax The maximum number of bytes to append.
453 * @throws std::bad_alloc On allocation error. The object is left unchanged.
454 * @returns Reference to the object.
455 */
456 Bstr &append(const RTCString &rThat, size_t offStart, size_t cchMax = RTSTR_MAX);
457
458 /**
459 * Appends the a substring from UTF-8 @a rThat to @a this.
460 *
461 * @param rThat The string to append a substring from.
462 * @param offStart The start of the substring to append (byte offset,
463 * not codepoint).
464 * @param cchMax The maximum number of bytes to append.
465 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
466 */
467 HRESULT appendNoThrow(const RTCString &rThat, size_t offStart, size_t cchMax = RTSTR_MAX) RT_NOEXCEPT;
468
469 /**
470 * Appends the first @a cchMax chars from UTF-16 string @a pszThat to @a this.
471 *
472 * @param pwszThat The C-style UTF-16 string to append.
473 * @param cchMax The maximum number of bytes to append.
474 * @throws std::bad_alloc On allocation error. The object is left unchanged.
475 * @returns Reference to the object.
476 */
477 Bstr &append(CBSTR pwszThat, size_t cchMax);
478
479 /**
480 * Appends the first @a cchMax chars from UTF-16 string @a pszThat to @a this.
481 *
482 * @param pwszThat The C-style UTF-16 string to append.
483 * @param cchMax The maximum number of bytes to append.
484 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
485 */
486 HRESULT appendNoThrow(CBSTR pwszThat, size_t cchMax) RT_NOEXCEPT;
487
488 /**
489 * Appends the first @a cchMax chars from string @a pszThat to @a this.
490 *
491 * @param pszThat The C-style string to append.
492 * @param cchMax The maximum number of bytes to append.
493 * @throws std::bad_alloc On allocation error. The object is left unchanged.
494 * @returns Reference to the object.
495 */
496 Bstr &append(const char *pszThat, size_t cchMax);
497
498 /**
499 * Appends the first @a cchMax chars from string @a pszThat to @a this.
500 *
501 * @param pszThat The C-style string to append.
502 * @param cchMax The maximum number of bytes to append.
503 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
504 */
505 HRESULT appendNoThrow(const char *pszThat, size_t cchMax) RT_NOEXCEPT;
506
507 /**
508 * Appends the given character to @a this.
509 *
510 * @param ch The character to append.
511 * @throws std::bad_alloc On allocation error. The object is left unchanged.
512 * @returns Reference to the object.
513 */
514 Bstr &append(char ch);
515
516 /**
517 * Appends the given character to @a this.
518 *
519 * @param ch The character to append.
520 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
521 */
522 HRESULT appendNoThrow(char ch) RT_NOEXCEPT;
523
524 /**
525 * Appends the given unicode code point to @a this.
526 *
527 * @param uc The unicode code point to append.
528 * @throws std::bad_alloc On allocation error. The object is left unchanged.
529 * @returns Reference to the object.
530 */
531 Bstr &appendCodePoint(RTUNICP uc);
532
533 /**
534 * Appends the given unicode code point to @a this.
535 *
536 * @param uc The unicode code point to append.
537 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
538 */
539 HRESULT appendCodePointNoThrow(RTUNICP uc) RT_NOEXCEPT;
540
541 /**
542 * Appends the output of the string format operation (RTStrPrintf).
543 *
544 * @param pszFormat Pointer to the format string,
545 * @see pg_rt_str_format.
546 * @param ... Ellipsis containing the arguments specified by
547 * the format string.
548 *
549 * @throws std::bad_alloc On allocation error. Object state is undefined.
550 *
551 * @returns Reference to the object.
552 */
553 Bstr &appendPrintf(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
554
555 /**
556 * Appends the output of the string format operation (RTStrPrintf).
557 *
558 * @param pszFormat Pointer to the format string,
559 * @see pg_rt_str_format.
560 * @param ... Ellipsis containing the arguments specified by
561 * the format string.
562 *
563 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
564 */
565 HRESULT appendPrintfNoThrow(const char *pszFormat, ...) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 2);
566
567 /**
568 * Appends the output of the string format operation (RTStrPrintfV).
569 *
570 * @param pszFormat Pointer to the format string,
571 * @see pg_rt_str_format.
572 * @param va Argument vector containing the arguments
573 * specified by the format string.
574 *
575 * @throws std::bad_alloc On allocation error. Object state is undefined.
576 *
577 * @returns Reference to the object.
578 */
579 Bstr &appendPrintfV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
580
581 /**
582 * Appends the output of the string format operation (RTStrPrintfV).
583 *
584 * @param pszFormat Pointer to the format string,
585 * @see pg_rt_str_format.
586 * @param va Argument vector containing the arguments
587 * specified by the format string.
588 *
589 * @returns S_OK, E_OUTOFMEMORY or E_INVAL (bad encoding).
590 */
591 HRESULT appendPrintfVNoThrow(const char *pszFormat, va_list va) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 0);
592
593 /**
594 * Shortcut to append(), Bstr variant.
595 *
596 * @param rThat The string to append.
597 * @returns Reference to the object.
598 */
599 Bstr &operator+=(const Bstr &rThat)
600 {
601 return append(rThat);
602 }
603
604 /**
605 * Shortcut to append(), RTCString variant.
606 *
607 * @param rThat The string to append.
608 * @returns Reference to the object.
609 */
610 Bstr &operator+=(const RTCString &rThat)
611 {
612 return append(rThat);
613 }
614
615 /**
616 * Shortcut to append(), CBSTR variant.
617 *
618 * @param pwszThat The C-style string to append.
619 * @returns Reference to the object.
620 */
621 Bstr &operator+=(CBSTR pwszThat)
622 {
623 return append(pwszThat);
624 }
625
626 /**
627 * Shortcut to append(), const char * variant.
628 *
629 * @param pszThat The C-style string to append.
630 * @returns Reference to the object.
631 */
632 Bstr &operator+=(const char *pszThat)
633 {
634 return append(pszThat);
635 }
636
637 /**
638 * Shortcut to append(), char variant.
639 *
640 * @param ch The character to append.
641 *
642 * @returns Reference to the object.
643 */
644 Bstr &operator+=(char ch)
645 {
646 return append(ch);
647 }
648
649 /** @} */
650
651 /**
652 * Erases a sequence from the string.
653 *
654 * @returns Reference to the object.
655 * @param offStart Where in @a this string to start erasing (UTF-16
656 * units, not codepoints).
657 * @param cwcLength How much following @a offStart to erase (UTF-16
658 * units, not codepoints).
659 */
660 Bstr &erase(size_t offStart = 0, size_t cwcLength = RTSTR_MAX) RT_NOEXCEPT;
661
662
663 /** @name BASE64 related methods
664 * @{ */
665 /**
666 * Encodes the give data as BASE64.
667 *
668 * @returns S_OK or E_OUTOFMEMORY.
669 * @param pvData Pointer to the data to encode.
670 * @param cbData Number of bytes to encode.
671 * @param fLineBreaks Whether to add line breaks (true) or just encode it
672 * as a continuous string.
673 */
674 HRESULT base64Encode(const void *pvData, size_t cbData, bool fLineBreaks = false);
675 /** @} */
676
677#if defined(VBOX_WITH_XPCOM)
678 /**
679 * Returns a pointer to the raw member UTF-16 string. If the member string is empty,
680 * returns a pointer to a global variable containing an empty BSTR with a proper zero
681 * length prefix so that Windows is happy.
682 */
683 CBSTR raw() const
684 {
685 if (m_bstr)
686 return m_bstr;
687
688 return g_bstrEmpty;
689 }
690#else
691 /**
692 * Windows-only hack, as the automatically generated headers use BSTR.
693 * So if we don't want to cast like crazy we have to be more loose than
694 * on XPCOM.
695 *
696 * Returns a pointer to the raw member UTF-16 string. If the member string is empty,
697 * returns a pointer to a global variable containing an empty BSTR with a proper zero
698 * length prefix so that Windows is happy.
699 */
700 BSTR raw() const
701 {
702 if (m_bstr)
703 return m_bstr;
704
705 return g_bstrEmpty;
706 }
707#endif
708
709 /**
710 * Returns a non-const raw pointer that allows modifying the string directly.
711 *
712 * @note As opposed to raw(), this DOES return NULL if the member string is
713 * empty because we cannot return a mutable pointer to the global variable
714 * with the empty string.
715 *
716 * @note If modifying the string size (only shrinking it is allows), #jolt() or
717 * #joltNoThrow() must be called!
718 *
719 * @note Do not modify memory beyond the #length() of the string!
720 *
721 * @sa joltNoThrow(), mutalbleRaw(), reserve(), reserveNoThrow()
722 */
723 BSTR mutableRaw() { return m_bstr; }
724
725 /**
726 * Correct the embedded length after using mutableRaw().
727 *
728 * This is needed on COM (Windows) to update the embedded string length. It is
729 * a stub on hosts using XPCOM.
730 *
731 * @param cwcNew The new string length, if handy, otherwise a negative
732 * number.
733 * @sa joltNoThrow(), mutalbleRaw(), reserve(), reserveNoThrow()
734 */
735#ifndef VBOX_WITH_XPCOM
736 void jolt(ssize_t cwcNew = -1);
737#else
738 void jolt(ssize_t cwcNew = -1)
739 {
740 Assert(cwcNew < 0 || (cwcNew == 0 && !m_bstr) || m_bstr[cwcNew] == '\0'); RT_NOREF(cwcNew);
741 }
742#endif
743
744 /**
745 * Correct the embedded length after using mutableRaw().
746 *
747 * This is needed on COM (Windows) to update the embedded string length. It is
748 * a stub on hosts using XPCOM.
749 *
750 * @returns S_OK on success, E_OUTOFMEMORY if shrinking the string failed.
751 * @param cwcNew The new string length, if handy, otherwise a negative
752 * number.
753 * @sa jolt(), mutalbleRaw(), reserve(), reserveNoThrow()
754 */
755#ifndef VBOX_WITH_XPCOM
756 HRESULT joltNoThrow(ssize_t cwcNew = -1) RT_NOEXCEPT;
757#else
758 HRESULT joltNoThrow(ssize_t cwcNew = -1) RT_NOEXCEPT
759 {
760 Assert(cwcNew < 0 || (cwcNew == 0 && !m_bstr) || m_bstr[cwcNew] == '\0'); RT_NOREF(cwcNew);
761 return S_OK;
762 }
763#endif
764
765 /**
766 * Make sure at that least @a cwc of buffer space is reserved.
767 *
768 * Requests that the contained memory buffer have at least cb bytes allocated.
769 * This may expand or shrink the string's storage, but will never truncate the
770 * contained string. In other words, cb will be ignored if it's smaller than
771 * length() + 1.
772 *
773 * @param cwcMin The new minimum string length that the can be stored. This
774 * does not include the terminator.
775 * @param fForce Force this size.
776 *
777 * @throws std::bad_alloc On allocation error. The object is left unchanged.
778 */
779 void reserve(size_t cwcMin, bool fForce = false);
780
781 /**
782 * A C like version of the #reserve() method, i.e. return code instead of throw.
783 *
784 * @returns S_OK or E_OUTOFMEMORY.
785 * @param cwcMin The new minimum string length that the can be stored. This
786 * does not include the terminator.
787 * @param fForce Force this size.
788 */
789 HRESULT reserveNoThrow(size_t cwcMin, bool fForce = false) RT_NOEXCEPT;
790
791 /**
792 * Intended to assign copies of instances to |BSTR| out parameters from
793 * within the interface method. Transfers the ownership of the duplicated
794 * string to the caller.
795 *
796 * If the member string is empty, this allocates an empty BSTR in *pstr
797 * (i.e. makes it point to a new buffer with a null byte).
798 *
799 * @deprecated Use cloneToEx instead to avoid throwing exceptions.
800 */
801 void cloneTo(BSTR *pstr) const
802 {
803 if (pstr)
804 {
805 *pstr = ::SysAllocString((const OLECHAR *)raw()); // raw() returns a pointer to "" if empty
806#ifdef RT_EXCEPTIONS_ENABLED
807 if (!*pstr)
808 throw std::bad_alloc();
809#endif
810 }
811 }
812
813 /**
814 * A version of cloneTo that does not throw any out of memory exceptions, but
815 * returns E_OUTOFMEMORY intead.
816 * @returns S_OK or E_OUTOFMEMORY.
817 */
818 HRESULT cloneToEx(BSTR *pstr) const
819 {
820 if (!pstr)
821 return S_OK;
822 *pstr = ::SysAllocString((const OLECHAR *)raw()); // raw() returns a pointer to "" if empty
823 return pstr ? S_OK : E_OUTOFMEMORY;
824 }
825
826 /**
827 * Intended to assign instances to |BSTR| out parameters from within the
828 * interface method. Transfers the ownership of the original string to the
829 * caller and resets the instance to null.
830 *
831 * As opposed to cloneTo(), this method doesn't create a copy of the
832 * string.
833 *
834 * If the member string is empty, this allocates an empty BSTR in *pstr
835 * (i.e. makes it point to a new buffer with a null byte).
836 *
837 * @param pbstrDst The BSTR variable to detach the string to.
838 *
839 * @throws std::bad_alloc if we failed to allocate a new empty string.
840 */
841 void detachTo(BSTR *pbstrDst)
842 {
843 if (m_bstr)
844 {
845 *pbstrDst = m_bstr;
846 m_bstr = NULL;
847 }
848 else
849 {
850 // allocate null BSTR
851 *pbstrDst = ::SysAllocString((const OLECHAR *)g_bstrEmpty);
852#ifdef RT_EXCEPTIONS_ENABLED
853 if (!*pbstrDst)
854 throw std::bad_alloc();
855#endif
856 }
857 }
858
859 /**
860 * A version of detachTo that does not throw exceptions on out-of-memory
861 * conditions, but instead returns E_OUTOFMEMORY.
862 *
863 * @param pbstrDst The BSTR variable to detach the string to.
864 * @returns S_OK or E_OUTOFMEMORY.
865 */
866 HRESULT detachToEx(BSTR *pbstrDst)
867 {
868 if (m_bstr)
869 {
870 *pbstrDst = m_bstr;
871 m_bstr = NULL;
872 }
873 else
874 {
875 // allocate null BSTR
876 *pbstrDst = ::SysAllocString((const OLECHAR *)g_bstrEmpty);
877 if (!*pbstrDst)
878 return E_OUTOFMEMORY;
879 }
880 return S_OK;
881 }
882
883 /**
884 * Intended to pass instances as |BSTR| out parameters to methods.
885 * Takes the ownership of the returned data.
886 */
887 BSTR *asOutParam()
888 {
889 cleanup();
890 return &m_bstr;
891 }
892
893 /**
894 * Static immutable empty-string object. May be used for comparison purposes.
895 */
896 static const Bstr Empty;
897
898protected:
899
900 void cleanup();
901
902 /**
903 * Protected internal helper to copy a string. This ignores the previous object
904 * state, so either call this from a constructor or call cleanup() first.
905 *
906 * This variant copies from a zero-terminated UTF-16 string (which need not
907 * be a BSTR, i.e. need not have a length prefix).
908 *
909 * If the source is empty, this sets the member string to NULL.
910 *
911 * @param a_bstrSrc The source string. The caller guarantees
912 * that this is valid UTF-16.
913 *
914 * @throws std::bad_alloc - the object is representing an empty string.
915 */
916 void copyFrom(const OLECHAR *a_bstrSrc);
917
918 /** cleanup() + copyFrom() - for assignment operators. */
919 void cleanupAndCopyFrom(const OLECHAR *a_bstrSrc);
920
921 /**
922 * Protected internal helper to copy a string. This ignores the previous object
923 * state, so either call this from a constructor or call cleanup() first.
924 *
925 * This variant copies and converts from a zero-terminated UTF-8 string.
926 *
927 * If the source is empty, this sets the member string to NULL.
928 *
929 * @param a_pszSrc The source string. The caller guarantees
930 * that this is valid UTF-8.
931 *
932 * @throws std::bad_alloc - the object is representing an empty string.
933 */
934 void copyFrom(const char *a_pszSrc)
935 {
936 copyFromN(a_pszSrc, RTSTR_MAX);
937 }
938
939 /**
940 * Variant of copyFrom for sub-string constructors.
941 *
942 * @param a_pszSrc The source string. The caller guarantees
943 * that this is valid UTF-8.
944 * @param a_cchSrc The maximum number of chars (not codepoints) to
945 * copy. If you pass RTSTR_MAX it'll be exactly
946 * like copyFrom().
947 *
948 * @throws std::bad_alloc - the object is representing an empty string.
949 */
950 void copyFromN(const char *a_pszSrc, size_t a_cchSrc);
951
952 Bstr &appendWorkerUtf16(PCRTUTF16 pwszSrc, size_t cwcSrc);
953 Bstr &appendWorkerUtf8(const char *pszSrc, size_t cchSrc);
954 HRESULT appendWorkerUtf16NoThrow(PCRTUTF16 pwszSrc, size_t cwcSrc) RT_NOEXCEPT;
955 HRESULT appendWorkerUtf8NoThrow(const char *pszSrc, size_t cchSrc) RT_NOEXCEPT;
956
957 static DECLCALLBACK(size_t) printfOutputCallbackNoThrow(void *pvArg, const char *pachChars, size_t cbChars) RT_NOEXCEPT;
958
959 BSTR m_bstr;
960
961 friend class Utf8Str; /* to access our raw_copy() */
962};
963
964/* symmetric compare operators */
965inline bool operator==(CBSTR l, const Bstr &r) { return r.operator==(l); }
966inline bool operator!=(CBSTR l, const Bstr &r) { return r.operator!=(l); }
967inline bool operator==(BSTR l, const Bstr &r) { return r.operator==(l); }
968inline bool operator!=(BSTR l, const Bstr &r) { return r.operator!=(l); }
969
970
971
972
973/**
974 * String class used universally in Main for UTF-8 strings.
975 *
976 * This is based on RTCString, to which some functionality has been
977 * moved. Here we keep things that are specific to Main, such as conversions
978 * with UTF-16 strings (Bstr).
979 *
980 * Like RTCString, Utf8Str does not differentiate between NULL strings
981 * and empty strings. In other words, Utf8Str("") and Utf8Str(NULL) behave the
982 * same. In both cases, RTCString allocates no memory, reports
983 * a zero length and zero allocated bytes for both, and returns an empty
984 * C string from c_str().
985 *
986 * @note All Utf8Str methods ASSUMES valid UTF-8 or UTF-16 input strings.
987 * The VirtualBox policy in this regard is to validate strings coming
988 * from external sources before passing them to Utf8Str or Bstr.
989 */
990class Utf8Str : public RTCString
991{
992public:
993
994 Utf8Str() {}
995
996 Utf8Str(const RTCString &that)
997 : RTCString(that)
998 {}
999
1000 Utf8Str(const char *that)
1001 : RTCString(that)
1002 {}
1003
1004 Utf8Str(const Bstr &that)
1005 {
1006 copyFrom(that.raw());
1007 }
1008
1009 Utf8Str(CBSTR that, size_t a_cwcSize = RTSTR_MAX)
1010 {
1011 copyFrom(that, a_cwcSize);
1012 }
1013
1014 Utf8Str(const char *a_pszSrc, size_t a_cchSrc)
1015 : RTCString(a_pszSrc, a_cchSrc)
1016 {
1017 }
1018
1019 /**
1020 * Constructs a new string given the format string and the list of the
1021 * arguments for the format string.
1022 *
1023 * @param a_pszFormat Pointer to the format string (UTF-8),
1024 * @see pg_rt_str_format.
1025 * @param a_va Argument vector containing the arguments
1026 * specified by the format string.
1027 * @sa RTCString::printfV
1028 */
1029 Utf8Str(const char *a_pszFormat, va_list a_va) RT_IPRT_FORMAT_ATTR(1, 0)
1030 : RTCString(a_pszFormat, a_va)
1031 {
1032 }
1033
1034 Utf8Str& operator=(const RTCString &that)
1035 {
1036 RTCString::operator=(that);
1037 return *this;
1038 }
1039
1040 Utf8Str& operator=(const char *that)
1041 {
1042 RTCString::operator=(that);
1043 return *this;
1044 }
1045
1046 Utf8Str& operator=(const Bstr &that)
1047 {
1048 cleanup();
1049 copyFrom(that.raw());
1050 return *this;
1051 }
1052
1053 Utf8Str& operator=(CBSTR that)
1054 {
1055 cleanup();
1056 copyFrom(that);
1057 return *this;
1058 }
1059
1060 /**
1061 * Extended assignment method that returns a COM status code instead of an
1062 * exception on failure.
1063 *
1064 * @returns S_OK or E_OUTOFMEMORY.
1065 * @param a_rSrcStr The source string
1066 */
1067 HRESULT assignEx(Utf8Str const &a_rSrcStr)
1068 {
1069 return copyFromExNComRC(a_rSrcStr.m_psz, 0, a_rSrcStr.m_cch);
1070 }
1071
1072 /**
1073 * Extended assignment method that returns a COM status code instead of an
1074 * exception on failure.
1075 *
1076 * @returns S_OK, E_OUTOFMEMORY or E_INVALIDARG.
1077 * @param a_rSrcStr The source string
1078 * @param a_offSrc The character (byte) offset of the substring.
1079 * @param a_cchSrc The number of characters (bytes) to copy from the source
1080 * string.
1081 */
1082 HRESULT assignEx(Utf8Str const &a_rSrcStr, size_t a_offSrc, size_t a_cchSrc)
1083 {
1084 if ( a_offSrc + a_cchSrc > a_rSrcStr.m_cch
1085 || a_offSrc > a_rSrcStr.m_cch)
1086 return E_INVALIDARG;
1087 return copyFromExNComRC(a_rSrcStr.m_psz, a_offSrc, a_cchSrc);
1088 }
1089
1090 /**
1091 * Extended assignment method that returns a COM status code instead of an
1092 * exception on failure.
1093 *
1094 * @returns S_OK or E_OUTOFMEMORY.
1095 * @param a_pcszSrc The source string
1096 */
1097 HRESULT assignEx(const char *a_pcszSrc)
1098 {
1099 return copyFromExNComRC(a_pcszSrc, 0, a_pcszSrc ? strlen(a_pcszSrc) : 0);
1100 }
1101
1102 /**
1103 * Extended assignment method that returns a COM status code instead of an
1104 * exception on failure.
1105 *
1106 * @returns S_OK or E_OUTOFMEMORY.
1107 * @param a_pcszSrc The source string
1108 * @param a_cchSrc The number of characters (bytes) to copy from the source
1109 * string.
1110 */
1111 HRESULT assignEx(const char *a_pcszSrc, size_t a_cchSrc)
1112 {
1113 return copyFromExNComRC(a_pcszSrc, 0, a_cchSrc);
1114 }
1115
1116 RTMEMEF_NEW_AND_DELETE_OPERATORS();
1117
1118#if defined(VBOX_WITH_XPCOM)
1119 /**
1120 * Intended to assign instances to |char *| out parameters from within the
1121 * interface method. Transfers the ownership of the duplicated string to the
1122 * caller.
1123 *
1124 * This allocates a single 0 byte in the target if the member string is empty.
1125 *
1126 * This uses XPCOM memory allocation and thus only works on XPCOM. MSCOM doesn't
1127 * like char* strings anyway.
1128 */
1129 void cloneTo(char **pstr) const;
1130
1131 /**
1132 * A version of cloneTo that does not throw allocation errors but returns
1133 * E_OUTOFMEMORY instead.
1134 * @returns S_OK or E_OUTOFMEMORY (COM status codes).
1135 */
1136 HRESULT cloneToEx(char **pstr) const;
1137#endif
1138
1139 /**
1140 * Intended to assign instances to |BSTR| out parameters from within the
1141 * interface method. Transfers the ownership of the duplicated string to the
1142 * caller.
1143 */
1144 void cloneTo(BSTR *pstr) const
1145 {
1146 if (pstr)
1147 {
1148 Bstr bstr(*this);
1149 bstr.cloneTo(pstr);
1150 }
1151 }
1152
1153 /**
1154 * A version of cloneTo that does not throw allocation errors but returns
1155 * E_OUTOFMEMORY instead.
1156 *
1157 * @param pbstr Where to store a clone of the string.
1158 * @returns S_OK or E_OUTOFMEMORY (COM status codes).
1159 */
1160 HRESULT cloneToEx(BSTR *pbstr) const
1161 {
1162 if (!pbstr)
1163 return S_OK;
1164 Bstr bstr(*this);
1165 return bstr.detachToEx(pbstr);
1166 }
1167
1168 /**
1169 * Safe assignment from BSTR.
1170 *
1171 * @param pbstrSrc The source string.
1172 * @returns S_OK or E_OUTOFMEMORY (COM status codes).
1173 */
1174 HRESULT cloneEx(CBSTR pbstrSrc)
1175 {
1176 cleanup();
1177 return copyFromEx(pbstrSrc);
1178 }
1179
1180 /**
1181 * Removes a trailing slash from the member string, if present.
1182 * Calls RTPathStripTrailingSlash() without having to mess with mutableRaw().
1183 */
1184 Utf8Str& stripTrailingSlash();
1185
1186 /**
1187 * Removes a trailing filename from the member string, if present.
1188 * Calls RTPathStripFilename() without having to mess with mutableRaw().
1189 */
1190 Utf8Str& stripFilename();
1191
1192 /**
1193 * Removes the path component from the member string, if present.
1194 * Calls RTPathFilename() without having to mess with mutableRaw().
1195 */
1196 Utf8Str& stripPath();
1197
1198 /**
1199 * Removes a trailing file name suffix from the member string, if present.
1200 * Calls RTPathStripSuffix() without having to mess with mutableRaw().
1201 */
1202 Utf8Str& stripSuffix();
1203
1204 /**
1205 * Parses key=value pairs.
1206 *
1207 * @returns offset of the @a a_rPairSeparator following the returned value.
1208 * @retval npos is returned if there are no more key/value pairs.
1209 *
1210 * @param a_rKey Reference to variable that should receive
1211 * the key substring. This is set to null if
1212 * no key/value found. (It's also possible the
1213 * key is an empty string, so be careful.)
1214 * @param a_rValue Reference to variable that should receive
1215 * the value substring. This is set to null if
1216 * no key/value found. (It's also possible the
1217 * value is an empty string, so be careful.)
1218 * @param a_offStart The offset to start searching from. This is
1219 * typically 0 for the first call, and the
1220 * return value of the previous call for the
1221 * subsequent ones.
1222 * @param a_rPairSeparator The pair separator string. If this is an
1223 * empty string, the whole string will be
1224 * considered as a single key/value pair.
1225 * @param a_rKeyValueSeparator The key/value separator string.
1226 */
1227 size_t parseKeyValue(Utf8Str &a_rKey, Utf8Str &a_rValue, size_t a_offStart = 0,
1228 const Utf8Str &a_rPairSeparator = ",", const Utf8Str &a_rKeyValueSeparator = "=") const;
1229
1230 /**
1231 * Static immutable empty-string object. May be used for comparison purposes.
1232 */
1233 static const Utf8Str Empty;
1234protected:
1235
1236 void copyFrom(CBSTR a_pbstr, size_t a_cwcMax = RTSTR_MAX);
1237 HRESULT copyFromEx(CBSTR a_pbstr);
1238 HRESULT copyFromExNComRC(const char *a_pcszSrc, size_t a_offSrc, size_t a_cchSrc);
1239
1240 friend class Bstr; /* to access our raw_copy() */
1241};
1242
1243/**
1244 * Class with RTCString::printf as constructor for your convenience.
1245 *
1246 * Constructing a Utf8Str string object from a format string and a variable
1247 * number of arguments can easily be confused with the other Utf8Str
1248 * constructures, thus this child class.
1249 *
1250 * The usage of this class is like the following:
1251 * @code
1252 Utf8StrFmt strName("program name = %s", argv[0]);
1253 @endcode
1254 */
1255class Utf8StrFmt : public Utf8Str
1256{
1257public:
1258
1259 /**
1260 * Constructs a new string given the format string and the list of the
1261 * arguments for the format string.
1262 *
1263 * @param a_pszFormat Pointer to the format string (UTF-8),
1264 * @see pg_rt_str_format.
1265 * @param ... Ellipsis containing the arguments specified by
1266 * the format string.
1267 */
1268 explicit Utf8StrFmt(const char *a_pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2)
1269 {
1270 va_list va;
1271 va_start(va, a_pszFormat);
1272 printfV(a_pszFormat, va);
1273 va_end(va);
1274 }
1275
1276 RTMEMEF_NEW_AND_DELETE_OPERATORS();
1277
1278protected:
1279 Utf8StrFmt()
1280 { }
1281
1282private:
1283};
1284
1285/**
1286 * Class with Bstr::printf as constructor for your convenience.
1287 */
1288class BstrFmt : public Bstr
1289{
1290public:
1291
1292 /**
1293 * Constructs a new string given the format string and the list of the
1294 * arguments for the format string.
1295 *
1296 * @param a_pszFormat printf-like format string (in UTF-8 encoding), see
1297 * iprt/string.h for details.
1298 * @param ... List of the arguments for the format string.
1299 */
1300 explicit BstrFmt(const char *a_pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2)
1301 {
1302 va_list va;
1303 va_start(va, a_pszFormat);
1304 printfV(a_pszFormat, va);
1305 va_end(va);
1306 }
1307
1308 RTMEMEF_NEW_AND_DELETE_OPERATORS();
1309
1310protected:
1311 BstrFmt()
1312 { }
1313};
1314
1315/**
1316 * Class with Bstr::printfV as constructor for your convenience.
1317 */
1318class BstrFmtVA : public Bstr
1319{
1320public:
1321
1322 /**
1323 * Constructs a new string given the format string and the list of the
1324 * arguments for the format string.
1325 *
1326 * @param a_pszFormat printf-like format string (in UTF-8 encoding), see
1327 * iprt/string.h for details.
1328 * @param a_va List of arguments for the format string
1329 */
1330 BstrFmtVA(const char *a_pszFormat, va_list a_va) RT_IPRT_FORMAT_ATTR(1, 0)
1331 {
1332 printfV(a_pszFormat, a_va);
1333 }
1334
1335 RTMEMEF_NEW_AND_DELETE_OPERATORS();
1336
1337protected:
1338 BstrFmtVA()
1339 { }
1340};
1341
1342} /* namespace com */
1343
1344/** @} */
1345
1346#endif /* !VBOX_INCLUDED_com_string_h */
1347
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette