scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
lab_number.cpp
Go to the documentation of this file.
1#include "./lab_number.hpp"
2
3using namespace std;
4
5namespace scifir
6{
7 bool is_lab_number(const string& init_lab_number)
8 {
9 if ((init_lab_number.find("\u00B1") != string::npos or init_lab_number.find("+") != string::npos or init_lab_number.find("-") != string::npos) and init_lab_number.length() > 1)
10 {
12 boost::split(numbers,init_lab_number,boost::is_any_of("+-,\u00B1"));
13 if (numbers.size() != 3)
14 {
15 return false;
16 }
17 if (numbers[2].length() < 1)
18 {
19 return false;
20 }
21 bool dot_present = false;
22 bool after_whitespace = false;
23 bool after_alpha = false;
24 boost::trim(numbers[0]);
25 boost::trim(numbers[2]);
26 for (unsigned int i = 0; i < numbers[0].length(); i++)
27 {
28 if (numbers[0][i] == '.')
29 {
30 if (dot_present)
31 {
32 return false;
33 }
34 else
35 {
36 dot_present = true;
37 continue;
38 }
39 }
40 else if (numbers[0][i] == ' ')
41 {
42 after_whitespace = true;
43 continue;
44 }
45 else if (!std::isdigit(numbers[0][i]) and after_whitespace == false)
46 {
47 return false;
48 }
49 else if (after_whitespace == true)
50 {
51 if (after_alpha == true and std::isalpha(numbers[0][i]))
52 {
53 return false;
54 }
55 else if (std::isalpha(numbers[0][i]))
56 {
57 continue;
58 }
59 else if (std::isdigit(numbers[0][i]))
60 {
61 after_alpha = true;
62 }
63 }
64 }
65 dot_present = false;
66 after_whitespace = false;
67 after_alpha = false;
68 for (unsigned int i = 0; i < numbers[2].length(); i++)
69 {
70 if (numbers[2][i] == '.')
71 {
72 if (dot_present)
73 {
74 return false;
75 }
76 else
77 {
78 dot_present = true;
79 continue;
80 }
81 }
82 else if (numbers[2][i] == ' ')
83 {
84 after_whitespace = true;
85 continue;
86 }
87 else if (!std::isdigit(numbers[2][i]) and after_whitespace == false)
88 {
89 return false;
90 }
91 else if (after_whitespace == true)
92 {
93 if (after_alpha == true and std::isalpha(numbers[2][i]))
94 {
95 return false;
96 }
97 else if (std::isalpha(numbers[2][i]))
98 {
99 continue;
100 }
101 else if (std::isdigit(numbers[2][i]))
102 {
103 after_alpha = true;
104 }
105 }
106 }
107 return true;
108 }
109 else
110 {
111 return false;
112 }
113 }
114}
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
bool is_lab_number(const string &init_lab_number)
Definition lab_number.cpp:7