diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/include/coreutil.h | 376 |
1 files changed, 188 insertions, 188 deletions
diff --git a/libraries/irrlicht-1.8/include/coreutil.h b/libraries/irrlicht-1.8/include/coreutil.h index 2ab4855..eaf0097 100644 --- a/libraries/irrlicht-1.8/include/coreutil.h +++ b/libraries/irrlicht-1.8/include/coreutil.h | |||
@@ -1,188 +1,188 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #ifndef __IRR_CORE_UTIL_H_INCLUDED__ | 5 | #ifndef __IRR_CORE_UTIL_H_INCLUDED__ |
6 | #define __IRR_CORE_UTIL_H_INCLUDED__ | 6 | #define __IRR_CORE_UTIL_H_INCLUDED__ |
7 | 7 | ||
8 | #include "irrString.h" | 8 | #include "irrString.h" |
9 | #include "path.h" | 9 | #include "path.h" |
10 | 10 | ||
11 | namespace irr | 11 | namespace irr |
12 | { | 12 | { |
13 | namespace core | 13 | namespace core |
14 | { | 14 | { |
15 | 15 | ||
16 | /*! \file coreutil.h | 16 | /*! \file coreutil.h |
17 | \brief File containing useful basic utility functions | 17 | \brief File containing useful basic utility functions |
18 | */ | 18 | */ |
19 | 19 | ||
20 | // ----------- some basic quite often used string functions ----------------- | 20 | // ----------- some basic quite often used string functions ----------------- |
21 | 21 | ||
22 | //! search if a filename has a proper extension | 22 | //! search if a filename has a proper extension |
23 | inline s32 isFileExtension ( const io::path& filename, | 23 | inline s32 isFileExtension ( const io::path& filename, |
24 | const io::path& ext0, | 24 | const io::path& ext0, |
25 | const io::path& ext1, | 25 | const io::path& ext1, |
26 | const io::path& ext2) | 26 | const io::path& ext2) |
27 | { | 27 | { |
28 | s32 extPos = filename.findLast ( '.' ); | 28 | s32 extPos = filename.findLast ( '.' ); |
29 | if ( extPos < 0 ) | 29 | if ( extPos < 0 ) |
30 | return 0; | 30 | return 0; |
31 | 31 | ||
32 | extPos += 1; | 32 | extPos += 1; |
33 | if ( filename.equals_substring_ignore_case ( ext0, extPos ) ) return 1; | 33 | if ( filename.equals_substring_ignore_case ( ext0, extPos ) ) return 1; |
34 | if ( filename.equals_substring_ignore_case ( ext1, extPos ) ) return 2; | 34 | if ( filename.equals_substring_ignore_case ( ext1, extPos ) ) return 2; |
35 | if ( filename.equals_substring_ignore_case ( ext2, extPos ) ) return 3; | 35 | if ( filename.equals_substring_ignore_case ( ext2, extPos ) ) return 3; |
36 | return 0; | 36 | return 0; |
37 | } | 37 | } |
38 | 38 | ||
39 | //! search if a filename has a proper extension | 39 | //! search if a filename has a proper extension |
40 | inline bool hasFileExtension ( const io::path& filename, | 40 | inline bool hasFileExtension ( const io::path& filename, |
41 | const io::path& ext0, | 41 | const io::path& ext0, |
42 | const io::path& ext1 = "", | 42 | const io::path& ext1 = "", |
43 | const io::path& ext2 = "") | 43 | const io::path& ext2 = "") |
44 | { | 44 | { |
45 | return isFileExtension ( filename, ext0, ext1, ext2 ) > 0; | 45 | return isFileExtension ( filename, ext0, ext1, ext2 ) > 0; |
46 | } | 46 | } |
47 | 47 | ||
48 | //! cut the filename extension from a source file path and store it in a dest file path | 48 | //! cut the filename extension from a source file path and store it in a dest file path |
49 | inline io::path& cutFilenameExtension ( io::path &dest, const io::path &source ) | 49 | inline io::path& cutFilenameExtension ( io::path &dest, const io::path &source ) |
50 | { | 50 | { |
51 | s32 endPos = source.findLast ( '.' ); | 51 | s32 endPos = source.findLast ( '.' ); |
52 | dest = source.subString ( 0, endPos < 0 ? source.size () : endPos ); | 52 | dest = source.subString ( 0, endPos < 0 ? source.size () : endPos ); |
53 | return dest; | 53 | return dest; |
54 | } | 54 | } |
55 | 55 | ||
56 | //! get the filename extension from a file path | 56 | //! get the filename extension from a file path |
57 | inline io::path& getFileNameExtension ( io::path &dest, const io::path &source ) | 57 | inline io::path& getFileNameExtension ( io::path &dest, const io::path &source ) |
58 | { | 58 | { |
59 | s32 endPos = source.findLast ( '.' ); | 59 | s32 endPos = source.findLast ( '.' ); |
60 | if ( endPos < 0 ) | 60 | if ( endPos < 0 ) |
61 | dest = ""; | 61 | dest = ""; |
62 | else | 62 | else |
63 | dest = source.subString ( endPos, source.size () ); | 63 | dest = source.subString ( endPos, source.size () ); |
64 | return dest; | 64 | return dest; |
65 | } | 65 | } |
66 | 66 | ||
67 | //! delete path from filename | 67 | //! delete path from filename |
68 | inline io::path& deletePathFromFilename(io::path& filename) | 68 | inline io::path& deletePathFromFilename(io::path& filename) |
69 | { | 69 | { |
70 | // delete path from filename | 70 | // delete path from filename |
71 | const fschar_t* s = filename.c_str(); | 71 | const fschar_t* s = filename.c_str(); |
72 | const fschar_t* p = s + filename.size(); | 72 | const fschar_t* p = s + filename.size(); |
73 | 73 | ||
74 | // search for path separator or beginning | 74 | // search for path separator or beginning |
75 | while ( *p != '/' && *p != '\\' && p != s ) | 75 | while ( *p != '/' && *p != '\\' && p != s ) |
76 | p--; | 76 | p--; |
77 | 77 | ||
78 | if ( p != s ) | 78 | if ( p != s ) |
79 | { | 79 | { |
80 | ++p; | 80 | ++p; |
81 | filename = p; | 81 | filename = p; |
82 | } | 82 | } |
83 | return filename; | 83 | return filename; |
84 | } | 84 | } |
85 | 85 | ||
86 | //! trim paths | 86 | //! trim paths |
87 | inline io::path& deletePathFromPath(io::path& filename, s32 pathCount) | 87 | inline io::path& deletePathFromPath(io::path& filename, s32 pathCount) |
88 | { | 88 | { |
89 | // delete path from filename | 89 | // delete path from filename |
90 | s32 i = filename.size(); | 90 | s32 i = filename.size(); |
91 | 91 | ||
92 | // search for path separator or beginning | 92 | // search for path separator or beginning |
93 | while ( i>=0 ) | 93 | while ( i>=0 ) |
94 | { | 94 | { |
95 | if ( filename[i] == '/' || filename[i] == '\\' ) | 95 | if ( filename[i] == '/' || filename[i] == '\\' ) |
96 | { | 96 | { |
97 | if ( --pathCount <= 0 ) | 97 | if ( --pathCount <= 0 ) |
98 | break; | 98 | break; |
99 | } | 99 | } |
100 | --i; | 100 | --i; |
101 | } | 101 | } |
102 | 102 | ||
103 | if ( i>0 ) | 103 | if ( i>0 ) |
104 | { | 104 | { |
105 | filename [ i + 1 ] = 0; | 105 | filename [ i + 1 ] = 0; |
106 | filename.validate(); | 106 | filename.validate(); |
107 | } | 107 | } |
108 | else | 108 | else |
109 | filename=""; | 109 | filename=""; |
110 | return filename; | 110 | return filename; |
111 | } | 111 | } |
112 | 112 | ||
113 | //! looks if file is in the same directory of path. returns offset of directory. | 113 | //! looks if file is in the same directory of path. returns offset of directory. |
114 | //! 0 means in same directory. 1 means file is direct child of path | 114 | //! 0 means in same directory. 1 means file is direct child of path |
115 | inline s32 isInSameDirectory ( const io::path& path, const io::path& file ) | 115 | inline s32 isInSameDirectory ( const io::path& path, const io::path& file ) |
116 | { | 116 | { |
117 | s32 subA = 0; | 117 | s32 subA = 0; |
118 | s32 subB = 0; | 118 | s32 subB = 0; |
119 | s32 pos; | 119 | s32 pos; |
120 | 120 | ||
121 | if ( path.size() && !path.equalsn ( file, path.size() ) ) | 121 | if ( path.size() && !path.equalsn ( file, path.size() ) ) |
122 | return -1; | 122 | return -1; |
123 | 123 | ||
124 | pos = 0; | 124 | pos = 0; |
125 | while ( (pos = path.findNext ( '/', pos )) >= 0 ) | 125 | while ( (pos = path.findNext ( '/', pos )) >= 0 ) |
126 | { | 126 | { |
127 | subA += 1; | 127 | subA += 1; |
128 | pos += 1; | 128 | pos += 1; |
129 | } | 129 | } |
130 | 130 | ||
131 | pos = 0; | 131 | pos = 0; |
132 | while ( (pos = file.findNext ( '/', pos )) >= 0 ) | 132 | while ( (pos = file.findNext ( '/', pos )) >= 0 ) |
133 | { | 133 | { |
134 | subB += 1; | 134 | subB += 1; |
135 | pos += 1; | 135 | pos += 1; |
136 | } | 136 | } |
137 | 137 | ||
138 | return subB - subA; | 138 | return subB - subA; |
139 | } | 139 | } |
140 | 140 | ||
141 | // splits a path into components | 141 | // splits a path into components |
142 | static inline void splitFilename(const io::path &name, io::path* path=0, | 142 | static inline void splitFilename(const io::path &name, io::path* path=0, |
143 | io::path* filename=0, io::path* extension=0, bool make_lower=false) | 143 | io::path* filename=0, io::path* extension=0, bool make_lower=false) |
144 | { | 144 | { |
145 | s32 i = name.size(); | 145 | s32 i = name.size(); |
146 | s32 extpos = i; | 146 | s32 extpos = i; |
147 | 147 | ||
148 | // search for path separator or beginning | 148 | // search for path separator or beginning |
149 | while ( i >= 0 ) | 149 | while ( i >= 0 ) |
150 | { | 150 | { |
151 | if ( name[i] == '.' ) | 151 | if ( name[i] == '.' ) |
152 | { | 152 | { |
153 | extpos = i; | 153 | extpos = i; |
154 | if ( extension ) | 154 | if ( extension ) |
155 | *extension = name.subString ( extpos + 1, name.size() - (extpos + 1), make_lower ); | 155 | *extension = name.subString ( extpos + 1, name.size() - (extpos + 1), make_lower ); |
156 | } | 156 | } |
157 | else | 157 | else |
158 | if ( name[i] == '/' || name[i] == '\\' ) | 158 | if ( name[i] == '/' || name[i] == '\\' ) |
159 | { | 159 | { |
160 | if ( filename ) | 160 | if ( filename ) |
161 | *filename = name.subString ( i + 1, extpos - (i + 1), make_lower ); | 161 | *filename = name.subString ( i + 1, extpos - (i + 1), make_lower ); |
162 | if ( path ) | 162 | if ( path ) |
163 | { | 163 | { |
164 | *path = name.subString ( 0, i + 1, make_lower ); | 164 | *path = name.subString ( 0, i + 1, make_lower ); |
165 | path->replace ( '\\', '/' ); | 165 | path->replace ( '\\', '/' ); |
166 | } | 166 | } |
167 | return; | 167 | return; |
168 | } | 168 | } |
169 | i -= 1; | 169 | i -= 1; |
170 | } | 170 | } |
171 | if ( filename ) | 171 | if ( filename ) |
172 | *filename = name.subString ( 0, extpos, make_lower ); | 172 | *filename = name.subString ( 0, extpos, make_lower ); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | //! some standard function ( to remove dependencies ) | 176 | //! some standard function ( to remove dependencies ) |
177 | #undef isdigit | 177 | #undef isdigit |
178 | #undef isspace | 178 | #undef isspace |
179 | #undef isupper | 179 | #undef isupper |
180 | inline s32 isdigit(s32 c) { return c >= '0' && c <= '9'; } | 180 | inline s32 isdigit(s32 c) { return c >= '0' && c <= '9'; } |
181 | inline s32 isspace(s32 c) { return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; } | 181 | inline s32 isspace(s32 c) { return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; } |
182 | inline s32 isupper(s32 c) { return c >= 'A' && c <= 'Z'; } | 182 | inline s32 isupper(s32 c) { return c >= 'A' && c <= 'Z'; } |
183 | 183 | ||
184 | 184 | ||
185 | } // end namespace core | 185 | } // end namespace core |
186 | } // end namespace irr | 186 | } // end namespace irr |
187 | 187 | ||
188 | #endif | 188 | #endif |