streamlet-examples/xpath.cpp
branchv_0
changeset 75 ecbf6504915c
parent 74 a2aa84f310a5
child 77 a680bcd946cd
--- a/streamlet-examples/xpath.cpp	Wed Jan 29 20:50:12 2020 +0100
+++ b/streamlet-examples/xpath.cpp	Thu Jan 30 14:19:14 2020 +0100
@@ -53,8 +53,8 @@
 	}
 
 	void findXmlnsInOptions() {
-		for (Option o : getOptions(std::wregex(L"xmlns[:_](.*)"))) ns[convertor.to_bytes(o.nameMatch[1])] = convertor.to_bytes(o.value);
-		for (Option o : getOptions(std::wregex(L"xmlns"), std::wregex(L"([^:]+):(.*)"))) ns[convertor.to_bytes(o.valueMatch[1])] = convertor.to_bytes(o.valueMatch[2]);
+		for (Option o : getOptions(std::wregex(L"xmlns[:_](.*)"))) ns[toBytes(o.nameMatch[1])] = toBytes(o.value);
+		for (Option o : getOptions(std::wregex(L"xmlns"), std::wregex(L"([^:]+):(.*)"))) ns[toBytes(o.valueMatch[1])] = toBytes(o.valueMatch[2]);
 	}
 
 	// Modes should share the logic of relpipe-in-xmltable
@@ -74,7 +74,7 @@
 		else if (modeName == L"raw-xml") return Mode::RAW_XML;
 		else if (modeName == L"line-number") return Mode::LINE_NUMBER;
 		else if (modeName == L"xpath") return Mode::XPATH;
-		else throw std::invalid_argument("Unsupported mode: " + convertor.to_bytes(modeName));
+		else throw std::invalid_argument("Unsupported mode: " + toBytes(modeName));
 	}
 
 	std::wstring toType(Mode mode) {
@@ -118,16 +118,16 @@
 
 		try {
 			xmlpp::DomParser parser;
-			parser.parse_file(convertor.to_bytes(currentFile));
+			parser.parse_file(toBytes(getCurrentFile()));
 			xmlpp::Element* root = parser.get_document()->get_root_node();
 
 			for (XPathAttribute xpathAttribute : xpathAttributes) {
-				std::string xpath = convertor.to_bytes(xpathAttribute.xpath);
+				std::string xpath = toBytes(xpathAttribute.xpath);
 				std::wstring result;
 				bool isNull = false;
 
 				if (xpathAttribute.mode == Mode::STRING) {
-					result = convertor.from_bytes(root->eval_to_string(xpath, ns));
+					result = fromBytes(root->eval_to_string(xpath, ns));
 				} else if (xpathAttribute.mode == Mode::BOOLEAN) {
 					result = root->eval_to_boolean(xpath, ns) ? L"true" : L"false";
 				} else if (xpathAttribute.mode == Mode::LINE_NUMBER) {
@@ -136,7 +136,7 @@
 					else isNull = true;
 				} else if (xpathAttribute.mode == Mode::XPATH) {
 					xmlpp::NodeSet attributeNodes = root->find(xpath, ns);
-					if (attributeNodes.size()) result = convertor.from_bytes(attributeNodes[0]->get_path());
+					if (attributeNodes.size()) result = fromBytes(attributeNodes[0]->get_path());
 					else isNull = true;
 				} else if (xpathAttribute.mode == Mode::RAW_XML) {
 					throw std::logic_error("Raw XML mode is not yet implemented."); // TODO: implement also RAW_XML