MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / commify

Method commify

src/Lexer.cpp:291–345  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

289
290////////////////////////////////////////////////////////////////////////////////
291std::string Lexer::commify(const std::string& data) {
292 // First scan for decimal point and end of digits.
293 int decimalPoint = -1;
294 int end = -1;
295
296 int i;
297 for (int i = 0; i < (int)data.length(); ++i) {
298 if (unicodeLatinDigit(data[i])) end = i;
299
300 if (data[i] == '.') decimalPoint = i;
301 }
302
303 std::string result;
304 if (decimalPoint != -1) {
305 // In reverse order, transfer all digits up to, and including the decimal
306 // point.
307 for (i = (int)data.length() - 1; i >= decimalPoint; --i) result += data[i];
308
309 int consecutiveDigits = 0;
310 for (; i >= 0; --i) {
311 if (unicodeLatinDigit(data[i])) {
312 result += data[i];
313
314 if (++consecutiveDigits == 3 && i && unicodeLatinDigit(data[i - 1])) {
315 result += ',';
316 consecutiveDigits = 0;
317 }
318 } else
319 result += data[i];
320 }
321 } else {
322 // In reverse order, transfer all digits up to, but not including the last
323 // digit.
324 for (i = (int)data.length() - 1; i > end; --i) result += data[i];
325
326 int consecutiveDigits = 0;
327 for (; i >= 0; --i) {
328 if (unicodeLatinDigit(data[i])) {
329 result += data[i];
330
331 if (++consecutiveDigits == 3 && i && unicodeLatinDigit(data[i - 1])) {
332 result += ',';
333 consecutiveDigits = 0;
334 }
335 } else
336 result += data[i];
337 }
338 }
339
340 // reverse result into data.
341 std::string done;
342 for (int i = (int)result.length() - 1; i >= 0; --i) done += result[i];
343
344 return done;
345}
346
347////////////////////////////////////////////////////////////////////////////////
348std::string Lexer::lowerCase(const std::string& input) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected