Changeset 935


Ignore:
Timestamp:
Feb 6, 2014, 2:05:39 PM (11 years ago)
Author:
s10k
Message:

XmlTools
Oni's Mac folder use a special character (U+0192), because of this I had to change all encoding transformations to UTF8

Location:
XmlTools2/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • XmlTools2/trunk/util.h

    r926 r935  
    4444//// as the result will be always a.
    4545//inline const char* toCstr(const QString &myString){
    46 //    return myString.toLatin1().constData();
     46//    return myString.toUtf8().constData();
    4747//}
    4848// Converts a std::string to QString
  • XmlTools2/trunk/utilxmltools.cpp

    r923 r935  
    4646    if(!QFile::exists(file+".bak")){
    4747        if(!Util::backupFile(file)){
    48             std::cerr << "Couldn't backup file '" << file.toLatin1().constData() << "'. Aborting." << std::endl;
     48            std::cerr << "Couldn't backup file '" << file.toUtf8().constData() << "'. Aborting." << std::endl;
    4949            exit(1);
    5050        }
     
    5252    else{
    5353        if(verboseEnabled){
    54             std::cout << "Backup file '" << file.toLatin1().constData() << "'' already exists. Skipping..." << std::endl;
     54            std::cout << "Backup file '" << file.toUtf8().constData() << "'' already exists. Skipping..." << std::endl;
    5555        }
    5656    }
     
    6464    try
    6565    {
    66         selectedNodes = doc.select_nodes(xPathExpression.toLatin1().constData());
     66        selectedNodes = doc.select_nodes(xPathExpression.toUtf8().constData());
    6767    }
    6868
     
    9191    try
    9292    {
    93         selectedNode = doc.select_single_node(xPathExpression.toLatin1().constData());
     93        selectedNode = doc.select_single_node(xPathExpression.toUtf8().constData());
    9494    }
    9595
     
    108108        if ((*currNode).name() == filters.getElementName() && (filters.getParentElementName() == "" || filters.getParentElementName() == (*currNode).parent().name())
    109109                && (filters.getAttributeName() == "" ||
    110                     Util::toQString((*currNode).attribute(filters.getAttributeName().toLatin1().constData()).value()) == filters.getAttributeValue()) ){ // Seems node attribute must be converted to qtsring to remove \r\n needs to check in future!
     110                    Util::toQString((*currNode).attribute(filters.getAttributeName().toUtf8().constData()).value()) == filters.getAttributeValue()) ){ // Seems node attribute must be converted to qtsring to remove \r\n needs to check in future!
    111111
    112112            result << *currNode;
     
    125125        if ((*currNode).name() == filters.getElementName() && (filters.getParentElementName() == "" || filters.getParentElementName() == (*currNode).parent().name())
    126126                && (filters.getAttributeName() == "" ||
    127                     Util::toQString((*currNode).attribute(filters.getAttributeName().toLatin1().constData()).value()) == filters.getAttributeValue()) ){
     127                    Util::toQString((*currNode).attribute(filters.getAttributeName().toUtf8().constData()).value()) == filters.getAttributeValue()) ){
    128128            return *currNode;
    129129        }
     
    142142void displaySuccessMessage(const int numberOperations, const QString &operation){
    143143    std::cout << "------------------------------------------------------------------------" << std::endl;
    144     std::cout << numberOperations << " " << operation.toLatin1().constData() << " operation(s) completed with success!" << std::endl;
     144    std::cout << numberOperations << " " << operation.toUtf8().constData() << " operation(s) completed with success!" << std::endl;
    145145    std::cout << "------------------------------------------------------------------------" << std::endl;
    146146}
     
    148148void displayErrorMessage(const QString& operation, const QString &message, bool exitProgram){
    149149    std::cerr << "************************************************************************" << std::endl;
    150     std::cerr << operation.toLatin1().constData() << " operation failed!" << std::endl << std::endl;
    151     std::cerr << message.toLatin1().constData() << std::endl << std::endl;
     150    std::cerr << operation.toUtf8().constData() << " operation failed!" << std::endl << std::endl;
     151    std::cerr << message.toUtf8().constData() << std::endl << std::endl;
    152152    if(exitProgram) std::cerr << "Aborting..." << std::endl;
    153153    std::cerr << "************************************************************************" << std::endl;
  • XmlTools2/trunk/utilxmltools.h

    r923 r935  
    2424inline void loadXmlFile(const QString &file, pugi::xml_document &document, pugi::xml_node &rootNode, bool backupsEnabled, bool verboseEnabled, const QString &operationForErrorMessage){
    2525
    26     pugi::xml_parse_result result = document.load_file(file.toLatin1().constData());
     26    pugi::xml_parse_result result = document.load_file(file.toUtf8().constData());
    2727    rootNode=document.root();
    2828
    2929    if(result.status==pugi::status_ok){
    3030        if(verboseEnabled){
    31             std::cout << "File '" << file.toLatin1().constData() << "' loaded with sucess." << std::endl;
     31            std::cout << "File '" << file.toUtf8().constData() << "' loaded with sucess." << std::endl;
    3232        }
    3333    }
     
    4343
    4444inline void saveXmlFile(const QString &file, pugi::xml_document &document, const QString &operationForErrorMessage){
    45     if(!document.save_file(file.toLatin1().constData(), "\t", pugi::format_indent | pugi::format_save_file_text | pugi::format_no_escapes)){ // output as the system new lines ending
     45    if(!document.save_file(file.toUtf8().constData(), "\t", pugi::format_indent | pugi::format_save_file_text | pugi::format_no_escapes)){ // output as the system new lines ending
    4646        UtilXmlTools::displayErrorMessage(operationForErrorMessage,"An error ocurred while saving '" + file + "' XML file");
    4747    }
  • XmlTools2/trunk/xmlpatch.cpp

    r926 r935  
    99
    1010    if(forceTargetFilesWildcard!=""){
    11         std::cout << "User forced patch in the target file(s): " << forceTargetFilesWildcard.toLatin1().constData() << std::endl;
     11        std::cout << "User forced patch in the target file(s): " << forceTargetFilesWildcard.toUtf8().constData() << std::endl;
    1212    }
    1313
     
    5858    }
    5959
    60     result=newNode.load(xmlString.toLatin1().constData()); // load xml to insert
     60    result=newNode.load(xmlString.toUtf8().constData()); // load xml to insert
    6161
    6262    if(result.status!=pugi::status_ok){
  • XmlTools2/trunk/xmltools.cpp

    r923 r935  
    5353                }
    5454
    55                 elements[j].text()=QString(Util::toQString(elements[j].text().as_string()) + " " + newValuesList[k]).toLatin1().constData(); // If it doesn't exists yet let's add it
     55                elements[j].text()=QString(Util::toQString(elements[j].text().as_string()) + " " + newValuesList[k]).toUtf8().constData(); // If it doesn't exists yet let's add it
    5656            }
    5757        }
     
    9999            if(elementChanged){ // If curr element changed update the XML
    100100                currValuesList.removeAll(""); // remove all files flagged to deletion
    101                 elements[j].text()=currValuesList.join(' ').toLatin1().constData();
     101                elements[j].text()=currValuesList.join(' ').toUtf8().constData();
    102102                elementChanged=false;
    103103            }
     
    141141
    142142            if(elementChanged){ // If curr element changed update the XML
    143                 elements[j].text()=currValuesList.join(" ").toLatin1().constData();
     143                elements[j].text()=currValuesList.join(" ").toUtf8().constData();
    144144            }
    145145            elementChanged=false;
     
    174174        for(int j=0; j<elements.size(); j++){
    175175            if(valuePositions!=""){
    176                 elements[j].text()=replaceSpecificPositions(value, Util::toQString(elements[j].text().as_string()),valuePositions).toLatin1().constData();
     176                elements[j].text()=replaceSpecificPositions(value, Util::toQString(elements[j].text().as_string()),valuePositions).toUtf8().constData();
    177177            }
    178178            else{
    179                 elements[j].text()=value.toLatin1().constData();
     179                elements[j].text()=value.toUtf8().constData();
    180180            }
    181181        }
     
    215215            currXmlValue=MultiDimVar(Util::toQString(elements[1].text().as_string())); // the currXmlValue will begin to be the second one of the node
    216216            newXmlValue=MultiDimVar::sub(lastXmlValue, MultiDimVar(diffBetweenOldAndNewValue));
    217             elements[0].text() = newXmlValue.toString().toLatin1().constData(); // update the first eblement with the new one already
     217            elements[0].text() = newXmlValue.toString().toUtf8().constData(); // update the first eblement with the new one already
    218218        }
    219219
     
    222222
    223223            newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue));
    224             elements[j].text() = newXmlValue.toString().toLatin1().constData(); // update element with the new value
     224            elements[j].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value
    225225            lastXmlValue=currXmlValue;
    226226            currXmlValue=MultiDimVar(Util::toQString(elements[j+1].text().as_string()));
     
    230230        // To update too last element (avoid out of bound because i+1)
    231231        newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue));
    232         elements[elements.size()-1].text() = newXmlValue.toString().toLatin1().constData(); // update element with the new value
     232        elements[elements.size()-1].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value
    233233
    234234        UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "update-elements");
     
    264264        // Override the tree with the inverted order
    265265        for(int j=0; j<elements.size(); j++){
    266             elements[j].text()= invertedElements[j].toLatin1().constData();
     266            elements[j].text()= invertedElements[j].toUtf8().constData();
    267267        }
    268268
Note: See TracChangeset for help on using the changeset viewer.