diff options
Diffstat (limited to 'src/uscxml/Convenience.h')
-rw-r--r-- | src/uscxml/Convenience.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/uscxml/Convenience.h b/src/uscxml/Convenience.h index cbc38d9..88afa8d 100644 --- a/src/uscxml/Convenience.h +++ b/src/uscxml/Convenience.h @@ -20,6 +20,7 @@ #ifndef CONVENIENCE_H_LU7GZ6CB #define CONVENIENCE_H_LU7GZ6CB +#include "uscxml/Common.h" #include <inttypes.h> #include <stdlib.h> #include <boost/detail/endian.hpp> @@ -43,6 +44,31 @@ template <typename T> T strTo(std::string tmp) { return output; } +class USCXML_API NumAttr { +public: + NumAttr(const std::string& str) { + size_t valueStart = str.find_first_of("0123456789."); + if (valueStart != std::string::npos) { + size_t valueEnd = str.find_last_of("0123456789."); + if (valueEnd != std::string::npos) { + value = str.substr(valueStart, (valueEnd - valueStart) + 1); + size_t unitStart = str.find_first_not_of(" \t", valueEnd + 1); + if (unitStart != std::string::npos) { + size_t unitEnd = str.find_last_of(" \t"); + if (unitEnd != std::string::npos && unitEnd > unitStart) { + unit = str.substr(unitStart, unitEnd - unitStart); + } else { + unit = str.substr(unitStart, str.length() - unitStart); + } + } + } + } + } + + std::string value; + std::string unit; +}; + bool isNumeric(const char* pszInput, int nNumberBase); bool isInteger( const char* pszInput, int nNumberBase); bool iequals(const std::string& a, const std::string& b); @@ -51,6 +77,7 @@ bool stringIsTrue(const std::string& value); bool envVarIsTrue(const char* name); bool envVarIEquals(const char* name, const char* value); +std::string escape(const std::string& a); std::string unescape(const std::string& a); // see http://www.cplusplus.com/forum/general/27544/ |