VirtualBox

Changeset 35128 in vbox


Ignore:
Timestamp:
Dec 15, 2010 12:38:41 PM (14 years ago)
Author:
vboxsync
Message:

Main: more backslash conversion in settings read/write, so add generic methods to XML classes

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/string.h

    r34846 r35128  
    552552
    553553    /**
    554      * Converts all '\' characters into '/'.
    555      */
    556     Utf8Str& useForwardSlashes();
    557 
    558     /**
    559554     *  Static immutable empty-string object. May be used for comparison purposes.
    560555     */
  • trunk/include/iprt/cpp/ministring.h

    r34785 r35128  
    664664
    665665    /**
     666     * Replaces all occurences of cFind with cReplace in the member string.
     667     * In order not to produce invalid UTF-8, the characters must be ASCII
     668     * values less than 128; this is not verified.
     669     *
     670     * @param cFind Character to replace. Must be ASCII < 128.
     671     * @param cReplace Character to replace cFind with. Must be ASCII < 128.
     672     */
     673    void findReplace(char cFind, char cReplace);
     674
     675    /**
    666676     * Returns a substring of "this" as a new Utf8Str.
    667677     *
  • trunk/include/iprt/cpp/xml.h

    r33835 r35128  
    454454    bool getAttributeValue(const char *pcszMatch, const char *&ppcsz) const;
    455455    bool getAttributeValue(const char *pcszMatch, iprt::MiniString &str) const;
     456    bool getAttributeValuePath(const char *pcszMatch, iprt::MiniString &str) const;
    456457    bool getAttributeValue(const char *pcszMatch, int32_t &i) const;
    457458    bool getAttributeValue(const char *pcszMatch, uint32_t &i) const;
     
    473474        return setAttribute(pcszName, strValue.c_str());
    474475    }
     476    AttributeNode* setAttributePath(const char *pcszName, const iprt::MiniString &strValue);
    475477    AttributeNode* setAttribute(const char *pcszName, int32_t i);
    476478    AttributeNode* setAttribute(const char *pcszName, uint32_t i);
  • trunk/src/VBox/Main/glue/string.cpp

    r34846 r35128  
    133133}
    134134
    135 Utf8Str& Utf8Str::useForwardSlashes()
    136 {
    137     for (size_t i = 0; i < length(); ++i)
    138     {
    139         char *p = &m_psz[i];
    140         if (*p == '\\')
    141             *p = '/';
    142     }
    143 
    144     return *this;
    145 }
    146 
    147135/**
    148136 * Internal function used in Utf8Str copy constructors and assignment when
  • trunk/src/VBox/Main/xml/Settings.cpp

    r35123 r35128  
    647647            if (fNeedsFilePath)
    648648            {
    649                 if (!(pelmImage->getAttributeValue("filePath", med.strLocation)))
     649                if (!(pelmImage->getAttributeValuePath("filePath", med.strLocation)))
    650650                    throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
    651                 else
    652                     // IPRT can handle forward slashes in file paths everywhere, but there might be
    653                     // backslashes in the settings file, so convert them into forward slashes.
    654                     med.strLocation.useForwardSlashes();
    655651            }
    656652        }
     
    10111007    pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
    10121008
    1013     // always use forward slashes when writing out settings, never '\'
    1014     Utf8Str strLocation(mdm.strLocation);
    1015     strLocation.useForwardSlashes();
    1016     pelmMedium->setAttribute("location", strLocation);
     1009    pelmMedium->setAttributePath("location", mdm.strLocation);
    10171010
    10181011    pelmMedium->setAttribute("format", mdm.strFormat);
     
    30613054    parseTimestamp(snap.timestamp, strTemp);
    30623055
    3063     elmSnapshot.getAttributeValue("stateFile", snap.strStateFile);      // online snapshots only
     3056    elmSnapshot.getAttributeValuePath("stateFile", snap.strStateFile);      // online snapshots only
    30643057
    30653058    // parse Hardware before the other elements because other things depend on it
     
    31843177            convertOldOSType_pre1_5(machineUserData.strOsType);
    31853178
    3186         elmMachine.getAttributeValue("stateFile", strStateFile);
     3179        elmMachine.getAttributeValuePath("stateFile", strStateFile);
     3180
    31873181        if (elmMachine.getAttributeValue("currentSnapshot", str))
    31883182            parseUUID(uuidCurrentSnapshot, str);
    31893183
    3190         elmMachine.getAttributeValue("snapshotFolder", machineUserData.strSnapshotFolder);
    3191         // IPRT can handle forward slashes in file paths everywhere, but there might be
    3192         // backslashes in the settings file, so convert them into forward slashes.
    3193         machineUserData.strSnapshotFolder.useForwardSlashes();
     3184        elmMachine.getAttributeValuePath("snapshotFolder", machineUserData.strSnapshotFolder);
    31943185
    31953186        if (!elmMachine.getAttributeValue("currentStateModified", fCurrentStateModified))
     
    41224113
    41234114    if (snap.strStateFile.length())
    4124         pelmSnapshot->setAttribute("stateFile", snap.strStateFile);
     4115        pelmSnapshot->setAttributePath("stateFile", snap.strStateFile);
    41254116
    41264117    if (snap.strDescription.length())
     
    42104201         && !(fl & BuildMachineXML_SuppressSavedState)
    42114202       )
    4212         elmMachine.setAttribute("stateFile", strStateFile);
     4203        elmMachine.setAttributePath("stateFile", strStateFile);
    42134204    if (    (fl & BuildMachineXML_IncludeSnapshots)
    42144205         && !uuidCurrentSnapshot.isEmpty())
     
    42164207
    42174208    if (machineUserData.strSnapshotFolder.length())
    4218     {
    4219         // always use forward slashes when writing out settings, never '\'
    4220         Utf8Str strSnapshotFolder(machineUserData.strSnapshotFolder);
    4221         strSnapshotFolder.useForwardSlashes();
    4222         elmMachine.setAttribute("snapshotFolder", strSnapshotFolder);
    4223     }
     4209        elmMachine.setAttributePath("snapshotFolder", machineUserData.strSnapshotFolder);
    42244210    if (!fCurrentStateModified)
    42254211        elmMachine.setAttribute("currentStateModified", fCurrentStateModified);
  • trunk/src/VBox/Runtime/common/string/ministring.cpp

    r33605 r35128  
    212212
    213213    return npos;
     214}
     215
     216void MiniString::findReplace(char cFind, char cReplace)
     217{
     218    for (size_t i = 0; i < length(); ++i)
     219    {
     220        char *p = &m_psz[i];
     221        if (*p == cFind)
     222            *p = cReplace;
     223    }
    214224}
    215225
  • trunk/src/VBox/Runtime/r3/xml.cpp

    r33835 r35128  
    831831    {
    832832        str = pAttr->getValue();
     833        return true;
     834    }
     835
     836    return false;
     837}
     838
     839/**
     840 * Like getAttributeValue (ministring variant), but makes sure that all backslashes
     841 * are converted to forward slashes.
     842 * @param pcszMatch
     843 * @param str
     844 * @return
     845 */
     846bool ElementNode::getAttributeValuePath(const char *pcszMatch, iprt::MiniString &str) const
     847{
     848    if (getAttributeValue(pcszMatch, str))
     849    {
     850        str.findReplace('\\', '/');
    833851        return true;
    834852    }
     
    10541072
    10551073/**
     1074 * Like setAttribute (ministring variant), but replaces all backslashes with forward slashes
     1075 * before calling that one.
     1076 * @param pcszName
     1077 * @param strValue
     1078 * @return
     1079 */
     1080AttributeNode* ElementNode::setAttributePath(const char *pcszName, const iprt::MiniString &strValue)
     1081{
     1082    iprt::MiniString strTemp(strValue);
     1083    strTemp.findReplace('\\', '/');
     1084    return setAttribute(pcszName, strTemp.c_str());
     1085}
     1086
     1087/**
    10561088 * Sets the given attribute; overloaded version for int32_t.
    10571089 *
Note: See TracChangeset for help on using the changeset viewer.

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