46 #ifndef AI_PARSING_UTILS_H_INC
47 #define AI_PARSING_UTILS_H_INC
50 #pragma GCC system_header
53 #include <assimp/StringComparison.h>
54 #include <assimp/StringUtils.h>
69 static const unsigned int BufferSize = 4096;
72 template <
class char_t>
73 AI_FORCE_INLINE char_t ToLower(char_t in) {
74 return (in >= (char_t)
'A' && in <= (char_t)
'Z') ? (char_t)(in + 0x20) : in;
78 template <
class char_t>
79 AI_FORCE_INLINE char_t ToUpper(char_t in) {
80 return (in >= (char_t)
'a' && in <= (char_t)
'z') ? (char_t)(in - 0x20) : in;
84 template <
class char_t>
85 AI_FORCE_INLINE
bool IsUpper(char_t in) {
86 return (in >= (char_t)
'A' && in <= (char_t)
'Z');
90 template <
class char_t>
91 AI_FORCE_INLINE
bool IsLower(char_t in) {
92 return (in >= (char_t)
'a' && in <= (char_t)
'z');
96 template <
class char_t>
97 AI_FORCE_INLINE
bool IsSpace(char_t in) {
98 return (in == (char_t)
' ' || in == (char_t)
'\t');
102 template <
class char_t>
103 AI_FORCE_INLINE
bool IsLineEnd(char_t in) {
104 return (in == (char_t)
'\r' || in == (char_t)
'\n' || in == (char_t)
'\0' || in == (char_t)
'\f');
108 template <
class char_t>
109 AI_FORCE_INLINE
bool IsSpaceOrNewLine(char_t in) {
110 return IsSpace<char_t>(in) || IsLineEnd<char_t>(in);
114 template <
class char_t>
115 AI_FORCE_INLINE
bool SkipSpaces(
const char_t *in,
const char_t **out) {
116 while (*in == (char_t)
' ' || *in == (char_t)
'\t') {
120 return !IsLineEnd<char_t>(*in);
124 template <
class char_t>
125 AI_FORCE_INLINE
bool SkipSpaces(
const char_t **inout) {
126 return SkipSpaces<char_t>(*inout, inout);
130 template <
class char_t>
131 AI_FORCE_INLINE
bool SkipLine(
const char_t *in,
const char_t **out) {
132 while (*in != (char_t)
'\r' && *in != (char_t)
'\n' && *in != (char_t)
'\0') {
137 while (*in == (char_t)
'\r' || *in == (char_t)
'\n') {
141 return *in != (char_t)
'\0';
145 template <
class char_t>
146 AI_FORCE_INLINE
bool SkipLine(
const char_t **inout) {
147 return SkipLine<char_t>(*inout, inout);
151 template <
class char_t>
152 AI_FORCE_INLINE
bool SkipSpacesAndLineEnd(
const char_t *in,
const char_t **out) {
153 while (*in == (char_t)
' ' || *in == (char_t)
'\t' || *in == (char_t)
'\r' || *in == (char_t)
'\n') {
161 template <
class char_t>
162 AI_FORCE_INLINE
bool SkipSpacesAndLineEnd(
const char_t **inout) {
163 return SkipSpacesAndLineEnd<char_t>(*inout, inout);
167 template <
class char_t>
168 AI_FORCE_INLINE
bool GetNextLine(
const char_t *&buffer, char_t out[BufferSize]) {
169 if ((char_t)
'\0' == *buffer) {
174 char *
const end = _out + BufferSize;
175 while (!IsLineEnd(*buffer) && _out < end) {
178 *_out = (char_t)
'\0';
180 while (IsLineEnd(*buffer) &&
'\0' != *buffer) {
188 template <
class char_t>
189 AI_FORCE_INLINE
bool IsNumeric(char_t in) {
190 return (in >=
'0' && in <=
'9') ||
'-' == in ||
'+' == in;
194 template <
class char_t>
195 AI_FORCE_INLINE
bool TokenMatch(char_t *&in,
const char *token,
unsigned int len) {
196 if (!::strncmp(token, in, len) && IsSpaceOrNewLine(in[len])) {
197 if (in[len] !=
'\0') {
214 AI_FORCE_INLINE
bool TokenMatchI(
const char *&in,
const char *token,
unsigned int len) {
223 AI_FORCE_INLINE
void SkipToken(
const char *&in) {
225 while (!IsSpaceOrNewLine(*in)) {
231 AI_FORCE_INLINE std::string GetNextToken(
const char *&in) {
232 SkipSpacesAndLineEnd(&in);
233 const char *cur = in;
234 while (!IsSpaceOrNewLine(*in)) {
237 return std::string(cur, (
size_t)(in - cur));
247 template <
class string_type>
248 AI_FORCE_INLINE
unsigned int tokenize(
const string_type &str, std::vector<string_type> &tokens,
249 const string_type &delimiters) {
251 typename string_type::size_type lastPos = str.find_first_not_of(delimiters, 0);
254 typename string_type::size_type pos = str.find_first_of(delimiters, lastPos);
255 while (string_type::npos != pos || string_type::npos != lastPos) {
257 string_type tmp = str.substr(lastPos, pos - lastPos);
258 if (!tmp.empty() &&
' ' != tmp[0])
259 tokens.push_back(tmp);
262 lastPos = str.find_first_not_of(delimiters, pos);
265 pos = str.find_first_of(delimiters, lastPos);
268 return static_cast<unsigned int>(tokens.size());
271 inline std::string ai_stdStrToLower(
const std::string &str) {
272 std::string out(str);
273 for (
size_t i = 0; i < str.size(); ++i) {
274 out[i] = (char) tolower(out[i]);
281 #endif // ! AI_PARSING_UTILS_H_INC