Changeset 40418 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Mar 9, 2012 10:00:56 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 76749
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/string.cpp
r36530 r40418 85 85 throw std::bad_alloc(); 86 86 memcpy(*pstr, c_str(), cb); 87 } 88 89 HRESULT Utf8Str::cloneToEx(char **pstr) const 90 { 91 size_t cb = length() + 1; 92 *pstr = (char*)nsMemory::Alloc(cb); 93 if (RT_UNLIKELY(!*pstr)) 94 return E_OUTOFMEMORY; 95 memcpy(*pstr, c_str(), cb); 96 return S_OK; 87 97 } 88 98 #endif … … 188 198 } 189 199 200 /** 201 * A variant of Utf8Str::copyFrom that does not throw any exceptions but returns 202 * E_OUTOFMEMORY instead. 203 * 204 * @param a_pbstr The source string. 205 * @returns S_OK or E_OUTOFMEMORY. 206 */ 207 HRESULT Utf8Str::copyFromEx(CBSTR a_pbstr) 208 { 209 if (a_pbstr && *a_pbstr) 210 { 211 int vrc = RTUtf16ToUtf8Ex((PCRTUTF16)a_pbstr, 212 RTSTR_MAX, // size_t cwcString: translate entire string 213 &m_psz, // char **ppsz: output buffer 214 0, // size_t cch: if 0, func allocates buffer in *ppsz 215 &m_cch); // size_t *pcch: receives the size of the output string, excluding the terminator. 216 if (RT_SUCCESS(vrc)) 217 m_cbAllocated = m_cch + 1; 218 else 219 { 220 if ( vrc != VERR_NO_STR_MEMORY 221 && vrc != VERR_NO_MEMORY) 222 { 223 /* ASSUME: input is valid Utf-16. Fake out of memory error. */ 224 AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTUtf16Len(a_pbstr) * sizeof(RTUTF16), a_pbstr)); 225 } 226 227 m_cch = 0; 228 m_cbAllocated = 0; 229 m_psz = NULL; 230 231 return E_OUTOFMEMORY; 232 } 233 } 234 else 235 { 236 m_cch = 0; 237 m_cbAllocated = 0; 238 m_psz = NULL; 239 } 240 return S_OK; 241 } 242 190 243 } /* namespace com */
Note:
See TracChangeset
for help on using the changeset viewer.