VirtualBox

Changeset 67640 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 27, 2017 3:23:45 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
116413
Message:

Utf8Str::parseKeyValue: Docs and style.

File:
1 edited

Legend:

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

    r62485 r67640  
    192192}
    193193
    194 size_t Utf8Str::parseKeyValue(Utf8Str &key, Utf8Str &value, size_t pos, const Utf8Str &pairSeparator, const Utf8Str &keyValueSeparator) const
    195 {
    196     size_t start = pos;
    197     while(start == (pos = find(pairSeparator.c_str(), pos)))
    198         start = ++pos;
    199 
    200     size_t kvSepPos = find(keyValueSeparator.c_str(), start);
    201     if (kvSepPos < pos)
    202     {
    203         key = substr(start, kvSepPos - start);
    204         value = substr(kvSepPos + 1, pos - kvSepPos - 1);
    205     }
    206     else
    207     {
    208         key = value = "";
    209     }
    210     return pos;
     194size_t Utf8Str::parseKeyValue(Utf8Str &a_rKey, Utf8Str &a_rValue, size_t a_offStart /* = 0*/,
     195                              const Utf8Str &a_rPairSeparator /*= ","*/, const Utf8Str &a_rKeyValueSeparator /*= "="*/) const
     196{
     197    /* Find the end of the next pair, skipping empty pairs.
     198       Note! The skipping allows us to pass the return value of a parseKeyValue()
     199             call as offStart to the next call. */
     200    size_t offEnd;
     201    while (   a_offStart == (offEnd = find(a_rPairSeparator.c_str(), a_offStart))
     202           && offEnd != npos)
     203        a_offStart++;
     204
     205    /* Look for a key/value separator before the end of the pair.
     206       ASSUMES npos value returned by find when the substring is not found is
     207       really high. */
     208    size_t offKeyValueSep = find(a_rKeyValueSeparator.c_str(), a_offStart);
     209    if (offKeyValueSep < offEnd)
     210    {
     211        a_rKey   = substr(a_offStart, offKeyValueSep - a_offStart);
     212        a_rValue = substr(offKeyValueSep + 1, offEnd - offKeyValueSep - 1);
     213    }
     214    else
     215    {
     216        a_rKey.setNull();
     217        a_rValue.setNull();
     218    }
     219
     220    return offEnd;
    211221}
    212222
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