@@ -183,45 +183,27 @@ inline void deserializeValue(const std::string &data, std::vector<double> &value
183183
184184inline void deserializeValue (const std::string &data, IPLColor &value)
185185{
186- std::array<float ,3 > color;
187-
188- int i = 0 ;
189186 std::smatch match;
190- auto pos = data.begin ();
191- while (i < (int ) color.size () && std::regex_search (pos,data.end (),match,std::regex (" [-0-9.]" )))
192- {
193- pos += match.position ();
194-
195- int charsParsed = 0 ;
196- float element = 0 ;
197- if (sscanf (&(*pos)," %f%n" ,&element,&charsParsed) > 0 )
198- color[i++] = element;
199-
200- pos += charsParsed;
187+ std::regex e (" \\ [([-0-9.eE]+),([-0-9.eE]+),([-0-9.eE]+)\\ ]" );
188+ if (!std::regex_search (data, match, e) || match.size () - 1 != 3 ) {
189+ value = IPLColor (0 , 0 , 0 );
190+ return ;
201191 }
202- value = IPLColor (color[0 ], color[1 ], color[2 ]);
192+ value = IPLColor (std::stof (match.str (1 )),
193+ std::stof (match.str (2 )),
194+ std::stof (match.str (3 )));
203195}
204196
205197inline void deserializeValue (const std::string &data, IPLPoint &value)
206198{
207- std::array<double ,2 > point;
208-
209- int i = 0 ;
210199 std::smatch match;
211- auto pos = data.begin ();
212- while (i < (int ) point.size () && std::regex_search (pos,data.end (),match,std::regex (" [-0-9.]" )))
213- {
214- pos += match.position ();
215-
216- int charsParsed = 0 ;
217- float element = 0 ;
218- if (sscanf (&(*pos)," %f%n" ,&element,&charsParsed) > 0 )
219- point[i++] = element;
220-
221- pos += charsParsed;
200+ std::regex e (" \\ [([-0-9.eE]+),([-0-9.eE]+)\\ ]" );
201+ if (!std::regex_search (data, match, e) || match.size () - 1 != 2 ) {
202+ value = IPLPoint (0 , 0 , 0 );
203+ return ;
222204 }
223-
224- value = IPLPoint (point[ 0 ], point[ 1 ] );
205+ value = IPLPoint ( std::stod (match. str ( 1 )),
206+ std::stod (match. str ( 2 )) );
225207}
226208
227209inline void deserializeValue (const std::string &data, std::string &value)
0 commit comments