VirtualBox

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


Ignore:
Timestamp:
Aug 3, 2012 9:56:09 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
79747
Message:

com/string.h: Added assignEx methods similar to cloneEx that returns HRESULT instead of exceptions.

File:
1 edited

Legend:

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

    r40418 r42570  
    241241}
    242242
     243
     244/**
     245 * A variant of Utf8Str::copyFromN that does not throw any exceptions but
     246 * returns E_OUTOFMEMORY instead.
     247 *
     248 * @param   a_pcszSrc   The source string.
     249 * @param   a_cchSrc    The source string.
     250 * @returns S_OK or E_OUTOFMEMORY.
     251 *
     252 * @remarks This calls cleanup() first, so the caller doesn't have to. (Saves
     253 *          code space.)
     254 */
     255HRESULT Utf8Str::copyFromExNComRC(const char *a_pcszSrc, size_t a_cchSrc)
     256{
     257    cleanup();
     258    if (a_cchSrc)
     259    {
     260        m_psz = RTStrAlloc(a_cchSrc + 1);
     261        if (RT_LIKELY(m_psz))
     262        {
     263            m_cch = a_cchSrc;
     264            m_cbAllocated = a_cchSrc + 1;
     265            memcpy(m_psz, a_pcszSrc, a_cchSrc);
     266            m_psz[a_cchSrc] = '\0';
     267        }
     268        else
     269        {
     270            m_cch = 0;
     271            m_cbAllocated = 0;
     272            return E_OUTOFMEMORY;
     273        }
     274    }
     275    else
     276    {
     277        m_cch = 0;
     278        m_cbAllocated = 0;
     279        m_psz = NULL;
     280    }
     281    return S_OK;
     282}
     283
    243284} /* namespace com */
Note: See TracChangeset for help on using the changeset viewer.

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