beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / unilib / ustring.h
blobd1653f5fa4420379c21d328c7ea345e81acb434c
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:
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
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.
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.
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.
27 #ifndef _UCHAR_H
28 # define _UCHAR_H
29 #include <unibasics.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <memory.h>
33 #include <charset.h>
35 extern unichar_t *u_copy(const unichar_t*);
36 extern unichar_t *u_copyn(const unichar_t*, long);
37 extern unichar_t *u_copynallocm(const unichar_t *pt, long n, long m);
38 extern unichar_t *uc_copyn(const char *, int);
39 extern unichar_t *uc_copy(const char*);
40 extern unichar_t *u_concat(const unichar_t*,const unichar_t*);
41 extern char *cu_copyn(const unichar_t *pt,int len);
42 extern char *cu_copy(const unichar_t*);
44 extern long uc_strcmp(const unichar_t *,const char *);
45 extern long u_strcmp(const unichar_t *, const unichar_t *);
46 extern long uc_strncmp(const unichar_t *,const char *,int);
47 extern long u_strncmp(const unichar_t *, const unichar_t *,int);
48 extern long uc_strmatch(const unichar_t *,const char *);
49 extern long uc_strnmatch(const unichar_t *,const char *,int);
50 extern long u_strnmatch(const unichar_t *str1, const unichar_t *str2, int len);
51 extern long u_strmatch(const unichar_t *, const unichar_t *);
52 extern int strmatch(const char *,const char *);
53 extern int strnmatch(const char *str1, const char *str2, int n);
54 extern void uc_strcpy(unichar_t *, const char *);
55 extern void cu_strcpy(char *, const unichar_t *);
56 extern void u_strcpy(unichar_t *, const unichar_t *);
57 extern void u_strncpy(unichar_t *, const unichar_t *,int);
58 extern void cu_strncpy(char *to, const unichar_t *from, int len);
59 extern void uc_strncpy(unichar_t *to, const char *from, int len);
60 extern void uc_strcat(unichar_t *, const char *);
61 extern void uc_strncat(unichar_t *, const char *,int len);
62 extern void cu_strcat(char *, const unichar_t *);
63 extern void cu_strncat(char *, const unichar_t *,int len);
64 extern void u_strcat(unichar_t *, const unichar_t *);
65 extern void u_strncat(unichar_t *, const unichar_t *, int len);
66 extern int u_strlen(const unichar_t *);
67 extern unichar_t *u_strchr(const unichar_t *,unichar_t);
68 extern unichar_t *u_strrchr(const unichar_t *,unichar_t);
69 extern unichar_t *uc_strstr(const unichar_t *,const char *);
70 extern unichar_t *u_strstr(const unichar_t *,const unichar_t *);
71 extern unichar_t *uc_strstrmatch(const unichar_t *,const char *);
72 extern unichar_t *u_strstrmatch(const unichar_t *,const unichar_t *);
73 extern char * strstrmatch(const char *,const char *);
75 extern char *u_to_c(const unichar_t *);
76 extern unichar_t *c_to_u(const char *);
78 extern unsigned long u_strtoul(const unichar_t *,unichar_t **,int);
79 extern long u_strtol(const unichar_t *,unichar_t **,int);
80 extern double u_strtod(const unichar_t *,unichar_t **);
82 extern char *strstart(const char *initial,const char *full);
83 extern char *strstartmatch(const char *initial,const char *full);
84 extern unichar_t *u_strstartmatch(const unichar_t *initial, const unichar_t *full);
85 extern unichar_t *cu_strstartmatch(const char *initial, const unichar_t *full);
87 #define utf82u_strncpy utf82U_strncpy
88 extern int32 utf8_ildb(const char **utf8_text);
89 extern char *utf8_idpb(char *utf8_text,uint32 ch);
90 extern char *utf8_db(char *utf8_text);
91 extern char *utf8_ib(char *utf8_text);
92 extern int utf8_valid(const char *str);
93 extern void utf8_truncatevalid(char *str);
94 extern char *latin1_2_utf8_strcpy(char *utf8buf,const char *lbuf);
95 extern char *latin1_2_utf8_copy(const char *lbuf);
96 extern char *utf8_2_latin1_copy(const char *utf8buf);
97 extern int utf8_strlen(const char *utf8_str); /* how many characters in the string */
98 extern int utf82u_strlen(const char *utf8_str); /* how many long would this be in shorts (UCS2) */
99 extern void utf8_strncpy(register char *to, const char *from, int len); /* copy n characters NOT bytes */
100 extern char *def2utf8_copy(const char *from);
101 extern char *utf82def_copy(const char *ufrom);
102 extern char *utf8_strchr(const char *utf8_str, int search_char);
104 extern unichar_t *utf82u_strncpy(unichar_t *ubuf,const char *utf8buf,int len);
105 extern unichar_t *utf82u_strcpy(unichar_t *ubuf,const char *utf8buf);
106 extern void utf82u_strcat(unichar_t *ubuf,const char *utf8buf);
107 extern unichar_t *utf82u_copyn(const char *utf8buf,int len);
108 extern unichar_t *utf82u_copy(const char *utf8buf);
109 extern char *u2utf8_strcpy(char *utf8buf,const unichar_t *ubuf);
110 extern char *u2utf8_copy(const unichar_t *ubuf);
111 extern char *u2utf8_copyn(const unichar_t *ubuf,int len);
112 extern unichar_t *encoding2u_strncpy(unichar_t *uto, const char *from, int n, enum encoding cs);
113 extern char *u2encoding_strncpy(char *to, const unichar_t *ufrom, int n, enum encoding cs);
114 extern unichar_t *def2u_strncpy(unichar_t *uto, const char *from, int n);
115 extern char *u2def_strncpy(char *to, const unichar_t *ufrom, int n);
116 extern unichar_t *def2u_copy(const char *from);
117 extern char *u2def_copy(const unichar_t *ufrom);
119 extern int u_sprintf(unichar_t *str, const unichar_t *format, ... );
120 extern int u_snprintf(unichar_t *str, int len, const unichar_t *format, ... );
121 extern int u_vsnprintf(unichar_t *str, int len, const unichar_t *format, va_list ap );
123 extern int uAllAscii(const unichar_t *str);
124 extern int AllAscii(const char *);
125 extern char *StripToASCII(const char *utf8_str);
127 extern char *copytolower(const char *);
128 extern int endswith(const char *haystack,const char *needle);
129 extern int endswithi(const char *haystack,const char *needle);
130 extern int endswithi_partialExtension( const char *haystack,const char *needle);
133 * Remove trailing \n or \r from the given string. No memory
134 * allocations are performed, null is injected over these terminators
135 * to trim the string.
137 * This function is designed to be impotent if called with a string
138 * that does not end with \n or \r. ie, you don't need to redundantly
139 * check if there is a newline at the end of string and not call here
140 * if there is no newline. You can just call here with any string and
141 * be assured that afterwards there will be no trailing newline or
142 * carrage return character found at the end of the string pointed to
143 * by 'p'.
145 extern char* chomp( char* p );
148 * Return true if the haystack plain string ends with the string
149 * needle. Return 0 otherwise.
151 * Needles which are larger than the haystack are handled.
153 * No new strings are allocated, freed, or returned.
155 int endswith(const char *haystack,const char *needle);
158 * Return true if the haystack unicode string ends with the string needle.
159 * Return 0 otherwise.
161 * Needles which are larger than the haystack are handled.
163 * No new strings are allocated, freed, or returned.
165 extern int u_endswith(const unichar_t *haystack,const unichar_t *needle);
167 #endif