VirtualBox

Changeset 52546 in vbox


Ignore:
Timestamp:
Sep 1, 2014 8:58:51 AM (10 years ago)
Author:
vboxsync
Message:

VBox/Main: #1909: Independent QMTranslator implementation. Some fixes to Utf8Str (added number of characters to be copied when created from CBSTR without terminating zero), added swap method to RTCString for fast exchange between strings. Makefile for VBoxSVC updated in order to compile with QMTranslatorImpl.cpp

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/string.h

    r52312 r52546  
    514514    }
    515515
    516     Utf8Str(CBSTR that)
    517     {
    518         copyFrom(that);
     516    Utf8Str(CBSTR that, size_t a_cchSize = RTSTR_MAX)
     517    {
     518        copyFrom(that, a_cchSize);
    519519    }
    520520
     
    718718protected:
    719719
    720     void copyFrom(CBSTR a_pbstr);
     720    void copyFrom(CBSTR a_pbstr, size_t a_cchSize = RTSTR_MAX);
    721721    HRESULT copyFromEx(CBSTR a_pbstr);
    722722    HRESULT copyFromExNComRC(const char *a_pcszSrc, size_t a_offSrc, size_t a_cchSrc);
  • trunk/include/iprt/cpp/ministring.h

    r50503 r52546  
    3333
    3434#include <new>
     35#include <utility>
    3536
    3637
     
    876877    static RTCString join(const RTCList<RTCString, RTCString *> &a_rList,
    877878                          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    }
    878891
    879892protected:
  • trunk/src/VBox/Main/Makefile.kmk

    r52244 r52546  
    345345        src-all/PCIDeviceAttachmentImpl.cpp \
    346346        src-all/ProgressImpl.cpp \
     347        src-all/QMTranslatorImpl.cpp \
    347348        src-all/SharedFolderImpl.cpp \
    348349        src-all/AutoCaller.cpp \
  • trunk/src/VBox/Main/glue/string.cpp

    r52312 r52546  
    179179 * @param   a_pbstr         The source string.  The caller guarantees that this
    180180 *                          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.
    181183 *
    182184 * @sa      RTCString::copyFromN
    183185 */
    184 void Utf8Str::copyFrom(CBSTR a_pbstr)
     186void 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 */
     228HRESULT Utf8Str::copyFromEx(CBSTR a_pbstr)
    185229{
    186230    if (a_pbstr && *a_pbstr)
     
    206250            m_psz = NULL;
    207251
    208             throw std::bad_alloc();
    209         }
    210     }
    211     else
    212     {
    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 returns
    221  * 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 string
    232                                   &m_psz,           // char **ppsz: output buffer
    233                                   0,                // size_t cch: if 0, func allocates buffer in *ppsz
    234                                   &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         else
    238         {
    239             if (   vrc != VERR_NO_STR_MEMORY
    240                 && 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 
    250252            return E_OUTOFMEMORY;
    251253        }
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r52312 r52546  
    7777#include "AutoCaller.h"
    7878#include "Logging.h"
     79
     80#include <QMTranslator.h>
    7981
    8082#ifdef RT_OS_WINDOWS
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette