# HG changeset patch # User František Kučera # Date 1580249901 -3600 # Node ID 5d3d57d9c3234bb01c646beaef6f1af08b6d9264 # Parent 0766d298eb1c6f7c0f4421c977d8b1c74613d07f streamlet examples: xpath: support multiple modes (string, boolean, line-number, xpath), TODO: raw-xml diff -r 0766d298eb1c -r 5d3d57d9c323 streamlet-examples/xpath.cpp --- a/streamlet-examples/xpath.cpp Tue Jan 28 14:26:39 2020 +0100 +++ b/streamlet-examples/xpath.cpp Tue Jan 28 23:18:21 2020 +0100 @@ -36,11 +36,45 @@ for (Option o : getOptions(std::wregex(L"xmlns"), std::wregex(L"([^:]+):(.*)"))) ns[convertor.to_bytes(o.valueMatch[1])] = convertor.to_bytes(o.valueMatch[2]); } + // Modes should share the logic of relpipe-in-xmltable + + enum class Mode { + STRING, + BOOLEAN, + // TODO: support also XML number, when we have a rational or decimal numbers in Relational pipes + RAW_XML, + LINE_NUMBER, + XPATH + }; + + Mode toMode(std::wstring modeName) { + if (modeName == L"string") return Mode::STRING; + else if (modeName == L"boolean") return Mode::BOOLEAN; + 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)); + } + + std::wstring toType(Mode mode) { + if (mode == Mode::BOOLEAN) return BOOLEAN; + else if (mode == Mode::LINE_NUMBER) return INTEGER; + else return STRING; + } + + // TODO: should not be done in particular streamlets but in the worker + std::wstring toNullValue(std::wstring type) { + if (type == BOOLEAN) return L"false"; + else if (type == INTEGER) return L"0"; + else return L""; + } + class XPathAttribute { public: std::wstring name; std::wstring xpath; + Mode mode = Mode::STRING; }; std::vector xpathAttributes; @@ -53,11 +87,13 @@ std::vector oam; + std::vector