cleaned all trailing white space from source files.
[sdk] / extras / types / Currency.ec
1 #ifdef ECERE_STATIC
2 public import static "ecere"
3 #else
4 public import "ecere"
5 #endif
6
7 default:
8
9 static void _WorkAround()
10 {
11    int a;
12    a.OnGetDataFromString(null);
13 }
14 extern int __ecereVMethodID_class_OnGetDataFromString;
15
16 private:
17
18 public class Currency : double
19 {
20    char * OnGetString(char * tempString, void * fieldData, bool * needClass)
21    {
22       char number[256];
23       int len;
24       int c = 0;
25       int pos = 2;
26       bool firstGroup = true;
27
28       sprintf(number, "%.2f", this);
29       len = strlen(number);
30
31       sprintf(tempString, "$ ");
32       if(number[c] == '-')
33       {
34          c++;
35          tempString[pos++] = '-';
36       }
37
38       while(true)
39       {
40          int numDigits = len - c - 3;
41          if(numDigits > 3)
42          {
43             if(firstGroup)
44             {
45                numDigits = (len - c - 3) % 3;
46                if(!numDigits) numDigits = 3;
47                firstGroup = false;
48             }
49             else
50                numDigits = 3;
51          }
52          memcpy(tempString + pos, number + c, numDigits);
53          c += numDigits;
54          pos += numDigits;
55          if(c == len - 3)
56             break;
57          tempString[pos++] = ',';
58       }
59       strcpy(tempString + pos, number + c);
60       return tempString;
61    }
62
63    bool OnGetDataFromString(char * string)
64    {
65       int c;
66       char ch;
67       char number[256] = "";
68       int len = 0;
69       bool gotDot = false;
70       int numDecimals = 0;
71       for(c = 0; (ch = string[c]) && !isdigit(ch) && ch != '.'; c++);
72       for(; (ch = string[c]) && (isdigit(ch) || ch == '.' || ch == ',' || ch == ' '); c++)
73       {
74          if(ch != ',' && ch != ' ')
75          {
76             if(ch == '.') gotDot = true;
77             else if(gotDot)
78                numDecimals++;
79             number[len++] = ch;
80             if(numDecimals == 2)
81                break;
82          }
83       }
84       number[len] = 0;
85       return ((bool (*)(void *, void *, const char *))(void *)class(double)._vTbl[__ecereVMethodID_class_OnGetDataFromString])(class(double), &this, number);
86    }
87 }