FLTK 1.3.2
fl_utf8.h
Go to the documentation of this file.
1 /* "$Id: fl_utf8.h 8864 2011-07-19 04:49:30Z greg.ercolano $"
2  *
3  * Author: Jean-Marc Lienher ( http://oksid.ch )
4  * Copyright 2000-2010 by O'ksi'D.
5  *
6  * This library is free software. Distribution and use rights are outlined in
7  * the file "COPYING" which should have been included with this file. If this
8  * file is missing or damaged, see the license at:
9  *
10  * http://www.fltk.org/COPYING.php
11  *
12  * Please report all bugs and problems on the following page:
13  *
14  * http://www.fltk.org/str.php
15  */
16 
17 /* Merged in some functionality from the fltk-2 version. IMM.
18  * The following code is an attempt to merge the functions incorporated in FLTK2
19  * with the functions provided in OksiD's fltk-1.1.6-utf8 port
20  */
21 
27 #ifndef _HAVE_FL_UTF8_HDR_
28 #define _HAVE_FL_UTF8_HDR_
29 
30 #include "Fl_Export.H"
31 #include "fl_types.h"
32 
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
36 
37 #ifdef WIN32
38 # include <sys/types.h>
39 # include <sys/stat.h>
40 # include <locale.h>
41 # include <ctype.h>
42 # define xchar wchar_t
43 # if !defined(FL_DLL) && !defined(__CYGWIN__)
44 # undef strdup
45 # define strdup _strdup
46 # undef putenv
47 # define putenv _putenv
48 # undef stricmp
49 # define stricmp _stricmp
50 # undef strnicmp
51 # define strnicmp _strnicmp
52 # undef hypot
53 # define hypot _hypot
54 # undef chdir
55 # define chdir _chdir
56 # endif
57 #elif defined(__APPLE__)
58 # include <wchar.h>
59 # include <sys/stat.h>
60 # define xchar wchar_t
61 #else /* X11 */
62 # include <sys/types.h>
63 # include <sys/stat.h>
64 # include "Xutf8.h"
65 # include <X11/Xlocale.h>
66 # include <X11/Xlib.h>
67 # include <locale.h>
68 # define xchar unsigned short
69 #endif
70 
71 # ifdef __cplusplus
72 extern "C" {
73 # endif
74 
79 /* F2: comes from FLTK2 */
80 /* OD: comes from OksiD */
81 
87 FL_EXPORT int fl_utf8bytes(unsigned ucs);
88 
89 /* OD: returns the byte length of the first UTF-8 char sequence (returns -1 if not valid) */
90 FL_EXPORT int fl_utf8len(char c);
91 
92 /* OD: returns the byte length of the first UTF-8 char sequence (returns +1 if not valid) */
93 FL_EXPORT int fl_utf8len1(char c);
94 
95 /* OD: returns the number of Unicode chars in the UTF-8 string */
96 FL_EXPORT int fl_utf_nb_char(const unsigned char *buf, int len);
97 
98 /* F2: Convert the next UTF8 char-sequence into a Unicode value (and say how many bytes were used) */
99 FL_EXPORT unsigned fl_utf8decode(const char* p, const char* end, int* len);
100 
101 /* F2: Encode a Unicode value into a UTF8 sequence, return the number of bytes used */
102 FL_EXPORT int fl_utf8encode(unsigned ucs, char* buf);
103 
104 /* F2: Move forward to the next valid UTF8 sequence start betwen start and end */
105 FL_EXPORT const char* fl_utf8fwd(const char* p, const char* start, const char* end);
106 
107 /* F2: Move backward to the previous valid UTF8 sequence start */
108 FL_EXPORT const char* fl_utf8back(const char* p, const char* start, const char* end);
109 
110 /* XX: Convert a single 32-bit Unicode value into UTF16 */
111 FL_EXPORT unsigned fl_ucs_to_Utf16(const unsigned ucs, unsigned short *dst, const unsigned dstlen);
112 
113 /* F2: Convert a UTF8 string into UTF16 */
114 FL_EXPORT unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
115 
116 /* F2: Convert a UTF8 string into a wide character string - makes UTF16 on win32, "UCS4" elsewhere */
117 FL_EXPORT unsigned fl_utf8towc(const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen);
118 
119 /* F2: Convert a wide character string to UTF8 - takes in UTF16 on win32, "UCS4" elsewhere */
120 FL_EXPORT unsigned fl_utf8fromwc(char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen);
121 
122 /* F2: Convert a UTF8 string into ASCII, eliding untranslatable glyphs */
123 FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen);
124 /* OD: convert UTF-8 string to latin1 */
125 /* FL_EXPORT int fl_utf2latin1(const unsigned char *src, int srclen, char *dst); */
126 
127 /* F2: Convert 8859-1 string to UTF8 */
128 FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen);
129 /* OD: convert latin1 str to UTF-8 */
130 /* FL_EXPORT int fl_latin12utf(const unsigned char *src, int srclen, char *dst); */
131 
132 /* F2: Returns true if the current O/S locale is UTF8 */
133 FL_EXPORT int fl_utf8locale();
134 
135 /* F2: Examine the first len characters of src, to determine if the input text is UTF8 or not
136  * NOTE: The value returned is not simply boolean - it contains information about the probable
137  * type of the src text. */
138 FL_EXPORT int fl_utf8test(const char *src, unsigned len);
139 
140 /* XX: return width of "raw" ucs character in columns.
141  * for internal use only */
142 FL_EXPORT int fl_wcwidth_(unsigned int ucs);
143 
144 /* XX: return width of utf-8 character string in columns.
145  * NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping,
146  * depending on original build options */
147 FL_EXPORT int fl_wcwidth(const char *src);
148 
149 /* OD: Return true if the character is non-spacing */
150 FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs);
151 
152 /* F2: Convert UTF8 to a local multi-byte encoding - mainly for win32? */
153 FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen);
154 /* OD: Convert UTF8 to a local multi-byte encoding */
155 FL_EXPORT char* fl_utf2mbcs(const char *src);
156 
157 /* F2: Convert a local multi-byte encoding to UTF8 - mainly for win32? */
158 FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen);
159 /* OD: Convert a local multi-byte encoding to UTF8 */
160 /* FL_EXPORT char* fl_mbcs2utf(const char *src); */
161 
162 /*****************************************************************************/
163 #ifdef WIN32
164 /* OD: Attempt to convert the UTF8 string to the current locale */
165 FL_EXPORT char *fl_utf8_to_locale(const char *s, int len, unsigned int codepage);
166 
167 /* OD: Attempt to convert a string in the current locale to UTF8 */
168 FL_EXPORT char *fl_locale_to_utf8(const char *s, int len, unsigned int codepage);
169 #endif
170 
171 /*****************************************************************************
172  * The following functions are intended to provide portable, UTF8 aware
173  * versions of standard functions
174  */
175 
176 /* OD: UTF8 aware strncasecmp - converts to lower case Unicode and tests */
177 FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n);
178 
179 /* OD: UTF8 aware strcasecmp - converts to Unicode and tests */
180 FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2);
181 
182 /* OD: return the Unicode lower case value of ucs */
183 FL_EXPORT int fl_tolower(unsigned int ucs);
184 
185 /* OD: return the Unicode upper case value of ucs */
186 FL_EXPORT int fl_toupper(unsigned int ucs);
187 
188 /* OD: converts the UTF8 string to the lower case equivalent */
189 FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf);
190 
191 /* OD: converts the UTF8 string to the upper case equivalent */
192 FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf);
193 
194 /* OD: Portable UTF8 aware chmod wrapper */
195 FL_EXPORT int fl_chmod(const char* f, int mode);
196 
197 /* OD: Portable UTF8 aware access wrapper */
198 FL_EXPORT int fl_access(const char* f, int mode);
199 
200 /* OD: Portable UTF8 aware stat wrapper */
201 FL_EXPORT int fl_stat( const char *path, struct stat *buffer );
202 
203 /* OD: Portable UTF8 aware getcwd wrapper */
204 FL_EXPORT char* fl_getcwd( char *buf, int maxlen);
205 
206 /* OD: Portable UTF8 aware fopen wrapper */
207 FL_EXPORT FILE *fl_fopen(const char *f, const char *mode);
208 
209 /* OD: Portable UTF8 aware system wrapper */
210 FL_EXPORT int fl_system(const char* f);
211 
212 /* OD: Portable UTF8 aware execvp wrapper */
213 FL_EXPORT int fl_execvp(const char *file, char *const *argv);
214 
215 /* OD: Portable UTF8 aware open wrapper */
216 FL_EXPORT int fl_open(const char* f, int o, ...);
217 
218 /* OD: Portable UTF8 aware unlink wrapper */
219 FL_EXPORT int fl_unlink(const char *f);
220 
221 /* OD: Portable UTF8 aware rmdir wrapper */
222 FL_EXPORT int fl_rmdir(const char *f);
223 
224 /* OD: Portable UTF8 aware getenv wrapper */
225 FL_EXPORT char* fl_getenv(const char *name);
226 
227 /* OD: Portable UTF8 aware execvp wrapper */
228 FL_EXPORT int fl_mkdir(const char* f, int mode);
229 
230 /* OD: Portable UTF8 aware rename wrapper */
231 FL_EXPORT int fl_rename(const char* f, const char *t);
232 
233 
234 /* OD: Given a full pathname, this will create the directory path needed to hold the file named */
235 FL_EXPORT void fl_make_path_for_file( const char *path );
236 
237 /* OD: recursively create a path in the file system */
238 FL_EXPORT char fl_make_path( const char *path );
239 
240 
243 /*****************************************************************************/
244 
245 #ifdef __cplusplus
246 }
247 #endif /* __cplusplus */
248 
249 
250 #endif /* _HAVE_FL_UTF8_HDR_ */
251 
252 /*
253  * End of "$Id: fl_utf8.h 8864 2011-07-19 04:49:30Z greg.ercolano $".
254  */
FL_EXPORT int fl_utf8test(const char *src, unsigned len)
Definition: fl_utf.c:919
FL_EXPORT int fl_wcwidth(const char *src)
extended wrapper around fl_wcwidth_(unsigned int ucs) function.
Definition: fl_utf.c:974
FL_EXPORT int fl_utf8len(char c)
return the byte length of the UTF-8 sequence with first byte c, or -1 if c is not valid...
Definition: fl_utf8.cxx:114
FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen)
Definition: fl_utf.c:778
FL_EXPORT unsigned fl_utf8toUtf16(const char *src, unsigned srclen, unsigned short *dst, unsigned dstlen)
Definition: fl_utf.c:426
FL_EXPORT FILE * fl_fopen(const char *f, const char *mode)
Cross-platform function to open files with a UTF-8 encoded name.
Definition: fl_utf8.cxx:562
FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs)
returns true if the character is non-spacing.
Definition: fl_utf8.cxx:361
FL_EXPORT unsigned fl_utf8fromwc(char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen)
Definition: fl_utf.c:611
FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf)
converts the str string to the lower case equivalent into buf.
Definition: fl_utf8.cxx:246
FL_EXPORT int fl_utf8locale()
Definition: fl_utf.c:745
FL_EXPORT int fl_wcwidth_(unsigned int ucs)
wrapper to adapt Markus Kuhn's implementation of wcwidth() for FLTK
Definition: fl_utf.c:957
FL_EXPORT unsigned fl_utf8towc(const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen)
Converts a UTF-8 string into a wide character string.
Definition: fl_utf.c:494
FL_EXPORT int fl_utf_nb_char(const unsigned char *buf, int len)
returns the number of Unicode chars in the UTF-8 string
Definition: fl_utf8.cxx:169
FL_EXPORT int fl_open(const char *f, int o,...)
Cross-platform function to open files with a UTF-8 encoded name.
Definition: fl_utf8.cxx:530
FL_EXPORT unsigned fl_utf8toa(const char *src, unsigned srclen, char *dst, unsigned dstlen)
Definition: fl_utf.c:550
FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n)
UTF-8 aware strncasecmp - converts to lower case Unicode and tests.
Definition: fl_utf8.cxx:194
FL_EXPORT int fl_utf8bytes(unsigned ucs)
Return the number of bytes needed to encode the given UCS4 character in UTF8.
Definition: fl_utf.c:273
FL_EXPORT int fl_utf8len1(char c)
Return the byte length of the UTF-8 sequence with first byte c, or 1 if c is not valid.
Definition: fl_utf8.cxx:143
FL_EXPORT int fl_toupper(unsigned int ucs)
return the Unicode upper case value of ucs
Definition: fl_utf8.cxx:237
FL_EXPORT unsigned fl_utf8froma(char *dst, unsigned dstlen, const char *src, unsigned srclen)
Definition: fl_utf.c:699
FL_EXPORT const char * fl_utf8back(const char *p, const char *start, const char *end)
Definition: fl_utf.c:254
FL_EXPORT const char * fl_utf8fwd(const char *p, const char *start, const char *end)
Definition: fl_utf.c:223
FL_EXPORT unsigned fl_utf8decode(const char *p, const char *end, int *len)
Definition: fl_utf.c:131
FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2)
UTF-8 aware strcasecmp - converts to Unicode and tests.
Definition: fl_utf8.cxx:221
FL_EXPORT char * fl_utf2mbcs(const char *src)
converts UTF8 to a local multi-byte character string.
Definition: fl_utf8.cxx:438
This file contains simple "C"-style type definitions.
FL_EXPORT int fl_utf8encode(unsigned ucs, char *buf)
Definition: fl_utf.c:303
FL_EXPORT int fl_tolower(unsigned int ucs)
return the Unicode lower case value of ucs
Definition: fl_utf8.cxx:229
FL_EXPORT unsigned fl_ucs_to_Utf16(const unsigned ucs, unsigned short *dst, const unsigned dstlen)
Definition: fl_utf.c:357
FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen)
Definition: fl_utf.c:852
FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf)
converts the str string to the upper case equivalent into buf.
Definition: fl_utf8.cxx:277