Mercurial > libanimone
annotate include/animone/util.h @ 32:93224b26a0ee default tip
player: efforts towards C-ization
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 10 Feb 2025 19:17:29 -0500 |
| parents | a76e55e098d1 |
| children |
| rev | line source |
|---|---|
|
14
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
1 #ifndef ANIMONE_ANIMONE_UTIL_H_ |
|
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
2 #define ANIMONE_ANIMONE_UTIL_H_ |
|
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
3 |
| 30 | 4 #include <stdint.h> |
| 5 #include <stddef.h> | |
| 6 | |
| 7 #ifdef __cplusplus | |
| 8 extern "C" { | |
| 9 #endif | |
|
14
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
10 |
| 30 | 11 int animone_internal_util_ReadFile(const char *path, char **data, size_t *size); |
| 12 int animone_internal_util_EqualStrings(const char *str1, const char *str2); | |
| 13 char *animone_internal_util_Stem(const char *filename); | |
| 14 int animone_internal_util_CheckPattern(const char *pattern, const char *str); | |
| 15 int animone_internal_util_TrimLeft(char *str, const char* chars); | |
| 16 int animone_internal_util_TrimRight(char *str, const char* chars); | |
| 17 | |
| 18 intmax_t animone_internal_util_StringToInt(const char *ptr, intmax_t def); | |
| 19 | |
| 20 #ifdef __cplusplus | |
| 21 } | |
|
14
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
22 |
| 30 | 23 #include <string> |
| 24 #include <cstdlib> | |
| 25 | |
| 26 namespace animone { | |
| 27 namespace internal { | |
| 28 namespace util { | |
|
14
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
29 |
| 30 | 30 // Compatibility bindings, to keep the existing C++ code working |
| 31 inline bool ReadFile(const std::string &path, std::string &data) | |
| 32 { | |
| 33 char *data_c; | |
| 34 size_t size_c; | |
| 35 | |
| 36 int x = ::animone_internal_util_ReadFile(path.c_str(), &data_c, &size_c); | |
| 37 | |
| 38 data.assign(data_c, size_c); | |
| 39 | |
| 40 std::free(data_c); | |
| 41 | |
| 42 return static_cast<bool>(x); | |
|
14
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
43 } |
|
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
44 |
| 30 | 45 inline bool EqualStrings(const std::string &str1, const std::string &str2) |
| 46 { | |
| 47 return static_cast<bool>(::animone_internal_util_EqualStrings(str1.c_str(), str2.c_str())); | |
| 48 } | |
| 49 | |
| 50 inline bool Stem(const std::string &filename, std::string &stem) | |
| 51 { | |
| 52 char *stem_c = ::animone_internal_util_Stem(filename.c_str()); | |
| 53 if (!stem_c) | |
| 54 return 0; | |
| 55 | |
| 56 stem.assign(stem_c); | |
| 57 | |
| 58 std::free(stem_c); | |
| 59 | |
| 60 return 1; | |
| 61 } | |
| 62 | |
| 63 inline bool CheckPattern(const std::string &pattern, const std::string &str) | |
| 64 { | |
| 65 return static_cast<bool>(::animone_internal_util_CheckPattern(pattern.c_str(), str.c_str())); | |
| 66 } | |
| 67 | |
| 68 inline bool TrimLeft(std::string &str, const char *chars) | |
| 69 { | |
| 70 return ::animone_internal_util_TrimLeft(str.data(), chars); | |
| 71 } | |
| 72 | |
| 73 inline bool TrimRight(std::string &str, const char* chars) | |
| 74 { | |
| 75 return ::animone_internal_util_TrimRight(str.data(), chars); | |
| 76 } | |
| 77 | |
| 78 inline intmax_t StringToInt(const std::string &ptr, intmax_t def) | |
| 79 { | |
| 80 return ::animone_internal_util_StringToInt(ptr.c_str(), def); | |
| 81 } | |
| 82 | |
| 83 } // namespace util | |
| 84 } // namespace internal | |
| 85 } // namespace animone | |
| 86 | |
| 87 #endif | |
|
14
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
88 |
|
27b988a1048c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
0
diff
changeset
|
89 #endif // ANIMONE_ANIMONE_UTIL_H_ |
