VirtualBox

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


Ignore:
Timestamp:
May 13, 2020 1:59:34 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137924
Message:

Glue/Bstr: Adding a base64Encode method using the new UTF-16 base64 encoding functions in IPRT. bugref:9224

File:
1 edited

Legend:

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

    r83785 r84287  
    1818#include "VBox/com/string.h"
    1919
     20#include <iprt/base64.h>
    2021#include <iprt/err.h>
     22#include <iprt/log.h>
    2123#include <iprt/path.h>
    22 #include <iprt/log.h>
    2324#include <iprt/string.h>
    2425#include <iprt/uni.h>
     
    228229        return ucLeft < ucRight ? -1 : 1;
    229230    }
     231}
     232
     233HRESULT Bstr::base64Encode(const void *pvData, size_t cbData, bool fLineBreaks /*= false*/)
     234{
     235    uint32_t const fFlags     = fLineBreaks ? RTBASE64_FLAGS_EOL_LF : RTBASE64_FLAGS_NO_LINE_BREAKS;
     236    size_t         cwcEncoded = RTBase64EncodedUtf16LengthEx(cbData, fFlags);
     237    HRESULT hrc = reserveNoThrow(cwcEncoded + 1);
     238    if (SUCCEEDED(hrc))
     239    {
     240        int vrc = RTBase64EncodeUtf16Ex(pvData, cbData, fFlags, mutableRaw(), cwcEncoded, &cwcEncoded);
     241        AssertRCReturnStmt(vrc, setNull(), E_FAIL);
     242        hrc = joltNoThrow(cwcEncoded);
     243    }
     244    return hrc;
    230245}
    231246
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