#include "StringValue.h" #include "Constants.h" #include "StringType.h" //#define SLRE_REGEXP #ifdef SLRE_REGEXP #include "..\slre\slre.h" #endif namespace Databoard { namespace Value { StringValue::StringValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) { } StringValue::~StringValue() { } void StringValue::setValue(std::string value) { this->value = value; } std::string StringValue::getValue() { return value; } std::string StringValue::writeOut(int /*indent*/) { std::string s; s += value; return s; } std::string StringValue::isValid() { std::string retValue = STR_EMPTY; #ifdef SLRE_REGEXP Databoard::Type::StringType* stringType = (Databoard::Type::StringType*)dataBoard; std::string p = stringType->getPattern(); if(p.length() > 0) { struct slre slre; struct cap captures[4 + 1]; if (!slre_compile(&slre, p.c_str())) { retValue = "StringValue: pattern error."; // slre internal error } // todo: this is not working completely else if (!slre_match(&slre, value.c_str(), value.length(), captures)) { retValue = "StringValue: value error."; } else { retValue = STR_EMPTY; } } else { retValue = STR_EMPTY; } #endif return retValue; } bool StringValue::equals(const Value* other) { StringValue* o = (StringValue*)other; return (this->value < o->value); } } }