fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_utf8.h
Go to the documentation of this file.
1 /*
2  * "$Id$"
3  *
4  * Author: Jean-Marc Lienher ( http://oksid.ch )
5  * Copyright 2000-2010 by O'ksi'D.
6  *
7  * This library is free software. Distribution and use rights are outlined in
8  * the file "COPYING" which should have been included with this file. If this
9  * file is missing or damaged, see the license at:
10  *
11  * http://www.fltk.org/COPYING.php
12  *
13  * Please report all bugs and problems on the following page:
14  *
15  * http://www.fltk.org/str.php
16  */
17 
18 /* Merged in some functionality from the fltk-2 version. IMM.
19  * The following code is an attempt to merge the functions incorporated in FLTK2
20  * with the functions provided in OksiD's fltk-1.1.6-utf8 port
21  */
22 
28 #ifndef _HAVE_FL_UTF8_HDR_
29 #define _HAVE_FL_UTF8_HDR_
30 
31 #include "Fl_Export.H"
32 #include "fl_types.h"
33 
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdlib.h>
37 
38 #ifdef WIN32
39 # include <sys/types.h>
40 # include <sys/stat.h>
41 # include <locale.h>
42 # include <ctype.h>
43 # define xchar wchar_t
44 # if !defined(FL_DLL) && !defined(__CYGWIN__)
45 # undef strdup
46 # define strdup _strdup
47 # undef putenv
48 # define putenv _putenv
49 # undef stricmp
50 # define stricmp _stricmp
51 # undef strnicmp
52 # define strnicmp _strnicmp
53 # undef chdir
54 # define chdir _chdir
55 # endif
56 #elif defined(__APPLE__)
57 # include <wchar.h>
58 # include <sys/stat.h>
59 # define xchar wchar_t
60 #else /* X11 */
61 # include <sys/types.h>
62 # include <sys/stat.h>
63 # if defined(FL_LIBRARY) /* don't expose X11 headers in user space */
64 # include <X11/Xlocale.h>
65 # include <X11/Xlib.h>
66 # endif /* defined(FL_LIBRARY) -- don't expose X11 headers in user space */
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 UTF-8 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 UTF-8 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 UTF-8 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 UTF-8 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 UTF-8 string into UTF16 */
114 FL_EXPORT unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
115 
116 /* F2: Convert a UTF-8 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 UTF-8 - 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 UTF-8 string into ASCII, eliding untranslatable glyphs */
123 FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen);
124 
125 /* F2: Convert 8859-1 string to UTF-8 */
126 FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen);
127 
128 /* F2: Returns true if the current O/S locale is UTF-8 */
129 FL_EXPORT int fl_utf8locale(void);
130 
131 /* F2: Examine the first len characters of src, to determine if the input text is UTF-8 or not
132  * NOTE: The value returned is not simply boolean - it contains information about the probable
133  * type of the src text. */
134 FL_EXPORT int fl_utf8test(const char *src, unsigned len);
135 
136 /* XX: return width of "raw" ucs character in columns.
137  * for internal use only */
138 FL_EXPORT int fl_wcwidth_(unsigned int ucs);
139 
140 /* XX: return width of utf-8 character string in columns.
141  * NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping,
142  * depending on original build options */
143 FL_EXPORT int fl_wcwidth(const char *src);
144 
145 /* OD: Return true if the character is non-spacing */
146 FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs);
147 
148 /* F2: Convert UTF-8 to a local multi-byte encoding - mainly for win32? */
149 FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen);
150 /* OD: Convert UTF-8 to a local multi-byte encoding */
151 FL_EXPORT char* fl_utf2mbcs(const char *src);
152 
153 /* F2: Convert a local multi-byte encoding to UTF-8 - mainly for win32? */
154 FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen);
155 
156 /*****************************************************************************/
157 #ifdef WIN32
158 /* OD: Attempt to convert the UTF-8 string to the current locale */
159 FL_EXPORT char *fl_utf8_to_locale(const char *s, int len, unsigned int codepage);
160 
161 /* OD: Attempt to convert a string in the current locale to UTF-8 */
162 FL_EXPORT char *fl_locale_to_utf8(const char *s, int len, unsigned int codepage);
163 #endif
164 
165 /*****************************************************************************
166  * The following functions are intended to provide portable, UTF-8 aware
167  * versions of standard functions
168  */
169 
170 /* OD: UTF-8 aware strncasecmp - converts to lower case Unicode and tests */
171 FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n);
172 
173 /* OD: UTF-8 aware strcasecmp - converts to Unicode and tests */
174 FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2);
175 
176 /* OD: return the Unicode lower case value of ucs */
177 FL_EXPORT int fl_tolower(unsigned int ucs);
178 
179 /* OD: return the Unicode upper case value of ucs */
180 FL_EXPORT int fl_toupper(unsigned int ucs);
181 
182 /* OD: converts the UTF-8 string to the lower case equivalent */
183 FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf);
184 
185 /* OD: converts the UTF-8 string to the upper case equivalent */
186 FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf);
187 
188 /* OD: Portable UTF-8 aware chmod wrapper */
189 FL_EXPORT int fl_chmod(const char* f, int mode);
190 
191 /* OD: Portable UTF-8 aware access wrapper */
192 FL_EXPORT int fl_access(const char* f, int mode);
193 
194 /* OD: Portable UTF-8 aware stat wrapper */
195 FL_EXPORT int fl_stat( const char *path, struct stat *buffer );
196 
197 /* OD: Portable UTF-8 aware getcwd wrapper */
198 FL_EXPORT char* fl_getcwd( char *buf, int maxlen);
199 
200 /* OD: Portable UTF-8 aware fopen wrapper */
201 FL_EXPORT FILE *fl_fopen(const char *f, const char *mode);
202 
203 /* OD: Portable UTF-8 aware system wrapper */
204 FL_EXPORT int fl_system(const char* f);
205 
206 /* OD: Portable UTF-8 aware execvp wrapper */
207 FL_EXPORT int fl_execvp(const char *file, char *const *argv);
208 
209 /* OD: Portable UTF-8 aware open wrapper */
210 FL_EXPORT int fl_open(const char* f, int o, ...);
211 
212 /* OD: Portable UTF-8 aware unlink wrapper */
213 FL_EXPORT int fl_unlink(const char *f);
214 
215 /* OD: Portable UTF-8 aware rmdir wrapper */
216 FL_EXPORT int fl_rmdir(const char *f);
217 
218 /* OD: Portable UTF-8 aware getenv wrapper */
219 FL_EXPORT char* fl_getenv(const char *name);
220 
221 /* OD: Portable UTF-8 aware execvp wrapper */
222 FL_EXPORT int fl_mkdir(const char* f, int mode);
223 
224 /* OD: Portable UTF-8 aware rename wrapper */
225 FL_EXPORT int fl_rename(const char* f, const char *t);
226 
227 
228 /* OD: Given a full pathname, this will create the directory path needed to hold the file named */
229 FL_EXPORT void fl_make_path_for_file( const char *path );
230 
231 /* OD: recursively create a path in the file system */
232 FL_EXPORT char fl_make_path( const char *path );
233 
234 
237 /*****************************************************************************/
238 
239 #ifdef __cplusplus
240 }
241 #endif /* __cplusplus */
242 
243 
244 #endif /* _HAVE_FL_UTF8_HDR_ */
245 
246 /*
247  * End of "$Id$".
248  */
buf
static char * buf
Definition: fl_encoding_mac_roman.cxx:76
fl_utf8towc
unsigned fl_utf8towc(const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen)
Definition: fl_utf.c:500
fl_getcwd
char * fl_getcwd(char *buf, int maxlen)
Definition: fl_utf8.cxx:699
fl_system
int fl_system(const char *f)
Definition: fl_utf8.cxx:534
fl_utf8toUtf16
unsigned fl_utf8toUtf16(const char *src, unsigned srclen, unsigned short *dst, unsigned dstlen)
Definition: fl_utf.c:432
fl_utf8len
int fl_utf8len(char c)
Definition: fl_utf8.cxx:111
fl_utf_tolower
int fl_utf_tolower(const unsigned char *str, int len, char *buf)
Definition: fl_utf8.cxx:246
fl_utf8toa
unsigned fl_utf8toa(const char *src, unsigned srclen, char *dst, unsigned dstlen)
Definition: fl_utf.c:556
fl_wcwidth
int fl_wcwidth(const char *src)
Definition: fl_utf.c:980
fl_utf8fromwc
unsigned fl_utf8fromwc(char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen)
Definition: fl_utf.c:617
fl_utf_toupper
int fl_utf_toupper(const unsigned char *str, int len, char *buf)
Definition: fl_utf8.cxx:275
fl_utf8fwd
const char * fl_utf8fwd(const char *p, const char *start, const char *end)
Definition: fl_utf.c:229
fl_fopen
FILE * fl_fopen(const char *f, const char *mode)
Definition: fl_utf8.cxx:498
FL_EXPORT
#define FL_EXPORT
Definition: Fl_Export.H:35
fl_open
int fl_open(const char *f, int o,...)
Definition: fl_utf8.cxx:461
buffer
static char * buffer
Definition: file.cxx:215
fl_utf8decode
unsigned fl_utf8decode(const char *p, const char *end, int *len)
Definition: fl_utf.c:137
fl_utf8froma
unsigned fl_utf8froma(char *dst, unsigned dstlen, const char *src, unsigned srclen)
Definition: fl_utf.c:705
p
static menustate * p
Definition: Fl_Menu.cxx:606
fl_utf8len1
int fl_utf8len1(char c)
Definition: fl_utf8.cxx:141
fl_utf8from_mb
unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen)
Definition: fl_utf.c:858
fl_chmod
int fl_chmod(const char *f, int mode)
Definition: fl_utf8.cxx:609
fl_utf8bytes
int fl_utf8bytes(unsigned ucs)
Definition: fl_utf.c:279
fl_stat
int fl_stat(const char *path, struct stat *buffer)
Definition: fl_utf8.cxx:669
fl_rename
int fl_rename(const char *f, const char *t)
Definition: fl_utf8.cxx:827
fl_getenv
char * fl_getenv(const char *name)
Definition: fl_utf8.cxx:421
fl_make_path_for_file
void fl_make_path_for_file(const char *path)
Definition: fl_utf8.cxx:878
fl_utf8locale
int fl_utf8locale(void)
Definition: fl_utf.c:751
fl_utf_strncasecmp
int fl_utf_strncasecmp(const char *s1, const char *s2, int n)
Definition: fl_utf8.cxx:193
fl_utf_strcasecmp
int fl_utf_strcasecmp(const char *s1, const char *s2)
Definition: fl_utf8.cxx:221
fl_utf_nb_char
int fl_utf_nb_char(const unsigned char *buf, int len)
Definition: fl_utf8.cxx:167
Fl_Export.H
fl_mkdir
int fl_mkdir(const char *f, int mode)
Definition: fl_utf8.cxx:768
fl_access
int fl_access(const char *f, int mode)
Definition: fl_utf8.cxx:639
fl_utf8test
int fl_utf8test(const char *src, unsigned len)
Definition: fl_utf.c:925
fl_utf8encode
int fl_utf8encode(unsigned ucs, char *buf)
Definition: fl_utf.c:309
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
fl_toupper
int fl_toupper(unsigned int ucs)
Definition: fl_utf8.cxx:237
fl_utf8back
const char * fl_utf8back(const char *p, const char *start, const char *end)
Definition: fl_utf.c:260
fl_nonspacing
unsigned int fl_nonspacing(unsigned int ucs)
Definition: fl_utf8.cxx:313
fl_types.h
fl_rmdir
int fl_rmdir(const char *f)
Definition: fl_utf8.cxx:797
start
static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy, int &X, int &Y, int &W, int &H)
Definition: Fl_Image.cxx:655
name
static const char * name
Definition: Fl_arg.cxx:53
fl_ucs_to_Utf16
unsigned fl_ucs_to_Utf16(const unsigned ucs, unsigned short *dst, const unsigned dstlen)
Definition: fl_utf.c:363
fl_wcwidth_
int fl_wcwidth_(unsigned int ucs)
Definition: fl_utf.c:963
fl_utf2mbcs
char * fl_utf2mbcs(const char *src)
Definition: fl_utf8.cxx:384
fl_make_path
char fl_make_path(const char *path)
Definition: fl_utf8.cxx:857
fl_utf8to_mb
unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen)
Definition: fl_utf.c:784
fl_tolower
int fl_tolower(unsigned int ucs)
Definition: fl_utf8.cxx:229
fl_unlink
int fl_unlink(const char *f)
Definition: fl_utf8.cxx:738
fl_execvp
int fl_execvp(const char *file, char *const *argv)
Definition: fl_utf8.cxx:554