7
* Copyright (C) 2006-2011 Oracle Corporation
7
* Copyright (C) 2006-2012 Oracle Corporation
9
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
10
* available from http://www.virtualbox.org. This file is free software;
280
286
* If the member string is empty, this allocates an empty BSTR in *pstr
281
287
* (i.e. makes it point to a new buffer with a null byte).
289
* @deprecated Use cloneToEx instead to avoid throwing exceptions.
283
291
void cloneTo(BSTR *pstr) const
304
* A version of cloneTo that does not throw any out of memory exceptions, but
305
* returns E_OUTOFMEMORY intead.
306
* @returns S_OK or E_OUTOFMEMORY.
308
HRESULT cloneToEx(BSTR *pstr) const
312
*pstr = ::SysAllocString((const OLECHAR *)raw()); // raw() returns a pointer to "" if empty
313
return pstr ? S_OK : E_OUTOFMEMORY;
296
317
* Intended to assign instances to |BSTR| out parameters from within the
297
318
* interface method. Transfers the ownership of the original string to the
298
319
* caller and resets the instance to null.
320
344
throw std::bad_alloc();
350
* A version of detachTo that does not throw exceptions on out-of-memory
351
* conditions, but instead returns E_OUTOFMEMORY.
353
* @param pbstrDst The BSTR variable to detach the string to.
354
* @returns S_OK or E_OUTOFMEMORY.
356
HRESULT detachToEx(BSTR *pbstrDst)
365
// allocate null BSTR
366
*pbstrDst = ::SysAllocString((const OLECHAR *)g_bstrEmpty);
368
return E_OUTOFMEMORY;
513
Utf8Str(const char *a_pszSrc, size_t a_cchSrc)
514
: RTCString(a_pszSrc, a_cchSrc)
467
519
* Constructs a new string given the format string and the list of the
468
520
* arguments for the format string.
507
559
bool operator<(const RTCString &that) const { return RTCString::operator<(that); }
562
* Extended assignment method that returns a COM status code instead of an
563
* exception on failure.
565
* @returns S_OK or E_OUTOFMEMORY.
566
* @param a_rSrcStr The source string
568
HRESULT assignEx(Utf8Str const &a_rSrcStr)
570
return copyFromExNComRC(a_rSrcStr.m_psz, a_rSrcStr.m_cch);
574
* Extended assignment method that returns a COM status code instead of an
575
* exception on failure.
577
* @returns S_OK, E_OUTOFMEMORY or E_INVALIDARG.
578
* @param a_pcszSrc The source string
579
* @param a_offSrc The character (byte) offset of the substring.
580
* @param a_cchSrc The number of characters (bytes) to copy from the source
583
HRESULT assignEx(Utf8Str const &a_rSrcStr, size_t a_offSrc, size_t a_cchSrc)
585
if ( a_offSrc + a_cchSrc > a_rSrcStr.m_cch
586
|| a_offSrc > a_rSrcStr.m_cch)
588
return copyFromExNComRC(a_rSrcStr.m_psz, a_rSrcStr.m_cch);
592
* Extended assignment method that returns a COM status code instead of an
593
* exception on failure.
595
* @returns S_OK or E_OUTOFMEMORY.
596
* @param a_pcszSrc The source string
598
HRESULT assignEx(const char *a_pcszSrc)
600
return copyFromExNComRC(a_pcszSrc, a_pcszSrc ? strlen(a_pcszSrc) : 0);
604
* Extended assignment method that returns a COM status code instead of an
605
* exception on failure.
607
* @returns S_OK or E_OUTOFMEMORY.
608
* @param a_pcszSrc The source string
609
* @param a_cchSrc The number of characters (bytes) to copy from the source
612
HRESULT assignEx(const char *a_pcszSrc, size_t a_cchSrc)
614
return copyFromExNComRC(a_pcszSrc, a_cchSrc);
509
617
RTMEMEF_NEW_AND_DELETE_OPERATORS();
511
619
#if defined(VBOX_WITH_XPCOM)
520
628
* like char* strings anyway.
522
630
void cloneTo(char **pstr) const;
633
* A version of cloneTo that does not throw allocation errors but returns
634
* E_OUTOFMEMORY instead.
635
* @returns S_OK or E_OUTOFMEMORY (COM status codes).
637
HRESULT cloneToEx(char **pstr) const;
655
* A version of cloneTo that does not throw allocation errors but returns
656
* E_OUTOFMEMORY instead.
658
* @param pbstr Where to store a clone of the string.
659
* @returns S_OK or E_OUTOFMEMORY (COM status codes).
661
HRESULT cloneToEx(BSTR *pbstr) const
666
return bstr.detachToEx(pbstr);
670
* Safe assignment from BSTR.
672
* @param pbstrSrc The source string.
673
* @returns S_OK or E_OUTOFMEMORY (COM status codes).
675
HRESULT cloneEx(CBSTR pbstrSrc)
678
return copyFromEx(pbstrSrc);
540
682
* Removes a trailing slash from the member string, if present.
541
683
* Calls RTPathStripTrailingSlash() without having to mess with mutableRaw().
569
711
void copyFrom(CBSTR a_pbstr);
712
HRESULT copyFromEx(CBSTR a_pbstr);
713
HRESULT copyFromExNComRC(const char *a_pcszSrc, size_t a_cchSrc);
571
715
friend class Bstr; /* to access our raw_copy() */