vrshoot

diff libs/assimp/ParsingUtils.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/ParsingUtils.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,210 @@
     1.4 +/*
     1.5 +Open Asset Import Library (assimp)
     1.6 +----------------------------------------------------------------------
     1.7 +
     1.8 +Copyright (c) 2006-2012, assimp team
     1.9 +All rights reserved.
    1.10 +
    1.11 +Redistribution and use of this software in source and binary forms, 
    1.12 +with or without modification, are permitted provided that the 
    1.13 +following conditions are met:
    1.14 +
    1.15 +* Redistributions of source code must retain the above
    1.16 +  copyright notice, this list of conditions and the
    1.17 +  following disclaimer.
    1.18 +
    1.19 +* Redistributions in binary form must reproduce the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer in the documentation and/or other
    1.22 +  materials provided with the distribution.
    1.23 +
    1.24 +* Neither the name of the assimp team, nor the names of its
    1.25 +  contributors may be used to endorse or promote products
    1.26 +  derived from this software without specific prior
    1.27 +  written permission of the assimp team.
    1.28 +
    1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 +
    1.41 +----------------------------------------------------------------------
    1.42 +*/
    1.43 +
    1.44 +
    1.45 +/** @file ParsingUtils.h
    1.46 + *  @brief Defines helper functions for text parsing 
    1.47 + */
    1.48 +#ifndef AI_PARSING_UTILS_H_INC
    1.49 +#define AI_PARSING_UTILS_H_INC
    1.50 +
    1.51 +#include "StringComparison.h"
    1.52 +namespace Assimp {
    1.53 +
    1.54 +	// NOTE: the functions below are mostly intended as replacement for
    1.55 +	// std::upper, std::lower, std::isupper, std::islower, std::isspace.
    1.56 +	// we don't bother of locales. We don't want them. We want reliable
    1.57 +	// (i.e. identical) results across all locales.
    1.58 +
    1.59 +	// The functions below accept any character type, but know only
    1.60 +	// about ASCII. However, UTF-32 is the only safe ASCII superset to
    1.61 +	// use since it doesn't have multibyte sequences.
    1.62 +
    1.63 +// ---------------------------------------------------------------------------------
    1.64 +template <class char_t>
    1.65 +AI_FORCE_INLINE char_t ToLower( char_t in)
    1.66 +{
    1.67 +	return (in >= (char_t)'A' && in <= (char_t)'Z') ? (char_t)(in+0x20) : in;
    1.68 +}
    1.69 +// ---------------------------------------------------------------------------------
    1.70 +template <class char_t>
    1.71 +AI_FORCE_INLINE char_t ToUpper( char_t in)
    1.72 +{
    1.73 +	return (in >= (char_t)'a' && in <= (char_t)'z') ? (char_t)(in-0x20) : in;
    1.74 +}
    1.75 +// ---------------------------------------------------------------------------------
    1.76 +template <class char_t>
    1.77 +AI_FORCE_INLINE bool IsUpper( char_t in)
    1.78 +{
    1.79 +	return (in >= (char_t)'A' && in <= (char_t)'Z');
    1.80 +}
    1.81 +// ---------------------------------------------------------------------------------
    1.82 +template <class char_t>
    1.83 +AI_FORCE_INLINE bool IsLower( char_t in)
    1.84 +{
    1.85 +	return (in >= (char_t)'a' && in <= (char_t)'z');
    1.86 +}
    1.87 +// ---------------------------------------------------------------------------------
    1.88 +template <class char_t>
    1.89 +AI_FORCE_INLINE bool IsSpace( char_t in)
    1.90 +{
    1.91 +	return (in == (char_t)' ' || in == (char_t)'\t');
    1.92 +}
    1.93 +// ---------------------------------------------------------------------------------
    1.94 +template <class char_t>
    1.95 +AI_FORCE_INLINE bool IsLineEnd( char_t in)
    1.96 +{
    1.97 +	return (in == (char_t)'\r' || in == (char_t)'\n' || in == (char_t)'\0');
    1.98 +}
    1.99 +// ---------------------------------------------------------------------------------
   1.100 +template <class char_t>
   1.101 +AI_FORCE_INLINE bool IsSpaceOrNewLine( char_t in)
   1.102 +{
   1.103 +	return IsSpace<char_t>(in) || IsLineEnd<char_t>(in);
   1.104 +}
   1.105 +// ---------------------------------------------------------------------------------
   1.106 +template <class char_t>
   1.107 +AI_FORCE_INLINE bool SkipSpaces( const char_t* in, const char_t** out)
   1.108 +{
   1.109 +	while (*in == (char_t)' ' || *in == (char_t)'\t')in++;
   1.110 +	*out = in;
   1.111 +	return !IsLineEnd<char_t>(*in);
   1.112 +}
   1.113 +// ---------------------------------------------------------------------------------
   1.114 +template <class char_t>
   1.115 +AI_FORCE_INLINE bool SkipSpaces( const char_t** inout)
   1.116 +{
   1.117 +	return SkipSpaces<char_t>(*inout,inout);
   1.118 +}
   1.119 +// ---------------------------------------------------------------------------------
   1.120 +template <class char_t>
   1.121 +inline bool SkipLine( const char_t* in, const char_t** out)
   1.122 +{
   1.123 +	while (*in != (char_t)'\r' && *in != (char_t)'\n' && *in != (char_t)'\0')in++;
   1.124 +
   1.125 +	// files are opened in binary mode. Ergo there are both NL and CR
   1.126 +	while (*in == (char_t)'\r' || *in == (char_t)'\n')in++;
   1.127 +	*out = in;
   1.128 +	return *in != (char_t)'\0';
   1.129 +}
   1.130 +// ---------------------------------------------------------------------------------
   1.131 +template <class char_t>
   1.132 +inline bool SkipLine( const char_t** inout)
   1.133 +{
   1.134 +	return SkipLine<char_t>(*inout,inout);
   1.135 +}
   1.136 +// ---------------------------------------------------------------------------------
   1.137 +template <class char_t>
   1.138 +inline bool SkipSpacesAndLineEnd( const char_t* in, const char_t** out)
   1.139 +{
   1.140 +	while (*in == (char_t)' ' || *in == (char_t)'\t' ||
   1.141 +		*in == (char_t)'\r' || *in == (char_t)'\n')in++;
   1.142 +	*out = in;
   1.143 +	return *in != '\0';
   1.144 +}
   1.145 +// ---------------------------------------------------------------------------------
   1.146 +template <class char_t>
   1.147 +inline bool SkipSpacesAndLineEnd( const char_t** inout)
   1.148 +{
   1.149 +	return SkipSpacesAndLineEnd<char_t>(*inout,inout);
   1.150 +}
   1.151 +// ---------------------------------------------------------------------------------
   1.152 +template <class char_t>
   1.153 +inline bool GetNextLine(const char_t*& buffer, char_t out[4096])
   1.154 +{
   1.155 +	if ((char_t)'\0' == *buffer)return false;
   1.156 +
   1.157 +	char* _out = out;
   1.158 +	char* const end = _out+4096;
   1.159 +	while (!IsLineEnd( *buffer ) && _out < end)
   1.160 +		*_out++ = *buffer++;
   1.161 +	*_out = (char_t)'\0';
   1.162 +
   1.163 +	while (IsLineEnd( *buffer ) && '\0' != *buffer)++buffer;
   1.164 +	return true;
   1.165 +}
   1.166 +// ---------------------------------------------------------------------------------
   1.167 +template <class char_t>
   1.168 +AI_FORCE_INLINE bool IsNumeric( char_t in)
   1.169 +{
   1.170 +	return ( in >= '0' && in <= '9' ) || '-' == in || '+' == in;
   1.171 +}
   1.172 +// ---------------------------------------------------------------------------------
   1.173 +template <class char_t>
   1.174 +AI_FORCE_INLINE bool TokenMatch(char_t*& in, const char* token, unsigned int len)
   1.175 +{
   1.176 +	if (!::strncmp(token,in,len) && IsSpaceOrNewLine(in[len]))
   1.177 +	{
   1.178 +		in += len+1;
   1.179 +		return true;
   1.180 +	}
   1.181 +	return false;
   1.182 +}
   1.183 +// ---------------------------------------------------------------------------------
   1.184 +/** @brief Case-ignoring version of TokenMatch
   1.185 + *  @param in Input
   1.186 + *  @param token Token to check for
   1.187 + *  @param len Number of characters to check
   1.188 + */
   1.189 +AI_FORCE_INLINE bool TokenMatchI(const char*& in, const char* token, unsigned int len)
   1.190 +{
   1.191 +	if (!ASSIMP_strincmp(token,in,len) && IsSpaceOrNewLine(in[len]))
   1.192 +	{
   1.193 +		in += len+1;
   1.194 +		return true;
   1.195 +	}
   1.196 +	return false;
   1.197 +}
   1.198 +// ---------------------------------------------------------------------------------
   1.199 +AI_FORCE_INLINE void SkipToken(const char*& in)
   1.200 +{
   1.201 +	SkipSpaces(&in);
   1.202 +	while (!IsSpaceOrNewLine(*in))++in;
   1.203 +}
   1.204 +// ---------------------------------------------------------------------------------
   1.205 +AI_FORCE_INLINE std::string GetNextToken(const char*& in)
   1.206 +{
   1.207 +	SkipSpacesAndLineEnd(&in);
   1.208 +	const char* cur = in;
   1.209 +	while (!IsSpaceOrNewLine(*in))++in;
   1.210 +	return std::string(cur,(size_t)(in-cur));
   1.211 +}
   1.212 +} // ! namespace Assimp
   1.213 +#endif // ! AI_PARSING_UTILS_H_INC