Changed LICENSE. Now referenced to web site and file on project root directory
[anna.git] / source / core / util / String.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <cctype> // for toupper
10 #include <string>
11 #include <algorithm>
12
13 #include <anna/core/util/String.hpp>
14 #include <anna/core/functions.hpp>
15 #include <anna/core//DataBlock.hpp>
16
17 using namespace std;
18 using namespace anna;
19
20 void String::toUpper()
21 throw() {
22   std::transform(begin(), end(), begin(), (int(*)(int)) toupper);
23 }
24
25 void String::toLower()
26 throw() {
27   std::transform(begin(), end(), begin(), (int(*)(int)) tolower);
28 }
29
30 String& String::operator<< (const char* vv)
31 throw() {
32   if(vv == NULL) {
33     if(a_flags & Flag::ShowNull)
34       string::operator+= ("<null>");
35   } else
36     string::operator+= (vv);
37
38   return *this;
39 }
40
41 String& String::operator<< (const int vv)
42 throw() {
43   char aux [16];
44   sprintf(aux, "%d", vv);
45   string::operator+= (aux);
46   return *this;
47 }
48
49 String& String::operator<< (const unsigned int vv)
50 throw() {
51   char aux [16];
52   sprintf(aux, "%u", vv);
53   string::operator+= (aux);
54   return *this;
55 }
56
57 String& String::operator<< (const S64 vv)
58 throw() {
59   char aux [32];
60   sprintf(aux, "%lld", vv);
61   /*
62   #ifdef __anna64__
63      sprintf (aux, "%ld", vv);
64   #else
65      sprintf (aux, "%lld", vv);
66   #endif
67   */
68   string::operator+= (aux);
69   return *this;
70 }
71
72 String& String::operator<< (const U64 vv)
73 throw() {
74   char aux [32];
75   sprintf(aux, "%llu", vv);
76   /*
77    #ifdef __anna64__
78       sprintf (aux, "%lu", vv);
79    #else
80       sprintf (aux, "%llu", vv);
81    #endif
82   */
83   string::operator+= (aux);
84   return *this;
85 }
86
87 String& String::operator<< (const float vv)
88 throw() {
89   char aux [64];
90   sprintf(aux, "%f", vv);
91   string::operator+= (aux);
92   return *this;
93 }
94
95 String& String::operator<< (const double vv)
96 throw() {
97   char aux [64];
98   sprintf(aux, "%e", vv);
99   string::operator+= (aux);
100   return *this;
101 }
102
103 String& String::operator<< (const DataBlock& vv)
104 throw() {
105   return *this += vv.asString();
106 }
107
108 //static
109 String String::format(const DataBlock& vv, const int characterByLine)
110 throw() {
111   return String(vv.asString(characterByLine));
112 }