Changeset 34846 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Dec 8, 2010 5:50:25 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 68659
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.