/usr/include/opencollada/COLLADABaseUtils/COLLADABUStringUtils.h is in opencollada-dev 0.1.0~20160714.0ec5063+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /*
Copyright (c) 2008-2009 NetAllied Systems GmbH
This file is part of COLLADABaseUtils.
Licensed under the MIT Open Source License,
for details please see LICENSE file or the website
http://www.opensource.org/licenses/mit-license.php
*/
#ifndef __COLLADABU_STRINGUTILS_H__
#define __COLLADABU_STRINGUTILS_H__
#include "COLLADABUPrerequisites.h"
#include "COLLADABUNativeString.h"
#include <sstream>
#include <fstream>
#include <map>
namespace COLLADABU
{
/** A class that holds some static COLLADA utility functions*/
class StringUtils
{
public:
/**
* Returns true, if both strings are equal. The comparison is case sensitive.
*/
template<class StringType>
static bool equals ( const StringType &str1, const StringType &str2 )
{
if ( str1.length() != str2.length() )
return false;
return ( strcmp ( str1.c_str(), str2.c_str() ) == 0 );
}
/**
* Returns true, if both strings are equal. The comparison is case intensitive.
*/
static bool equalsIgnoreCase ( const WideString& s1, const WideString& s2 );
/** Checks for a valid xs:NCName.
1. replaces all not allowed characters
2. forces that the string begins with a letter or an _
@param ncName The string to convert to a valid xs:NCName.
@return The checked string
*/
static WideString checkNCName ( const WideString &ncName );
// static UTF8String checkNCName ( const UTF8String &ncName ){return UTF8String();};
/** Checks for a valid xs:ID.
1. replaces all not allowed characters
2. forces that the string begins with a letter or an _
@param ncName The string to convert to a valid xs:ID.
@return The checked string
*/
static WideString checkID ( const WideString &id );
// static UTF8String checkID ( const UTF8String &id ){return UTF8String();};
/** Checks if @a c is name start character according to http://www.w3.org/TR/xml11/#NT-NameStartChar */
static bool isNameStartChar ( wchar_t c );
/** Checks if @a c is name character according to http://www.w3.org/TR/xml11/#NT-NameChar */
static bool isNameChar ( wchar_t c );
/** Checks if @a c is an upper ASCII character*/
static bool isUpperAsciiChar ( char c )
{
return ( c >= 'A' ) && ( c <= 'Z' ) ;
}
/** Checks if @a c is a lower ASCII character*/
static bool isLowerAsciiChar ( char c )
{
return ( c >= 'a' ) && ( c <= 'z' ) ;
}
/** Checks if @a c is an ASCII character*/
static bool isAsciiAlphaChar ( char c )
{
return isLowerAsciiChar ( c ) || isUpperAsciiChar ( c ) ;
}
/** Checks if @a c is a digit*/
static bool isDigit ( char c )
{
return ( c >= '0' ) && ( c <= '9' ) ;
}
/** Checks if @a c is an xs:id character, but not alpha numeric*/
static bool isIDExtraChar ( char c )
{
return ( c == '.' ) || ( c == '-' ) || ( c == '_' ) ;
}
/** Checks if @a c is an xs:id character, but not alpha numeric*/
static bool isIDChar ( char c )
{
return isAsciiAlphaChar ( c ) || isDigit ( c ) || isIDExtraChar ( c ) ;
}
/** If @a c is a lower case ascii character, the corresponding upper character is returned.*/
static char toUpperASCIIChar( char c );
static String uriEncode ( const String & sSrc );
/** Escapes all the characters not allowed in xml text elements.
@param srcString The string to translate.
@return The translated string.*/
static String translateToXML ( const String &srcString );
/** Escapes all the characters not allowed in xml text elements.
@param srcString The string to translate.
@return The translated string.*/
static WideString translateToXML ( const WideString &srcString );
/** Returns @a text with all dots replaced by underlines*/
static String replaceDot ( const String &text );
/** Converts @a value to a NativeString.
@param T The type of the value to convert.
@param value The value of type @a T to convert to a NativeString.
*/
template<class T>
static NativeString toNativeString ( const T & value )
{
std::stringstream stream;
stream << value;
return NativeString(stream.str());
}
/** Converts @a value to a UTF8String.
@param T The type of the value to convert.
@param value The value of type @a T to convert to a UTF8String.
*/
template<class T>
static String toUTF8String( const T & value )
{
std::stringstream stream;
stream << value;
return String(stream.str());
}
/** Converts @a value to a String.
@param T The type of the value to convert.
@param value The value of type @a T to convert to a string.
*/
template<class T>
static WideString toWideString ( const T & value )
{
std::wstringstream stream;
stream << value;
return WideString(stream.str());
}
/**
* Searches all search strings in the source string and replace it with the replaceString.
* @param source Reference to the source string.
* @param searchString The search string.
* @param replaceString The replace string.
*/
template<class StringType>
static void stringFindAndReplace ( StringType &source, const StringType searchString, const StringType replaceString )
{
size_t found = source.find ( searchString );
if ( found != StringType::npos )
{
size_t searchStrLength = searchString.length();
size_t replaceStrLength = replaceString.length();
do
{
source.replace ( found, searchStrLength, replaceString );
found = source.find (searchString, found + replaceStrLength );
} while ( found != StringType::npos );
}
}
/** Converts the utf8 encoded string @a utf8String to a unicode encoded widestring.*/
static WideString utf8String2WideString( const String& utf8String );
/** Converts the unicode encoded string @a wideString to a UTF encoded string.*/
static String wideString2utf8String( const WideString& wideString );
};
}
#endif // __COLLADABU_STRINGUTILS_H__
|