annotate OrthancStone/Sources/Toolbox/GenericToolbox.h @ 2101:517ef20aef74

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 14 Nov 2023 11:44:46 +0100
parents 07964689cb0b
children c23eef785569
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
1 /**
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 *
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11 * the License, or (at your option) any later version.
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 *
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
20 * <http://www.gnu.org/licenses/>.
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21 **/
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23 #pragma once
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1331
diff changeset
25 #include <Compatibility.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1331
diff changeset
26 #include <OrthancException.h>
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
27 #include <Logging.h>
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
28
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
29 #include "LinearAlgebra.h"
1328
fd616c4a5904 Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 1306
diff changeset
30
fd616c4a5904 Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 1306
diff changeset
31 #include <boost/shared_ptr.hpp>
fd616c4a5904 Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 1306
diff changeset
32
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 #include <string>
1101
141593f1aa88 fix build on ubuntu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1080
diff changeset
34 #include <stdint.h>
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
35 #include <math.h>
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
36
1328
fd616c4a5904 Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 1306
diff changeset
37 #include <memory>
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
38 #include <vector>
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
39
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 namespace OrthancStone
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42 namespace GenericToolbox
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 {
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
44 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
45 Fast floating point string validation.
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
46 No trimming applied, so the input must match regex
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
47 /^[-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
48 The following are allowed as edge cases: "" and "-"
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
49
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
50 The parsing always stops if encountering either 0 or the stopChar
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
51
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
52 */
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
53 inline bool LegitDoubleString(const char* text, char stopChar = 0)
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 const char* p = text;
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
56 if (*p == '-')
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 p++;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 size_t period = 0;
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
59 while ((*p != 0) && (*p != stopChar) && (*p != ' ') && (*p != '\t'))
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 if (*p >= '0' && *p <= '9')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 ++p;
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
63 else if (*p == '.')
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 {
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
65 if (period > 0)
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 else
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 period++;
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
69 ++p;
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 }
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
71 else if (*p == 'e' || *p == 'E')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
72 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
73 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
74 if (*p == '-' || *p == '+')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
75 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
76 // "e+"/"E+" "e-"/"E-" or "e"/"E" must be followed by a number
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
77 if (!(*p >= '0' && *p <= '9'))
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
78 return false;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
79
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
80 // these must be the last in the string
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
81 while (*p >= '0' && *p <= '9')
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
82 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
83
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
84 // after that, there can only be spaces
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
85 while ((*p != 0) && (*p != stopChar))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
86 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
87 if ((*p != ' ') && (*p != '\t'))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
88 return false;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
89 ++p;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
90 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
91
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
92 return ((*p == 0) || (*p == stopChar));
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
93 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 else
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
95 {
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
96 return false;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
97 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
98 }
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
99
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
100 // we only accept trailing whitespace
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
101 while ((*p != 0) && (*p != stopChar))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
102 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
103 if( (*p != ' ') && (*p != '\t'))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
104 return false;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
105 ++p;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
106 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 return true;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
110
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
111
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
112 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
113 Fast integer string validation.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
114 No trimming applied, so the input must match regex /^-?[0-9]*$/
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
115 The following are allowed as edge cases: "" and "-"
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
116
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
117 The parsing always stops if encountering either 0 or the stopChar
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
118
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
119 */
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
120 inline bool LegitIntegerString(const char* text, char stopChar = 0)
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 const char* p = text;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123 if (*p == '-')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
124 p++;
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
125 while ((*p != 0) && (*p != stopChar))
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 if (*p >= '0' && *p <= '9')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 else
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
132 return true;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
135
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
136 static const double FRAC_FACTORS[] =
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137 {
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
138 1.0,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
139 0.1,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
140 0.01,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
141 0.001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
142 0.0001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
143 0.00001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
144 0.000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
145 0.0000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
146 0.00000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
147 0.000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
148 0.0000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
149 0.00000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
150 0.000000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
151 0.0000000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
152 0.00000000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
153 0.000000000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
154 0.0000000000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
155 0.00000000000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
156 0.000000000000000001,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
157 0.0000000000000000001
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
158 };
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
159 static const size_t FRAC_FACTORS_LEN = sizeof(FRAC_FACTORS) / sizeof(double);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
160
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
161 /**
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
162 Technical version of StringToDouble, meant for parsing bigger strings in-place.
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
163
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
164 Only works for dot decimal numbers without digit separation
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
165
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
166 The parsing stops when encountering EITHER \x00 or stopChar.
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
167
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
168 Instead of filling r and returning true if number is legit, it fills r then
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
169 returns the number of parsed characters (NOT including the end character (which
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
170 can be zero, since an empty string is an allowed edge case) BUT including the trailing
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
171 spaces), or -1 if a parsing error occurred.
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
172
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
173 Please note that if stopChar is a number, a minus sign, the decimal separator
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
174 or the letters e and E, the behavior is UNDEFINED!!!
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
175
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
176 In order to allow the containing string not to be space-stripped:
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
177 - Spaces and tabs are ignored if they occur before the scientific notation e or E letter
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
178 - Spaces and tabs are ignored between the end of the number and the \x00 or stopChar
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
179 - Spaces and tabs cause errors anywhere else
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
180
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
181 It is up to the caller to detect whether a successful parsing has reached the
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
182 terminator (\x00) or stopChar.
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
183
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
184 In case of an error returned, in a parsing scenario where multiple numbers
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
185 are to be read in a bigger surrounding string, it is up to the caller to
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
186 recover from the error by advancing the read pointer to the next character,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
187 if desirable.
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
188
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
189 Example:
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
190 ------
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
191 const char* s = "0.0/.123/3/12.5//-43.1";
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
192
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
193 int size;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
194 double r;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
195 const char* p = s;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
196
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
197 size = StringToDoubleEx(r, p, '/');
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
198 // -->
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
199 // r = 0 and size = 3
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
200
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
201 p += size + 1; // gobble the separator
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
202 size = StringToDoubleEx(r, p, '/');
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
203 // -->
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
204 // r = 0.123 and size = 4
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
205
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
206 p += size + 1; // gobble the separator
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
207 size = StringToDoubleEx(r, p, '/');
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
208 // -->
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
209 // r = 3.0 and size = 1
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
210
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
211 p += size + 1; // gobble the separator
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
212 size = StringToDoubleEx(r, p, '/');
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
213 // -->
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
214 // r = 12.5 and size = 3
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
215
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
216 p += size + 1; // gobble the separator
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
217 size = StringToDoubleEx(r, p, '/');
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
218 // -->
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
219 // r = 0 and size = 0
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
220
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
221 p += size + 1; // gobble the separator
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
222 size = StringToDoubleEx(r, p, '/');
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
223 // -->
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
224 // r = 0 and size = 0
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
225
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
226 p += size
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
227 if(p == 0)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
228 ...stop parsing!
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
229 */
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
230
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
231 inline int32_t StringToDoubleEx(double& r, const char* text, char stopChar = 0)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
232 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
233 if (!LegitDoubleString(text,stopChar))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
234 return -1;
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 r = 0.0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237 double neg = 1.0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 const char* p = text;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 if (*p == '-')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242 neg = -1.0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 // 12345.67890
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
246 while (*p >= '0' && *p <= '9')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
247 {
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
248 r = (r * 10.0) + (*p - '0'); // 1 12 123 123 12345
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
250 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
251 if (*p == '.')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
252 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 double f = 0.0;
1192
91d86144fb79 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1166
diff changeset
254 size_t n = 1;
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
255 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256 while (*p >= '0' && *p <= '9' && n < FRAC_FACTORS_LEN)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 f += (*p - '0') * FRAC_FACTORS[n];
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
259 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
260 ++n;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
262 r += f;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
263 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
264 r *= neg;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
265
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
266 // skip the remaining numbers until we reach not-a-digit (either the
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
267 // end of the string OR the scientific notation symbol)
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
268 // spaces are skipped in this phase here
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
269 while ((*p >= '0' && *p <= '9') || *p == ' ' || *p == '\t')
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
270 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
271
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
272 if ( (*p == 0) || (*p == stopChar))
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
273 {
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
274 return static_cast<int32_t>(p - text);
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
275 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
276 else if ((*p == 'e') || (*p == 'E'))
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
277 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
278 // process the scientific notation
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
279 double sign; // no init is safe (read below)
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
280 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
281 if (*p == '-')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
282 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
283 sign = -1.0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
284 // point to first number
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
285 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
286 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
287 else if (*p == '+')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
288 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
289 sign = 1.0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
290 // point to first number
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
291 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
292 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
293 else if (*p >= '0' && *p <= '9')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
294 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
295 sign = 1.0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
296 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
297 else
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
298 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
299 // only a sign char or a number is allowed
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
300 return -1;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
301 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
302 // now p points to the absolute value of the exponent
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
303 double exp = 0;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
304 while (*p >= '0' && *p <= '9')
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
305 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
306 exp = (exp * 10.0) + static_cast<double>(*p - '0'); // 1 12 123 123 12345
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
307 ++p;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
308 }
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
309 // now we have our exponent. put a sign on it.
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
310 exp *= sign;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
311 double scFac = ::pow(10.0, exp);
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
312 r *= scFac;
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
313
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
314 // skip the trailing spaces
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
315 while (*p == ' ' || *p == '\t')
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
316 ++p;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
317
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
318 // only allowed symbol here is EOS or stopChar
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
319 if ((*p == 0) || (*p == stopChar))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
320 return static_cast<int32_t>(p - text);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
321 else
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
322 return -1;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
323 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
324 else
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
325 {
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
326 // not allowed
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
327 return -1;
1166
f68da12e852b Added scientific notation support to StringToDouble
Benjamin Golinvaux <bgo@osimis.io>
parents: 1101
diff changeset
328 }
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
329 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
330
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
331 /**
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
332 Fast string --> double conversion.
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
333 Must pass the LegitDoubleString test
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
334
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
335 String to doubles with at most 18 digits
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
336
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
337 Returns true if okay and false if failed.
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
338
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
339 The end-of-substring is character \x00
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
340 */
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
341 inline bool StringToDouble(double& r, const char* text)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
342 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
343 int32_t size = StringToDoubleEx(r, text, 0);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
344 return (size != -1);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
345 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
346
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
347 /**
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
348 See main overload
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
349 */
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
350 inline bool StringToDouble(double& r, const std::string& text)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
351 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
352 return StringToDouble(r, text.c_str());
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
353 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
354
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
355 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
356 Fast string to integer conversion. Leading zeroes and minus are accepted,
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
357 but a leading + sign is NOT.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
358 Must pass the LegitIntegerString function test.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
359 In addition, an empty string (or lone minus sign) yields 0.
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
360 */
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
361
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
362 template<typename T>
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
363 inline bool StringToInteger(T& r, const char* text)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
364 {
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
365 if (!LegitIntegerString(text))
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
366 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
367
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
368 r = 0;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
369 T neg = 1;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
370 const char* p = text;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
371
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
372 if (*p == '-')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
373 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
374 neg = -1;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
375 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
376 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
377 while (*p >= '0' && *p <= '9')
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
378 {
1679
5b8b88e5bfd6 successfully running unit tests in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
379 r = (r * 10) + static_cast<T>(*p - '0'); // 1 12 123 123 12345
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
380 ++p;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
381 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
382 r *= neg;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
383 if (*p == 0)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
384 return true;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
385 else
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
386 return false;
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
387 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
388
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
389 template<typename T>
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
390 inline bool StringToInteger(T& r, const std::string& text)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
391 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
392 return StringToInteger<T>(r, text.c_str());
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
393 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
394
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
395 /**
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
396 if input is "rgb(12,23,255)" --> function fills `red`, `green` and `blue` and returns true
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
397 else ("everything else") --> function returns false and leaves all values untouched
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
398 */
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
399 bool GetRgbValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, const char* text);
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
400
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
401 /**
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
402 See main overload
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
403 */
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
404 inline bool GetRgbValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, const std::string& text)
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
405 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
406 return GetRgbValuesFromString(red, green, blue, text.c_str());
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
407 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
408
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
409 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
410 Same as GetRgbValuesFromString
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
411 */
1328
fd616c4a5904 Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 1306
diff changeset
412 bool GetRgbaValuesFromString(uint8_t& red,
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
413 uint8_t& green,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
414 uint8_t& blue,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
415 uint8_t& alpha,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
416 const char* text);
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
417
1306
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
418 /**
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
419 Same as GetRgbValuesFromString
fef1ec42a7db Some docs + headers added to CMake for easier VS browsing + tiny predecl
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
420 */
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
421 inline bool GetRgbaValuesFromString(uint8_t& red,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
422 uint8_t& green,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
423 uint8_t& blue,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
424 uint8_t& alpha,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
425 const std::string& text)
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
426 {
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
427 return GetRgbaValuesFromString(red, green, blue, alpha, text.c_str());
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
428 }
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
429
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
430
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
431 /**
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
432 This method could have been called StripSpacesAndChangeToLower but we might want to
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
433 add some UUID validation to the argument
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
434 */
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
435 void NormalizeUuid(std::string& uuid);
1748
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
436
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
437
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
438 inline void FastTokenizeString(std::vector<std::string>& result,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
439 const std::string& value,
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
440 char separator)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
441 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
442 size_t countSeparators = 0;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
443
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
444 for (size_t i = 0; i < value.size(); i++)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
445 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
446 if (value[i] == separator)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
447 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
448 countSeparators++;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
449 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
450 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
451
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
452 result.clear();
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
453 result.reserve(countSeparators + 1);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
454
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
455 std::string currentItem;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
456
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
457 for (size_t i = 0; i < value.size(); i++)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
458 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
459 if (value[i] == separator)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
460 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
461 result.push_back(currentItem);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
462 currentItem.clear();
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
463 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
464 else
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
465 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
466 currentItem.push_back(value[i]);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
467 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
468 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
469
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
470 result.push_back(currentItem);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
471 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
472
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
473
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
474 inline std::string FastStripSpaces(const std::string& source)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
475 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
476 size_t first = 0;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
477
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
478 while (first < source.length() &&
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
479 isspace(source[first]))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
480 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
481 first++;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
482 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
483
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
484 if (first == source.length())
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
485 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
486 // String containing only spaces
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
487 return "";
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
488 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
489
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
490 size_t last = source.length();
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
491 while (last > first &&
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
492 isspace(source[last - 1]))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
493 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
494 last--;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
495 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
496
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
497 assert(first <= last);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
498 return source.substr(first, last - first);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
499 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
500
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
501 /**
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
502 Return the raw numbers of occurrences of `separator` in s (starting at s up to \x00)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
503 */
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
504 inline size_t GetCharCount(const char* s, const char separator)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
505 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
506 const char* p = s;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
507 size_t sepCount = 0;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
508
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
509 while (*p != 0)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
510 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
511 if(*p == separator)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
512 sepCount++;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
513 ++p;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
514 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
515 return sepCount;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
516 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
517
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
518 inline bool FastParseVector(Vector& target, const std::string& value)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
519 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
520 const char* s = value.c_str();
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
521 const char SEP = '\\';
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
522
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
523 size_t sepCount = GetCharCount(s, SEP);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
524
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
525 size_t itemCount = sepCount + 1;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
526 target.resize(itemCount);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
527
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
528 while (*s == ' ' || *s == '\t')
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
529 ++s;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
530
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
531 const char* p = s;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
532
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
533 double r;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
534 for (size_t i = 0; i < itemCount; i++)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
535 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
536 int32_t numberCharCount = StringToDoubleEx(r, p, SEP);
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
537 if (numberCharCount == -1)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
538 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
539 LOG(ERROR) << "Parsing error for vector \"" << value << "\". Current position (0-based) = " << i;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
540 return false;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
541 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
542 p += numberCharCount;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
543 if (*p == 0)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
544 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
545 // if we are at the end of the string, it means we have processed the last character
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
546 // let's check this. this is a small price to pay for a useful check
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
547 if (i != (itemCount - 1))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
548 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
549 LOG(ERROR) << "Parsing error for vector \"" << value << "\". Reached end of the string without consuming the right # of items! Current position (0-based) = " << i;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
550 return false;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
551 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
552 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
553 else
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
554 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
555 if (*p != SEP)
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
556 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
557 LOG(ERROR) << "Parsing error for vector \"" << value << "\". Character past end of number Reached end of the string without consuming the right # of items! Current position (0-based) = " << i << " and r = " << r;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
558 return false;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
559 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
560 if (i == (itemCount - 1))
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
561 {
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
562 LOG(ERROR) << "Parsing error for vector \"" << value << "\". Reached end of the vector too soon. Current position (0-based) = " << i << " and r = " << r;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
563 return false;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
564 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
565 // advance to next number
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
566 p += 1;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
567 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
568 target[i] = r;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
569 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
570 return true;
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
571 }
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
572
b6a6ad64192a FastParseVector : manually written code to parse strings like 3.1315\-1.2e12\2344.5\123 into boost::numeric::ublas::vector<double> + tests
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
573
1080
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
574 }
287ec78f63b4 GenericToolbox (fast c-string --> double or integer) + refactoring to be able
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
575 }