src/miscallenous.cc

changeset 800
a1d9b7fff8f7
parent 799
c18c8846f6a7
child 817
cee9f0ecac66
equal deleted inserted replaced
799:c18c8846f6a7 800:a1d9b7fff8f7
136 return out; 136 return out;
137 } 137 }
138 138
139 // ============================================================================= 139 // =============================================================================
140 // 140 //
141 bool numeric (const QString& tok)
142 {
143 bool gotDot = false;
144
145 for (int i = 0; i < tok.length(); ++i)
146 {
147 const QChar c = tok[i];
148
149 // Allow leading hyphen for negatives
150 if (i == 0 && c == '-')
151 continue;
152
153 // Check for decimal point
154 if (not gotDot && c == '.')
155 {
156 gotDot = true;
157 continue;
158 }
159
160 if (c >= '0' && c <= '9')
161 continue; // Digit
162
163 // If the above cases didn't catch this character, it was
164 // illegal and this is therefore not a number.
165 return false;
166 }
167
168 return true;
169 }
170
171 // =============================================================================
172 //
173 void simplify (int& numer, int& denom) 141 void simplify (int& numer, int& denom)
174 { 142 {
175 bool repeat; 143 bool repeat;
176 144
177 do 145 do

mercurial