X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdbms%2FString.cpp;fp=source%2Fdbms%2FString.cpp;h=2e7e6fb666a89ad253e982b5ed082cf2ca3c2568;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/source/dbms/String.cpp b/source/dbms/String.cpp new file mode 100644 index 0000000..2e7e6fb --- /dev/null +++ b/source/dbms/String.cpp @@ -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 + +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 += " }"; +} +