Revert "Remove mysql and oracle resources for anna-ericsson project"
[anna.git] / source / dbms / String.cpp
diff --git a/source/dbms/String.cpp b/source/dbms/String.cpp
new file mode 100644 (file)
index 0000000..2e7e6fb
--- /dev/null
@@ -0,0 +1,69 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#include <anna/dbms/String.hpp>
+
+using namespace anna;
+using namespace anna::dbms;
+
+String& String::operator = (const String & other)
+throw(RuntimeException) {
+  if(this == &other)
+    return *this;
+
+  if(other.isNull() == true) {
+    setNull(true);
+    a_value [0] = 0;
+    return *this;
+  }
+
+  return operator= (other.a_value);
+}
+
+String& String::operator = (const char * str)
+throw(RuntimeException) {
+  if(a_value != str) {
+    if(anna_strlen(str) > Data::getMaxSize())
+      throw RuntimeException(
+        functions::asString("'%s' out of range | MaxLen: %d | Len: %d ", str, Data::getMaxSize(), anna_strlen(str)),
+        ANNA_FILE_LOCATION
+      );
+
+    anna_strcpy(a_value, str);
+  }
+
+  Data::setNull(false);
+  return *this;
+}
+
+char* String::strip(char *str)
+throw() {
+  int len;
+
+  if(str == NULL || (len = anna_strlen(str)) == 0)
+    return str;
+
+  int end = len - 1;
+
+  while(end >= 0 && str [end] == ' ') end --;
+
+  if(end >= 0)
+    str [++ end] = 0;
+
+  return str;
+}
+
+std::string dbms::String::asString() const
+throw() {
+  std::string result("dbms::String { ");
+  result += dbms::Data::asString();
+  result += " | Value: ";
+  result += a_value;
+  return result += " }";
+}
+