Debian Codegraph @

inc/ustring.h

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef FONTFORGE_UCHAR_H
29 #define FONTFORGE_UCHAR_H
30
31 #include <fontforge-config.h>
32
33 #include "basics.h"
34
35 #include <memory.h>
36 #include <stdarg.h>
37 #include <string.h>
38
39 #pragma push_macro("PRINTF_FORMAT_ATTRIBUTE")
40 #ifdef __GNUC__
41 # if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO != 0
42 # define PRINTF_FORMAT_ATTRIBUTE(x, y) __attribute__((format(gnu_printf, x, y)))
43 # else
44 # define PRINTF_FORMAT_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
45 # endif
46 #else
47 # define PRINTF_FORMAT_ATTRIBUTE(x, y)
48 #endif
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 extern bool SetupUCharMap(const char* unichar_name, const char* local_name, bool is_local_utf8);
55
56 extern char *copy(const char *);
57 extern char *copyn(const char *,long);
58 extern unichar_t *u_copy(const unichar_t*);
59 extern unichar_t *u_copyn(const unichar_t*, long);
60 extern unichar_t *u_copynallocm(const unichar_t *pt, long n, long m);
61 extern unichar_t *uc_copyn(const char *, int);
62 extern unichar_t *uc_copy(const char*);
63 extern unichar_t *u_concat(const unichar_t*,const unichar_t*);
64 extern char *cu_copyn(const unichar_t *pt,int len);
65 extern char *cu_copy(const unichar_t*);
66
67 extern char *vsmprintf(const char *fmt, va_list args);
68 extern char *smprintf(const char *fmt, ...) PRINTF_FORMAT_ATTRIBUTE(1, 2);
69
70 extern long uc_strcmp(const unichar_t *,const char *);
71 extern long u_strcmp(const unichar_t *, const unichar_t *);
72 extern long uc_strncmp(const unichar_t *,const char *,int);
73 extern long u_strncmp(const unichar_t *, const unichar_t *,int);
74 extern long uc_strmatch(const unichar_t *,const char *);
75 extern long uc_strnmatch(const unichar_t *,const char *,int);
76 extern long u_strnmatch(const unichar_t *str1, const unichar_t *str2, int len);
77 extern long u_strmatch(const unichar_t *, const unichar_t *);
78 extern int strmatch(const char *,const char *);
79 extern int strnmatch(const char *str1, const char *str2, int n);
80 extern void uc_strcpy(unichar_t *, const char *);
81 extern void cu_strcpy(char *, const unichar_t *);
82 extern void u_strcpy(unichar_t *, const unichar_t *);
83 extern void u_strncpy(unichar_t *, const unichar_t *,int);
84 extern void cu_strncpy(char *to, const unichar_t *from, int len);
85 extern void uc_strncpy(unichar_t *to, const char *from, int len);
86 /**
87 * Like strncpy but passing a null 'from' will simply null terminate
88 * to[0] to give a blank result rather than a crash.
89 */
90 extern char *cc_strncpy(char *to, const char *from, int len);
91 extern void uc_strcat(unichar_t *, const char *);
92 extern void uc_strncat(unichar_t *, const char *,int len);
93 extern void cu_strcat(char *, const unichar_t *);
94 extern void cu_strncat(char *, const unichar_t *,int len);
95 extern void u_strcat(unichar_t *, const unichar_t *);
96 extern void u_strncat(unichar_t *, const unichar_t *, int len);
97 extern int u_strlen(const unichar_t *);
98 /**
99 * Like strlen() but passing a null pointer gets a 0 length
100 */
101 extern int c_strlen(const char *);
102 extern unichar_t *u_strchr(const unichar_t *,unichar_t);
103 extern unichar_t *u_strrchr(const unichar_t *,unichar_t);
104 extern unichar_t *uc_strstr(const unichar_t *,const char *);
105 extern unichar_t *u_strstr(const unichar_t *,const unichar_t *);
106 extern unichar_t *uc_strstrmatch(const unichar_t *,const char *);
107 extern unichar_t *u_strstrmatch(const unichar_t *,const unichar_t *);
108 extern char * strstrmatch(const char *,const char *);
109
110 extern char *u_to_c(const unichar_t *);
111 extern unichar_t *c_to_u(const char *);
112
113 extern unsigned long u_strtoul(const unichar_t *,unichar_t **,int);
114 extern long u_strtol(const unichar_t *,unichar_t **,int);
115 extern double u_strtod(const unichar_t *,unichar_t **);
116
117 /*
118 * Convert the integer 'v' to a string and return it.
119 * You do not own the return value, it is an internal buffer
120 * so you should copy it before using the function again
121 */
122 extern char* c_itostr( int v );
123
124 extern char *strstart(const char *initial,const char *full);
125 extern char *strstartmatch(const char *initial,const char *full);
126 extern unichar_t *u_strstartmatch(const unichar_t *initial, const unichar_t *full);
127 extern unichar_t *cu_strstartmatch(const char *initial, const unichar_t *full);
128
129 #define utf82u_strncpy utf82U_strncpy
130 extern int32_t utf8_ildb(const char **utf8_text);
131 #define UTF8IDPB_NOZERO 1 /* Allow for 0 encoded as a non-zero utf8 0xc0:0x80 char */
132 #define UTF8IDPB_OLDLIMIT 2 /* Today's utf8 is agreed to be limited to {0..0x10FFFF} */
133 #define UTF8IDPB_UCS2 8 /* Encode {0...0xffff} as 16bit ucs2 type values */
134 #define UTF8IDPB_UTF16 16 /* Encode {0...0x10ffff} as 16bit utf16 type values */
135 #define UTF8IDPB_UTF32 32 /* Encode {0...0x10ffff} as 32bit utf32 type values */
136 extern char *utf8_idpb(char *utf8_text,uint32_t ch,int flags);
137 extern char *utf8_db(char *utf8_text);
138 extern char *utf8_ib(char *utf8_text);
139 extern int utf8_valid(const char *str);
140 extern void utf8_truncatevalid(char *str);
141 extern char *latin1_2_utf8_strcpy(char *utf8buf,const char *lbuf);
142 extern char *latin1_2_utf8_copy(const char *lbuf);
143 extern char *utf8_2_latin1_copy(const char *utf8buf);
144 extern long utf8_strlen(const char *utf8_str); /* Count how many characters in the string NOT bytes */
145 extern long utf82u_strlen(const char *utf8_str); /* Count how many shorts needed to represent in UCS2 */
146 extern void utf8_strncpy(char *to, const char *from, int len); /* copy n characters NOT bytes */
147 extern char *def2utf8_copy(const char *from);
148 extern char *utf82def_copy(const char *ufrom);
149 extern char *utf82def_copy_safe(const char *ufrom);
150 extern char *utf8_strchr(const char *utf8_str, int search_char);
151
152 extern unichar_t *utf82u_strncpy(unichar_t *ubuf,const char *utf8buf,int len);
153 extern unichar_t *utf82u_strcpy(unichar_t *ubuf,const char *utf8buf);
154 extern void utf82u_strcat(unichar_t *ubuf,const char *utf8buf);
155 extern unichar_t *utf82u_copyn(const char *utf8buf,int len);
156 extern unichar_t *utf82u_copy(const char *utf8buf);
157 extern char *u2utf8_strcpy(char *utf8buf,const unichar_t *ubuf);
158 extern char *u2utf8_strncpy(char *utf8buf,const unichar_t *ubuf,int len);
159 extern char *u2utf8_copy(const unichar_t *ubuf);
160 extern char *u2utf8_copyn(const unichar_t *ubuf,int len);
161 extern unichar_t *def2u_strncpy(unichar_t *uto, const char *from, size_t n);
162 extern char *u2def_strncpy(char *to, const unichar_t *ufrom, size_t n);
163 extern unichar_t *def2u_copy(const char *from);
164 extern char *u2def_copy(const unichar_t *ufrom);
165
166 extern uint16_t *u2utf16_strcpy(uint16_t *utf16buf,const unichar_t *ubuf);
167 extern unichar_t *utf162u_strcpy(unichar_t*ubuf, const uint16_t *utf16buf);
168
169 extern uint16_t *utf82utf16_copy(const char* utf8buf);
170
171 extern int uAllAscii(const unichar_t *str);
172 extern int AllAscii(const char *);
173 extern char *StripToASCII(const char *utf8_str);
174
175 extern char *copytolower(const char *);
176 extern int endswith(const char *haystack,const char *needle);
177 extern int endswithi(const char *haystack,const char *needle);
178 extern int endswithi_partialExtension( const char *haystack,const char *needle);
179
180 /**
181 * Remove trailing \n or \r from the given string. No memory
182 * allocations are performed, null is injected over these terminators
183 * to trim the string.
184 *
185 * This function is designed to be impotent if called with a string
186 * that does not end with \n or \r. ie, you don't need to redundantly
187 * check if there is a newline at the end of string and not call here
188 * if there is no newline. You can just call here with any string and
189 * be assured that afterwards there will be no trailing newline or
190 * carrage return character found at the end of the string pointed to
191 * by 'p'.
192 */
193 extern char* chomp( char* p );
194
195 /**
196 * Return true if the haystack plain string ends with the string
197 * needle. Return 0 otherwise.
198 *
199 * Needles which are larger than the haystack are handled.
200 *
201 * No new strings are allocated, freed, or returned.
202 */
203 int endswith(const char *haystack,const char *needle);
204
205 /**
206 * Return true if the haystack unicode string ends with the string needle.
207 * Return 0 otherwise.
208 *
209 * Needles which are larger than the haystack are handled.
210 *
211 * No new strings are allocated, freed, or returned.
212 */
213 extern int u_endswith(const unichar_t *haystack,const unichar_t *needle);
214
215 extern int u_startswith(const unichar_t *haystack,const unichar_t *needle);
216 extern int uc_startswith(const unichar_t *haystack,const char* needle);
217
218 /**
219 * In the string 's' replace all occurrences of 'orig' with 'replacement'.
220 * If you set free_s to true then the string 's' will be freed by this function.
221 * Normally you want to set free_s to 0 to avoid that. The case you will want to
222 * use free_s to 1 is chaining many calls like:
223 *
224 * char* s = copy( input );
225 * s = str_replace_all( s, "foo", "bar", 1 );
226 * s = str_replace_all( s, "baz", "gah", 1 );
227 * // use s
228 * free(s);
229 * // no leaks in the above.
230 *
231 * Note that 's' is first copied before the first call to replace_all in the above
232 * so it can be freed without concern. This also allows the ordering of replace_all
233 * in the above to be changed without having to worry about the free_s flag.
234 */
235 extern char* str_replace_all( char* s, char* orig, char* replacement, int free_s );
236
237
238 int toint( char* v );
239 char* tostr( int v );
240 /* reallocate buffer and adjust its tail and intermediate processor if present
241 */
242 void realloc_tail(char** p_buf, size_t size_delta, char** p_tail,
243 char** p_proc);
244
245 #ifdef __cplusplus
246 }
247 #endif
248
249 #pragma pop_macro("PRINTF_FORMAT_ATTRIBUTE")
250
251 #endif /* FONTFORGE_UCHAR_H */