Add no-deprecated to warnings due to dynamic exceptions.
[anna.git] / source / dbms / 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 <anna/dbms/String.hpp>
10
11 using namespace anna;
12 using namespace anna::dbms;
13
14 String& String::operator = (const String & other)
15 throw(RuntimeException) {
16   if(this == &other)
17     return *this;
18
19   if(other.isNull() == true) {
20     setNull(true);
21     a_value [0] = 0;
22     return *this;
23   }
24
25   return operator= (other.a_value);
26 }
27
28 String& String::operator = (const char * str)
29 throw(RuntimeException) {
30   if(a_value != str) {
31     if(anna_strlen(str) > Data::getMaxSize())
32       throw RuntimeException(
33         functions::asString("'%s' out of range | MaxLen: %d | Len: %d ", str, Data::getMaxSize(), anna_strlen(str)),
34         ANNA_FILE_LOCATION
35       );
36
37     anna_strcpy(a_value, str);
38   }
39
40   Data::setNull(false);
41   return *this;
42 }
43
44 char* String::strip(char *str)
45 throw() {
46   int len;
47
48   if(str == NULL || (len = anna_strlen(str)) == 0)
49     return str;
50
51   int end = len - 1;
52
53   while(end >= 0 && str [end] == ' ') end --;
54
55   if(end >= 0)
56     str [++ end] = 0;
57
58   return str;
59 }
60
61 std::string dbms::String::asString() const
62 throw() {
63   std::string result("dbms::String { ");
64   result += dbms::Data::asString();
65   result += " | Value: ";
66   result += a_value;
67   return result += " }";
68 }
69