#include "StringType.h" #include "Range.h" #include "Limit.h" #include namespace Databoard { namespace Type { StringType::StringType() { this->length = NULL; } StringType::StringType(std::string pattern) { this->pattern = pattern; this->length = NULL; } StringType::StringType(std::string pattern, std::string mimeType, Range* length) { this->pattern = pattern; this->mimeType = mimeType; this->length = length; } StringType::~StringType() { if(length != NULL) { delete length; } } std::string StringType::getPattern() { return pattern; } void StringType::setPattern(std::string pattern) { this->pattern = pattern; } std::string StringType::getMimeType() { return mimeType; } void StringType::setMimeType(std::string mimeType) { this->mimeType = mimeType; } Range* StringType::getLength() { return length; } void StringType::setLength(Range* length) { this->length = length; } int StringType::minLength() { if(length == NULL) return 0; return length->getLower()->getInteger(INT_MAX); } int StringType::maxLength() { if(length == NULL) return INT_MAX; return length->getUpper()->getInteger(INT_MIN); } std::string StringType::writeOut(int /*indent*/) { std::string s; s.append("String"); bool parenthesis = false; if(mimeType.size() > 0) { s += "(mimeType=\"" + mimeType + "\""; parenthesis = true; } if(pattern.size() > 0) { if(parenthesis == false) { s += "("; } else { s += ", "; } s += "pattern=\"" + pattern + "\""; parenthesis = true; } if(parenthesis == true) { s += ")"; } return s; } } }