RetroArch
stdstring.h
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (stdstring.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __LIBRETRO_SDK_STDSTRING_H
24 #define __LIBRETRO_SDK_STDSTRING_H
25 
26 #include <stdlib.h>
27 #include <stddef.h>
28 #include <ctype.h>
29 #include <string.h>
30 #include <boolean.h>
31 
32 #include <retro_common_api.h>
33 #include <retro_inline.h>
34 #include <compat/strl.h>
35 
37 
38 static INLINE bool string_is_empty(const char *data)
39 {
40  return (data == NULL) || (*data == '\0');
41 }
42 
43 static INLINE bool string_is_equal(const char *a, const char *b)
44 {
45  if (!a || !b)
46  return false;
47  while(*a && (*a == *b))
48  {
49  a++;
50  b++;
51  }
52  return (*(const unsigned char*)a - *(const unsigned char*)b) == 0;
53 }
54 
55 static INLINE bool string_is_not_equal(const char *a, const char *b)
56 {
57  return !string_is_equal(a, b);
58 }
59 
60 #define string_add_pair_open(s, size) strlcat((s), " (", (size))
61 #define string_add_pair_close(s, size) strlcat((s), ")", (size))
62 #define string_add_bracket_open(s, size) strlcat((s), "{", (size))
63 #define string_add_bracket_close(s, size) strlcat((s), "}", (size))
64 #define string_add_single_quote(s, size) strlcat((s), "'", (size))
65 #define string_add_quote(s, size) strlcat((s), "\"", (size))
66 #define string_add_colon(s, size) strlcat((s), ":", (size))
67 #define string_add_glob_open(s, size) strlcat((s), "glob('*", (size))
68 #define string_add_glob_close(s, size) strlcat((s), "*')", (size))
69 
70 static INLINE void string_add_between_pairs(char *s, const char *str,
71  size_t size)
72 {
74  strlcat(s, str, size);
76 }
77 
78 #define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0)
79 #define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0)
80 
81 static INLINE bool string_is_equal_case_insensitive(const char *a,
82  const char *b)
83 {
84  int result = 0;
85  const unsigned char *p1 = (const unsigned char*)a;
86  const unsigned char *p2 = (const unsigned char*)b;
87 
88  if (!a || !b)
89  return false;
90  if (p1 == p2)
91  return true;
92 
93  while ((result = tolower (*p1) - tolower (*p2++)) == 0)
94  if (*p1++ == '\0')
95  break;
96 
97  return (result == 0);
98 }
99 
100 static INLINE bool string_is_equal_noncase(const char *a, const char *b)
101 {
102  int result = 0;
103  const unsigned char *p1 = (const unsigned char*)a;
104  const unsigned char *p2 = (const unsigned char*)b;
105 
106  if (!a || !b)
107  return false;
108  if (p1 == p2)
109  return false;
110 
111  while ((result = tolower (*p1) - tolower (*p2++)) == 0)
112  if (*p1++ == '\0')
113  break;
114 
115  return (result == 0);
116 }
117 
118 char *string_to_upper(char *s);
119 
120 char *string_to_lower(char *s);
121 
122 char *string_ucwords(char* s);
123 
124 char *string_replace_substring(const char *in, const char *pattern,
125  const char *by);
126 
127 /* Remove leading whitespaces */
128 char *string_trim_whitespace_left(char *const s);
129 
130 /* Remove trailing whitespaces */
131 char *string_trim_whitespace_right(char *const s);
132 
133 /* Remove leading and trailing whitespaces */
134 char *string_trim_whitespace(char *const s);
135 
136 char *word_wrap(char* buffer, const char *string, int line_width, bool unicode);
137 
139 
140 #endif
#define INLINE
Definition: retro_inline.h:35
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
static INLINE void string_add_between_pairs(char *s, const char *str, size_t size)
Definition: stdstring.h:70
char * word_wrap(char *buffer, const char *string, int line_width, bool unicode)
Definition: stdstring.c:154
int tolower(int ch)
Definition: compat_ctype.c:35
char * string_trim_whitespace_left(char *const s)
Definition: stdstring.c:104
GLsizeiptr size
Definition: glext.h:6559
GLdouble s
Definition: glext.h:6390
char * string_replace_substring(const char *in, const char *pattern, const char *by)
Definition: stdstring.c:58
Definition: ibxm.h:9
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
char * string_to_upper(char *s)
Definition: stdstring.c:29
static RETRO_BEGIN_DECLS INLINE bool string_is_empty(const char *data)
Definition: stdstring.h:38
char * string_to_lower(char *s)
Definition: stdstring.c:37
#define NULL
Pointer to 0.
Definition: gctypes.h:65
static INLINE bool string_is_not_equal(const char *a, const char *b)
Definition: stdstring.h:55
float4 p1
Definition: notHere.h:1
GLuint in
Definition: glext.h:10523
GLuint64EXT * result
Definition: glext.h:12211
char * string_trim_whitespace(char *const s)
Definition: stdstring.c:146
#define string_add_pair_open(s, size)
Definition: stdstring.h:60
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
GLbyte by
Definition: glext.h:9673
Definition: ibxm.h:34
#define string_add_pair_close(s, size)
Definition: stdstring.h:61
float4 p2
Definition: local.h:1
#define strlcat(dst, src, size)
Definition: strl.h:48
static INLINE bool string_is_equal_case_insensitive(const char *a, const char *b)
Definition: stdstring.h:81
char * string_ucwords(char *s)
Definition: stdstring.c:45
char * string_trim_whitespace_right(char *const s)
Definition: stdstring.c:126
static INLINE bool string_is_equal(const char *a, const char *b)
Definition: stdstring.h:43
Definition: video4linux2.c:51
static INLINE bool string_is_equal_noncase(const char *a, const char *b)
Definition: stdstring.h:100
const char *const str
Definition: portlistingparse.c:18
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844