first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / graphiq / library / geometric / math_bits.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : mathematical operations group                                     *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 1996-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 \*****************************************************************************/
14
15 #include "math_bits.h"
16
17 #include <basis/astring.h>
18
19 using namespace basis;
20
21 namespace geometric {
22
23 astring crop_numeric(const astring &input)
24 {
25   astring to_return(input);
26   for (int i = 0; i < to_return.length(); i++)
27     if ( ( (to_return[i] >= '0') && (to_return[i] <= '9') )
28          || (to_return[i] == '.')
29          || (to_return[i] == '+') || (to_return[i] == '-')
30          || (to_return[i] == 'E') || (to_return[i] == 'e') ) {
31       to_return.zap(i, i);  // remove non-useful character.
32       i--;  // move backwards in loop.
33     } else break;
34   return to_return;
35 }
36
37 astring crop_non_numeric(const astring &input)
38 {
39   astring to_return(input);
40   for (int i = 0; i < to_return.length(); i++)
41     if ( ! ((to_return[i] >= '0') && (to_return[i] <= '9'))
42          && (to_return[i] != '.')
43          && (to_return[i] != '+') && (to_return[i] != '-')
44          && (to_return[i] != 'E') && (to_return[i] != 'e') ) {
45       to_return.zap(i, i);  // remove non-useful character.
46       i--;  // move backwards in loop.
47     } else break;
48   return to_return;
49 }
50
51 }
52