CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUStrings.h
1 //
2 // CUStrings.h
3 // Cornell University Game Library (CUGL)
4 //
5 // Android does not support a lot of the built-in string methods. Therefore,
6 // we need alternate definitions that are platform agnostic. Note that these
7 // functions have names that are very similar to those in the std namespace,
8 // but all live in the cocos2d namespace.
9 //
10 // Note that this module does not refer to the integral types as short, int,
11 // long, etc. Those types are NOT cross-platform. For example, a long is
12 // 8 bytes on Unix/OS X, but 4 bytes on some Win32 platforms.
13 //
14 // CUGL MIT License:
15 // This software is provided 'as-is', without any express or implied
16 // warranty. In no event will the authors be held liable for any damages
17 // arising from the use of this software.
18 //
19 // Permission is granted to anyone to use this software for any purpose,
20 // including commercial applications, and to alter it and redistribute it
21 // freely, subject to the following restrictions:
22 //
23 // 1. The origin of this software must not be misrepresented; you must not
24 // claim that you wrote the original software. If you use this software
25 // in a product, an acknowledgment in the product documentation would be
26 // appreciated but is not required.
27 //
28 // 2. Altered source versions must be plainly marked as such, and must not
29 // be misrepresented as being the original software.
30 //
31 // 3. This notice may not be removed or altered from any source distribution.
32 //
33 // Author: Walker White
34 // Version: 2/10/16
35 //
36 #ifndef __CU_STRINGS_H_
37 #define __CU_STRINGS_H_
38 #include <SDL/SDL.h>
39 #include <vector>
40 #include <string>
41 #include <locale>
42 #include <algorithm>
43 
44 namespace cugl {
45 
46 #pragma mark NUMBER TO STRING FUNCTIONS
47 
56  std::string to_string(Uint8 value);
57 
65  std::string to_string(Sint16 value);
66 
74  std::string to_string(Uint16 value);
75 
83  std::string to_string(Sint32 value);
84 
92  std::string to_string(Uint32 value );
93 
101  std::string to_string(Sint64 value );
102 
110  std::string to_string(Uint64 value );
111 
124  std::string to_string(float value, int precision=-1);
125 
138  std::string to_string(double value, int precision=-1);
139 
140 
141 #pragma mark -
142 #pragma mark ARRAY TO STRING FUNCTIONS
143 
154  std::string to_string(Uint8* array, size_t length, size_t offset=0);
155 
167  std::string to_string(Sint16* array, size_t length, size_t offset=0);
168 
180  std::string to_string(Uint16* array, size_t length, size_t offset=0);
181 
193  std::string to_string(Sint32* array, size_t length, size_t offset=0);
194 
206  std::string to_string(Uint32* array, size_t length, size_t offset=0);
207 
219  std::string to_string(Sint64* array, size_t length, size_t offset=0);
220 
232  std::string to_string(Uint64* array, size_t length, size_t offset=0);
233 
249  std::string to_string(float* array, size_t length, size_t offset=0, int precision=-1);
250 
266  std::string to_string(double* array, size_t length, size_t offset=0, int precision=-1);
267 
268 
269 #pragma mark -
270 #pragma mark STRING TO NUMBER FUNCTIONS
271 
285  Uint8 stou8(const std::string& str, std::size_t* pos = 0, int base = 10);
286 
301  Sint16 stos16(const std::string& str, std::size_t* pos = 0, int base = 10);
302 
317  Uint16 stou16(const std::string& str, std::size_t* pos = 0, int base = 10);
318 
333  Sint32 stos32(const std::string& str, std::size_t* pos = 0, int base = 10);
334 
349  Uint32 stou32(const std::string& str, std::size_t* pos = 0, int base = 10);
350 
365  Sint64 stos64(const std::string& str, std::size_t* pos = 0, int base = 10);
366 
381  Uint64 stou64(const std::string& str, std::size_t* pos = 0, int base = 10);
382 
396  float stof(const std::string& str, std::size_t* pos = 0);
397 
411  double stod(const std::string& str, std::size_t* pos = 0);
412 
413 
414 #pragma mark -
415 #pragma mark UTILITY FUNCTIONS
416 
425  std::string to_lower(const std::string& str);
426 
436  std::string to_upper(const std::string& str);
437 
447  std::string trim(const std::string& str);
448 
461  std::vector<std::string> split(const std::string& str, const std::string& sep);
462 
475  std::vector<std::string> split(const std::string& str, const char* sep);
476 
486  bool isalpha(const std::string& str);
487 
497  bool isalphanum(const std::string& str);
498 
508  bool isnumeric(const std::string& str);
509 
519  bool isnumber(const std::string& str);
520 
521 }
522 
523 #endif /* __CU_STRINGS_H_ */