From a0d97dbc7e6adb7df67063eb504722a5f150f0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Mon, 9 Jul 2018 00:14:15 -0300 Subject: [PATCH] deserializeValue: try to fix IPLPoint/IPLColor loading (always reset to 0) using some C++11 --- IPL/src/IPLProcessProperty.cpp | 44 ++++++++++------------------------ 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/IPL/src/IPLProcessProperty.cpp b/IPL/src/IPLProcessProperty.cpp index 2656b4d..fb4c2eb 100644 --- a/IPL/src/IPLProcessProperty.cpp +++ b/IPL/src/IPLProcessProperty.cpp @@ -183,45 +183,27 @@ inline void deserializeValue(const std::string &data, std::vector &value inline void deserializeValue(const std::string &data, IPLColor &value) { - std::array color; - - int i = 0; std::smatch match; - auto pos = data.begin(); - while(i < (int) color.size() && std::regex_search(pos,data.end(),match,std::regex("[-0-9.]"))) - { - pos += match.position(); - - int charsParsed = 0; - float element = 0; - if (sscanf(&(*pos),"%f%n",&element,&charsParsed) > 0) - color[i++] = element; - - pos += charsParsed; + std::regex e ("\\[([-0-9.eE]+),([-0-9.eE]+),([-0-9.eE]+)\\]"); + if (!std::regex_search(data, match, e) || match.size() - 1 != 3) { + value = IPLColor(0, 0, 0); + return; } - value = IPLColor(color[0], color[1], color[2]); + value = IPLColor(std::stof(match.str(1)), + std::stof(match.str(2)), + std::stof(match.str(3))); } inline void deserializeValue(const std::string &data, IPLPoint &value) { - std::array point; - - int i = 0; std::smatch match; - auto pos = data.begin(); - while(i < (int) point.size() && std::regex_search(pos,data.end(),match,std::regex("[-0-9.]"))) - { - pos += match.position(); - - int charsParsed = 0; - float element = 0; - if (sscanf(&(*pos),"%f%n",&element,&charsParsed) > 0) - point[i++] = element; - - pos += charsParsed; + std::regex e ("\\[([-0-9.eE]+),([-0-9.eE]+)\\]"); + if (!std::regex_search(data, match, e) || match.size() - 1 != 2) { + value = IPLPoint(0, 0, 0); + return; } - - value = IPLPoint(point[0], point[1]); + value = IPLPoint(std::stod(match.str(1)), + std::stod(match.str(2))); } inline void deserializeValue(const std::string &data, std::string &value)