bool StringValidation::IsTime(const std::string &input, void *data) { std::string strTime = input; StringUtils::Trim(strTime); if (StringUtils::EndsWithNoCase(strTime, " min")) { strTime = StringUtils::Left(strTime, strTime.size() - 4); StringUtils::TrimRight(strTime); return IsPositiveInteger(strTime, NULL); } else { size_t pos = strTime.find(":"); // if there's no ":", the value must be in seconds only if (pos == std::string::npos) return IsPositiveInteger(strTime, NULL); std::string strMin = StringUtils::Left(strTime, pos); std::string strSec = StringUtils::Mid(strTime, pos + 1); return IsPositiveInteger(strMin, NULL) && IsPositiveInteger(strSec, NULL); } return false; }
bool StringValidation::IsTime(const std::string &input, void *data) { std::string strTime = input; StringUtils::Trim(strTime); if (StringUtils::EndsWithNoCase(strTime, " min")) { strTime = StringUtils::Left(strTime, strTime.size() - 4); StringUtils::TrimRight(strTime); return IsPositiveInteger(strTime, NULL); } else { // support [[HH:]MM:]SS std::vector<std::string> bits = StringUtils::Split(input, ":"); if (bits.size() > 3) return false; for (std::vector<std::string>::const_iterator i = bits.begin(); i != bits.end(); ++i) if (!IsPositiveInteger(*i, NULL)) return false; return true; } return false; }