Changeset 52546 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Sep 1, 2014 8:58:51 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/string.cpp
r52312 r52546 179 179 * @param a_pbstr The source string. The caller guarantees that this 180 180 * is valid UTF-16. 181 * @param a_cbSize The number of characters to be copied. If set to RTSTR_MAX, 182 * the entire string will be copied. 181 183 * 182 184 * @sa RTCString::copyFromN 183 185 */ 184 void Utf8Str::copyFrom(CBSTR a_pbstr) 186 void Utf8Str::copyFrom(CBSTR a_pbstr, size_t a_cchSize) 187 { 188 if (a_pbstr && *a_pbstr) 189 { 190 int vrc = RTUtf16ToUtf8Ex((PCRTUTF16)a_pbstr, 191 a_cchSize, // size_t cwcString: translate entire string 192 &m_psz, // char **ppsz: output buffer 193 0, // size_t cch: if 0, func allocates buffer in *ppsz 194 &m_cch); // size_t *pcch: receives the size of the output string, excluding the terminator. 195 if (RT_SUCCESS(vrc)) 196 m_cbAllocated = m_cch + 1; 197 else 198 { 199 if ( vrc != VERR_NO_STR_MEMORY 200 && vrc != VERR_NO_MEMORY) 201 { 202 /* ASSUME: input is valid Utf-16. Fake out of memory error. */ 203 AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTUtf16Len(a_pbstr) * sizeof(RTUTF16), a_pbstr)); 204 } 205 206 m_cch = 0; 207 m_cbAllocated = 0; 208 m_psz = NULL; 209 210 throw std::bad_alloc(); 211 } 212 } 213 else 214 { 215 m_cch = 0; 216 m_cbAllocated = 0; 217 m_psz = NULL; 218 } 219 } 220 221 /** 222 * A variant of Utf8Str::copyFrom that does not throw any exceptions but returns 223 * E_OUTOFMEMORY instead. 224 * 225 * @param a_pbstr The source string. 226 * @returns S_OK or E_OUTOFMEMORY. 227 */ 228 HRESULT Utf8Str::copyFromEx(CBSTR a_pbstr) 185 229 { 186 230 if (a_pbstr && *a_pbstr) … … 206 250 m_psz = NULL; 207 251 208 throw std::bad_alloc();209 }210 }211 else212 {213 m_cch = 0;214 m_cbAllocated = 0;215 m_psz = NULL;216 }217 }218 219 /**220 * A variant of Utf8Str::copyFrom that does not throw any exceptions but returns221 * E_OUTOFMEMORY instead.222 *223 * @param a_pbstr The source string.224 * @returns S_OK or E_OUTOFMEMORY.225 */226 HRESULT Utf8Str::copyFromEx(CBSTR a_pbstr)227 {228 if (a_pbstr && *a_pbstr)229 {230 int vrc = RTUtf16ToUtf8Ex((PCRTUTF16)a_pbstr,231 RTSTR_MAX, // size_t cwcString: translate entire string232 &m_psz, // char **ppsz: output buffer233 0, // size_t cch: if 0, func allocates buffer in *ppsz234 &m_cch); // size_t *pcch: receives the size of the output string, excluding the terminator.235 if (RT_SUCCESS(vrc))236 m_cbAllocated = m_cch + 1;237 else238 {239 if ( vrc != VERR_NO_STR_MEMORY240 && vrc != VERR_NO_MEMORY)241 {242 /* ASSUME: input is valid Utf-16. Fake out of memory error. */243 AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTUtf16Len(a_pbstr) * sizeof(RTUTF16), a_pbstr));244 }245 246 m_cch = 0;247 m_cbAllocated = 0;248 m_psz = NULL;249 250 252 return E_OUTOFMEMORY; 251 253 }
Note:
See TracChangeset
for help on using the changeset viewer.