VirtualBox

Changeset 50503 in vbox


Ignore:
Timestamp:
Feb 19, 2014 8:35:27 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92345
Message:

IPRT/ministring: Added RTCString::joinEx().

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/ministring.h

    r48076 r50503  
    44
    55/*
    6  * Copyright (C) 2007-2012 Oracle Corporation
     6 * Copyright (C) 2007-2014 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    853853    RTCList<RTCString, RTCString *> split(const RTCString &a_rstrSep,
    854854                                          SplitMode a_enmMode = RemoveEmptyParts) const;
     855
     856    /**
     857     * Joins a list of strings together using the provided separator and
     858     * an optional prefix for each item in the list.
     859     *
     860     * @param   a_rList         The list to join.
     861     * @param   a_rstrPrefix    The prefix used for appending to each item.
     862     * @param   a_rstrSep       The separator used for joining.
     863     * @returns joined string.
     864     */
     865    static RTCString joinEx(const RTCList<RTCString, RTCString *> &a_rList,
     866                            const RTCString &a_rstrPrefix /* = "" */,
     867                            const RTCString &a_rstrSep /* = "" */);
    855868
    856869    /**
  • trunk/src/VBox/Runtime/common/string/ministring.cpp

    r40417 r50503  
    88
    99/*
    10  * Copyright (C) 2007-2012 Oracle Corporation
     10 * Copyright (C) 2007-2014 Oracle Corporation
    1111 *
    1212 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    395395/* static */
    396396RTCString
    397 RTCString::join(const RTCList<RTCString, RTCString *> &a_rList,
    398                 const RTCString &a_rstrSep /* = "" */)
     397RTCString::joinEx(const RTCList<RTCString, RTCString *> &a_rList,
     398                  const RTCString &a_rstrPrefix /* = "" */,
     399                  const RTCString &a_rstrSep /* = "" */)
    399400{
    400401    RTCString strRet;
     
    403404        /* calc the required size */
    404405        size_t cbNeeded = a_rstrSep.length() * (a_rList.size() - 1) + 1;
     406        cbNeeded += a_rstrPrefix.length() * (a_rList.size() - 1) + 1;
    405407        for (size_t i = 0; i < a_rList.size(); ++i)
    406408            cbNeeded += a_rList.at(i).length();
     
    410412        for (size_t i = 0; i < a_rList.size() - 1; ++i)
    411413        {
     414            if (a_rstrPrefix.isNotEmpty())
     415                strRet.append(a_rstrPrefix);
    412416            strRet.append(a_rList.at(i));
    413417            strRet.append(a_rstrSep);
     
    417421    /* special case: one list item. */
    418422    else if (a_rList.size() > 0)
     423    {
     424        if (a_rstrPrefix.isNotEmpty())
     425            strRet.append(a_rstrPrefix);
    419426        strRet.append(a_rList.last());
     427    }
    420428
    421429    return strRet;
     430}
     431
     432/* static */
     433RTCString
     434RTCString::join(const RTCList<RTCString, RTCString *> &a_rList,
     435                const RTCString &a_rstrSep /* = "" */)
     436{
     437    return RTCString::joinEx(a_rList,
     438                             "" /* a_rstrPrefix */, a_rstrSep);
    422439}
    423440
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