VirtualBox

Changeset 85306 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Jul 13, 2020 12:10:02 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139284
Message:

Main/comimpl.xsl,++: Make it possible to pass Utf8Str rather that IN_BSTR to the event creation/fire/reinit functions. bugref:9790

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/string.cpp

    r85288 r85306  
    185185    throw std::bad_alloc();
    186186}
     187
     188HRESULT Bstr::cleanupAndCopyFromNoThrow(const char *a_pszSrc, size_t a_cchMax) RT_NOEXCEPT
     189{
     190    /*
     191     * Check for empty input (m_bstr == NULL means empty, there are no NULL strings).
     192     */
     193    cleanup();
     194    if (!a_cchMax || !a_pszSrc || !*a_pszSrc)
     195        return S_OK;
     196
     197    /*
     198     * Calculate the length and allocate a BSTR string buffer of the right
     199     * size, i.e. optimize heap usage.
     200     */
     201    HRESULT hrc;
     202    size_t cwc;
     203    int vrc = ::RTStrCalcUtf16LenEx(a_pszSrc, a_cchMax, &cwc);
     204    if (RT_SUCCESS(vrc))
     205    {
     206        m_bstr = ::SysAllocStringByteLen(NULL, (unsigned)(cwc * sizeof(OLECHAR)));
     207        if (RT_LIKELY(m_bstr))
     208        {
     209            PRTUTF16 pwsz = (PRTUTF16)m_bstr;
     210            vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL);
     211            if (RT_SUCCESS(vrc))
     212                return S_OK;
     213
     214            /* This should not happen! */
     215            AssertRC(vrc);
     216            cleanup();
     217            hrc = E_UNEXPECTED;
     218        }
     219        else
     220            hrc = E_OUTOFMEMORY;
     221    }
     222    else
     223    {
     224        /* Unexpected: Invalid UTF-8 input. */
     225        AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTStrNLen(a_pszSrc, a_cchMax), a_pszSrc));
     226        hrc = E_UNEXPECTED;
     227    }
     228    return hrc;
     229}
     230
    187231
    188232int Bstr::compareUtf8(const char *a_pszRight, CaseSensitivity a_enmCase /*= CaseSensitive*/) const
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