Changeset 935
- Timestamp:
- Feb 6, 2014, 2:05:39 PM (11 years ago)
- Location:
- XmlTools2/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
XmlTools2/trunk/util.h
r926 r935 44 44 //// as the result will be always a. 45 45 //inline const char* toCstr(const QString &myString){ 46 // return myString.to Latin1().constData();46 // return myString.toUtf8().constData(); 47 47 //} 48 48 // Converts a std::string to QString -
XmlTools2/trunk/utilxmltools.cpp
r923 r935 46 46 if(!QFile::exists(file+".bak")){ 47 47 if(!Util::backupFile(file)){ 48 std::cerr << "Couldn't backup file '" << file.to Latin1().constData() << "'. Aborting." << std::endl;48 std::cerr << "Couldn't backup file '" << file.toUtf8().constData() << "'. Aborting." << std::endl; 49 49 exit(1); 50 50 } … … 52 52 else{ 53 53 if(verboseEnabled){ 54 std::cout << "Backup file '" << file.to Latin1().constData() << "'' already exists. Skipping..." << std::endl;54 std::cout << "Backup file '" << file.toUtf8().constData() << "'' already exists. Skipping..." << std::endl; 55 55 } 56 56 } … … 64 64 try 65 65 { 66 selectedNodes = doc.select_nodes(xPathExpression.to Latin1().constData());66 selectedNodes = doc.select_nodes(xPathExpression.toUtf8().constData()); 67 67 } 68 68 … … 91 91 try 92 92 { 93 selectedNode = doc.select_single_node(xPathExpression.to Latin1().constData());93 selectedNode = doc.select_single_node(xPathExpression.toUtf8().constData()); 94 94 } 95 95 … … 108 108 if ((*currNode).name() == filters.getElementName() && (filters.getParentElementName() == "" || filters.getParentElementName() == (*currNode).parent().name()) 109 109 && (filters.getAttributeName() == "" || 110 Util::toQString((*currNode).attribute(filters.getAttributeName().to Latin1().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! 111 111 112 112 result << *currNode; … … 125 125 if ((*currNode).name() == filters.getElementName() && (filters.getParentElementName() == "" || filters.getParentElementName() == (*currNode).parent().name()) 126 126 && (filters.getAttributeName() == "" || 127 Util::toQString((*currNode).attribute(filters.getAttributeName().to Latin1().constData()).value()) == filters.getAttributeValue()) ){127 Util::toQString((*currNode).attribute(filters.getAttributeName().toUtf8().constData()).value()) == filters.getAttributeValue()) ){ 128 128 return *currNode; 129 129 } … … 142 142 void displaySuccessMessage(const int numberOperations, const QString &operation){ 143 143 std::cout << "------------------------------------------------------------------------" << std::endl; 144 std::cout << numberOperations << " " << operation.to Latin1().constData() << " operation(s) completed with success!" << std::endl;144 std::cout << numberOperations << " " << operation.toUtf8().constData() << " operation(s) completed with success!" << std::endl; 145 145 std::cout << "------------------------------------------------------------------------" << std::endl; 146 146 } … … 148 148 void displayErrorMessage(const QString& operation, const QString &message, bool exitProgram){ 149 149 std::cerr << "************************************************************************" << std::endl; 150 std::cerr << operation.to Latin1().constData() << " operation failed!" << std::endl << std::endl;151 std::cerr << message.to Latin1().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; 152 152 if(exitProgram) std::cerr << "Aborting..." << std::endl; 153 153 std::cerr << "************************************************************************" << std::endl; -
XmlTools2/trunk/utilxmltools.h
r923 r935 24 24 inline void loadXmlFile(const QString &file, pugi::xml_document &document, pugi::xml_node &rootNode, bool backupsEnabled, bool verboseEnabled, const QString &operationForErrorMessage){ 25 25 26 pugi::xml_parse_result result = document.load_file(file.to Latin1().constData());26 pugi::xml_parse_result result = document.load_file(file.toUtf8().constData()); 27 27 rootNode=document.root(); 28 28 29 29 if(result.status==pugi::status_ok){ 30 30 if(verboseEnabled){ 31 std::cout << "File '" << file.to Latin1().constData() << "' loaded with sucess." << std::endl;31 std::cout << "File '" << file.toUtf8().constData() << "' loaded with sucess." << std::endl; 32 32 } 33 33 } … … 43 43 44 44 inline void saveXmlFile(const QString &file, pugi::xml_document &document, const QString &operationForErrorMessage){ 45 if(!document.save_file(file.to Latin1().constData(), "\t", pugi::format_indent | pugi::format_save_file_text | pugi::format_no_escapes)){ // output as the system new lines ending45 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 46 46 UtilXmlTools::displayErrorMessage(operationForErrorMessage,"An error ocurred while saving '" + file + "' XML file"); 47 47 } -
XmlTools2/trunk/xmlpatch.cpp
r926 r935 9 9 10 10 if(forceTargetFilesWildcard!=""){ 11 std::cout << "User forced patch in the target file(s): " << forceTargetFilesWildcard.to Latin1().constData() << std::endl;11 std::cout << "User forced patch in the target file(s): " << forceTargetFilesWildcard.toUtf8().constData() << std::endl; 12 12 } 13 13 … … 58 58 } 59 59 60 result=newNode.load(xmlString.to Latin1().constData()); // load xml to insert60 result=newNode.load(xmlString.toUtf8().constData()); // load xml to insert 61 61 62 62 if(result.status!=pugi::status_ok){ -
XmlTools2/trunk/xmltools.cpp
r923 r935 53 53 } 54 54 55 elements[j].text()=QString(Util::toQString(elements[j].text().as_string()) + " " + newValuesList[k]).to Latin1().constData(); // If it doesn't exists yet let's add it55 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 56 56 } 57 57 } … … 99 99 if(elementChanged){ // If curr element changed update the XML 100 100 currValuesList.removeAll(""); // remove all files flagged to deletion 101 elements[j].text()=currValuesList.join(' ').to Latin1().constData();101 elements[j].text()=currValuesList.join(' ').toUtf8().constData(); 102 102 elementChanged=false; 103 103 } … … 141 141 142 142 if(elementChanged){ // If curr element changed update the XML 143 elements[j].text()=currValuesList.join(" ").to Latin1().constData();143 elements[j].text()=currValuesList.join(" ").toUtf8().constData(); 144 144 } 145 145 elementChanged=false; … … 174 174 for(int j=0; j<elements.size(); j++){ 175 175 if(valuePositions!=""){ 176 elements[j].text()=replaceSpecificPositions(value, Util::toQString(elements[j].text().as_string()),valuePositions).to Latin1().constData();176 elements[j].text()=replaceSpecificPositions(value, Util::toQString(elements[j].text().as_string()),valuePositions).toUtf8().constData(); 177 177 } 178 178 else{ 179 elements[j].text()=value.to Latin1().constData();179 elements[j].text()=value.toUtf8().constData(); 180 180 } 181 181 } … … 215 215 currXmlValue=MultiDimVar(Util::toQString(elements[1].text().as_string())); // the currXmlValue will begin to be the second one of the node 216 216 newXmlValue=MultiDimVar::sub(lastXmlValue, MultiDimVar(diffBetweenOldAndNewValue)); 217 elements[0].text() = newXmlValue.toString().to Latin1().constData(); // update the first eblement with the new one already217 elements[0].text() = newXmlValue.toString().toUtf8().constData(); // update the first eblement with the new one already 218 218 } 219 219 … … 222 222 223 223 newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue)); 224 elements[j].text() = newXmlValue.toString().to Latin1().constData(); // update element with the new value224 elements[j].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value 225 225 lastXmlValue=currXmlValue; 226 226 currXmlValue=MultiDimVar(Util::toQString(elements[j+1].text().as_string())); … … 230 230 // To update too last element (avoid out of bound because i+1) 231 231 newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue)); 232 elements[elements.size()-1].text() = newXmlValue.toString().to Latin1().constData(); // update element with the new value232 elements[elements.size()-1].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value 233 233 234 234 UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "update-elements"); … … 264 264 // Override the tree with the inverted order 265 265 for(int j=0; j<elements.size(); j++){ 266 elements[j].text()= invertedElements[j].to Latin1().constData();266 elements[j].text()= invertedElements[j].toUtf8().constData(); 267 267 } 268 268
Note:
See TracChangeset
for help on using the changeset viewer.