Changeset 34846 in vbox
- Timestamp:
- Dec 8, 2010 5:50:25 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 68659
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r34837 r34846 125 125 } 126 126 127 Bstr(const char *a_pThat, size_t a_cchMax) 128 { 129 copyFromN(a_pThat, a_cchMax); 130 } 131 127 132 ~Bstr() 128 133 { … … 389 394 } 390 395 396 /** 397 * Variant of copyFrom for sub-string constructors. 398 * 399 * @param a_pszSrc The source string. 400 * @param a_cchMax The maximum number of chars (not 401 * codepoints) to copy. If you pass RTSTR_MAX 402 * it'll be exactly like copyFrom(). 403 * @throws std::bad_alloc 404 */ 405 void copyFromN(const char *a_pszSrc, size_t a_cchSrc); 406 391 407 BSTR m_bstr; 392 408 -
trunk/src/VBox/Main/glue/string.cpp
r34837 r34846 36 36 const Bstr Bstr::Empty; /* default ctor is OK */ 37 37 38 void Bstr::copyFromN(const char *a_pszSrc, size_t a_cchMax) 39 { 40 /* 41 * Initialie m_bstr first in case of throws further down in the code, then 42 * check for empty input (m_bstr == NULL means empty, there are no NULL 43 * strings). 44 */ 45 m_bstr = NULL; 46 if (!a_cchMax || !a_pszSrc || !*a_pszSrc) 47 return; 48 49 /* 50 * Calculate the length and allocate a BSTR string buffer of the right 51 * size, i.e. optimize heap usage. 52 */ 53 size_t cwc; 54 int vrc = ::RTStrCalcUtf16LenEx(a_pszSrc, a_cchMax, &cwc); 55 AssertRCReturnVoid(vrc); /* throw instead? */ 56 57 m_bstr = ::SysAllocStringByteLen(NULL, cwc * sizeof(OLECHAR)); 58 if (m_bstr) 59 { 60 PRTUTF16 pwsz = (PRTUTF16)m_bstr; 61 vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL); 62 if (RT_FAILURE(vrc)) 63 { 64 /* This should not happen! */ 65 AssertRC(vrc); 66 cleanup(); 67 } 68 } 69 else 70 throw std::bad_alloc(); 71 } 72 73 38 74 /* static */ 39 75 const Utf8Str Utf8Str::Empty; /* default ctor is OK */ 40 76 41 #if defined 77 #if defined(VBOX_WITH_XPCOM) 42 78 void Utf8Str::cloneTo(char **pstr) const 43 79 {
Note:
See TracChangeset
for help on using the changeset viewer.