Changeset 52546 in vbox
- Timestamp:
- Sep 1, 2014 8:58:51 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r52312 r52546 514 514 } 515 515 516 Utf8Str(CBSTR that )517 { 518 copyFrom(that );516 Utf8Str(CBSTR that, size_t a_cchSize = RTSTR_MAX) 517 { 518 copyFrom(that, a_cchSize); 519 519 } 520 520 … … 718 718 protected: 719 719 720 void copyFrom(CBSTR a_pbstr );720 void copyFrom(CBSTR a_pbstr, size_t a_cchSize = RTSTR_MAX); 721 721 HRESULT copyFromEx(CBSTR a_pbstr); 722 722 HRESULT copyFromExNComRC(const char *a_pcszSrc, size_t a_offSrc, size_t a_cchSrc); -
trunk/include/iprt/cpp/ministring.h
r50503 r52546 33 33 34 34 #include <new> 35 #include <utility> 35 36 36 37 … … 876 877 static RTCString join(const RTCList<RTCString, RTCString *> &a_rList, 877 878 const RTCString &a_rstrSep = ""); 879 880 /* Swaps the values of the two strings. 881 * Used instead of copying when the string which 882 * is copied will no longer be needed after copying 883 * Both of two strings remain valid. 884 * The method is exception-safe */ 885 inline void swap(RTCString &that) throw() 886 { 887 std::swap(m_psz, that.m_psz); 888 std::swap(m_cch, that.m_cch); 889 std::swap(m_cbAllocated, that.m_cbAllocated); 890 } 878 891 879 892 protected: -
trunk/src/VBox/Main/Makefile.kmk
r52244 r52546 345 345 src-all/PCIDeviceAttachmentImpl.cpp \ 346 346 src-all/ProgressImpl.cpp \ 347 src-all/QMTranslatorImpl.cpp \ 347 348 src-all/SharedFolderImpl.cpp \ 348 349 src-all/AutoCaller.cpp \ -
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 } -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r52312 r52546 77 77 #include "AutoCaller.h" 78 78 #include "Logging.h" 79 80 #include <QMTranslator.h> 79 81 80 82 #ifdef RT_OS_WINDOWS
Note:
See TracChangeset
for help on using the changeset viewer.