VirtualBox

Ignore:
Timestamp:
Mar 15, 2016 10:39:16 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106008
Message:

iprt: Added simple (and untested) RTAsn1Integer_ToString implemented. Added spacing flags to RTStrPrintHexBytes (also untested).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/RTStrPrintHexBytes.cpp

    r57358 r60028  
    55
    66/*
    7  * Copyright (C) 2009-2015 Oracle Corporation
     7 * Copyright (C) 2009-2016 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3636
    3737
    38 RTDECL(int) RTStrPrintHexBytes(char *pszBuf, size_t cchBuf, void const *pv, size_t cb, uint32_t fFlags)
     38RTDECL(int) RTStrPrintHexBytes(char *pszBuf, size_t cbBuf, void const *pv, size_t cb, uint32_t fFlags)
    3939{
    40     AssertReturn(!(fFlags & ~RTSTRPRINTHEXBYTES_F_UPPER), VERR_INVALID_PARAMETER);
     40    AssertReturn(   !(fFlags & ~(RTSTRPRINTHEXBYTES_F_UPPER | RTSTRPRINTHEXBYTES_F_SEP_SPACE | RTSTRPRINTHEXBYTES_F_SEP_COLON))
     41                 &&    (fFlags & (RTSTRPRINTHEXBYTES_F_SEP_SPACE | RTSTRPRINTHEXBYTES_F_SEP_COLON))
     42                    != (RTSTRPRINTHEXBYTES_F_SEP_SPACE | RTSTRPRINTHEXBYTES_F_SEP_COLON),
     43                 VERR_INVALID_FLAGS);
    4144    AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
    4245    AssertReturn(cb * 2 >= cb, VERR_BUFFER_OVERFLOW);
    43     AssertReturn(cchBuf >= cb * 2 + 1, VERR_BUFFER_OVERFLOW);
     46    char const chSep = fFlags & RTSTRPRINTHEXBYTES_F_SEP_SPACE ? ' '
     47                     : fFlags & RTSTRPRINTHEXBYTES_F_SEP_COLON ? ':' : '\0';
     48    AssertReturn(cbBuf >= cb * (2 + (chSep != '\0')) - (chSep != '\0') + 1, VERR_BUFFER_OVERFLOW);
    4449    if (cb)
    4550        AssertPtrReturn(pv, VERR_INVALID_POINTER);
     
    5055
    5156    uint8_t const *pb = (uint8_t const *)pv;
    52     while (cb-- > 0)
     57
     58    if (!chSep)
     59    {
     60        while (cb-- > 0)
     61        {
     62            uint8_t b = *pb++;
     63            *pszBuf++ = pszHexDigits[b >> 4];
     64            *pszBuf++ = pszHexDigits[b & 0xf];
     65        }
     66    }
     67    else if (cb-- > 0)
    5368    {
    5469        uint8_t b = *pb++;
    5570        *pszBuf++ = pszHexDigits[b >> 4];
    5671        *pszBuf++ = pszHexDigits[b & 0xf];
     72
     73        while (cb-- > 0)
     74        {
     75            b = *pb++;
     76            *pszBuf++ = chSep;
     77            *pszBuf++ = pszHexDigits[b >> 4];
     78            *pszBuf++ = pszHexDigits[b & 0xf];
     79        }
    5780    }
     81
    5882    *pszBuf = '\0';
    5983    return VINF_SUCCESS;
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