FLTK 1.3.0
|
00001 /* "$Id: fl_utf8.h 8585 2011-04-13 15:43:22Z ianmacarthur $" 00002 * 00003 * Author: Jean-Marc Lienher ( http://oksid.ch ) 00004 * Copyright 2000-2010 by O'ksi'D. 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00019 * USA. 00020 * 00021 * Please report all bugs and problems on the following page: 00022 * 00023 * http://www.fltk.org/str.php 00024 */ 00025 00026 /* Merged in some functionality from the fltk-2 version. IMM. 00027 * The following code is an attempt to merge the functions incorporated in FLTK2 00028 * with the functions provided in OksiD's fltk-1.1.6-utf8 port 00029 */ 00030 00036 #ifndef _HAVE_FL_UTF8_HDR_ 00037 #define _HAVE_FL_UTF8_HDR_ 00038 00039 #include "Fl_Export.H" 00040 #include "fl_types.h" 00041 00042 #include <stdio.h> 00043 #include <string.h> 00044 #include <stdlib.h> 00045 00046 #ifdef WIN32 00047 # include <sys/types.h> 00048 # include <sys/stat.h> 00049 # include <locale.h> 00050 # include <ctype.h> 00051 # define xchar wchar_t 00052 # if !defined(FL_DLL) && !defined(__CYGWIN__) 00053 # undef strdup 00054 # define strdup _strdup 00055 # undef putenv 00056 # define putenv _putenv 00057 # undef stricmp 00058 # define stricmp _stricmp 00059 # undef strnicmp 00060 # define strnicmp _strnicmp 00061 # undef hypot 00062 # define hypot _hypot 00063 # undef chdir 00064 # define chdir _chdir 00065 # endif 00066 #elif defined(__APPLE__) 00067 # include <wchar.h> 00068 # include <sys/stat.h> 00069 # define xchar wchar_t 00070 #else /* X11 */ 00071 # include <sys/types.h> 00072 # include <sys/stat.h> 00073 # include "Xutf8.h" 00074 # include <X11/Xlocale.h> 00075 # include <X11/Xlib.h> 00076 # include <locale.h> 00077 # define xchar unsigned short 00078 #endif 00079 00080 # ifdef __cplusplus 00081 extern "C" { 00082 # endif 00083 00088 /* F2: comes from FLTK2 */ 00089 /* OD: comes from OksiD */ 00090 00096 FL_EXPORT int fl_utf8bytes(unsigned ucs); 00097 00098 /* OD: returns the byte length of the first UTF-8 char sequence (returns -1 if not valid) */ 00099 FL_EXPORT int fl_utf8len(char c); 00100 00101 /* OD: returns the byte length of the first UTF-8 char sequence (returns +1 if not valid) */ 00102 FL_EXPORT int fl_utf8len1(char c); 00103 00104 /* OD: returns the number of Unicode chars in the UTF-8 string */ 00105 FL_EXPORT int fl_utf_nb_char(const unsigned char *buf, int len); 00106 00107 /* F2: Convert the next UTF8 char-sequence into a Unicode value (and say how many bytes were used) */ 00108 FL_EXPORT unsigned fl_utf8decode(const char* p, const char* end, int* len); 00109 00110 /* F2: Encode a Unicode value into a UTF8 sequence, return the number of bytes used */ 00111 FL_EXPORT int fl_utf8encode(unsigned ucs, char* buf); 00112 00113 /* F2: Move forward to the next valid UTF8 sequence start betwen start and end */ 00114 FL_EXPORT const char* fl_utf8fwd(const char* p, const char* start, const char* end); 00115 00116 /* F2: Move backward to the previous valid UTF8 sequence start */ 00117 FL_EXPORT const char* fl_utf8back(const char* p, const char* start, const char* end); 00118 00119 /* XX: Convert a single 32-bit Unicode value into UTF16 */ 00120 FL_EXPORT unsigned fl_ucs_to_Utf16(const unsigned ucs, unsigned short *dst, const unsigned dstlen); 00121 00122 /* F2: Convert a UTF8 string into UTF16 */ 00123 FL_EXPORT unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen); 00124 00125 /* F2: Convert a UTF8 string into a wide character string - makes UTF16 on win32, "UCS4" elsewhere */ 00126 FL_EXPORT unsigned fl_utf8towc(const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen); 00127 00128 /* F2: Convert a wide character string to UTF8 - takes in UTF16 on win32, "UCS4" elsewhere */ 00129 FL_EXPORT unsigned fl_utf8fromwc(char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen); 00130 00131 /* F2: Convert a UTF8 string into ASCII, eliding untranslatable glyphs */ 00132 FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen); 00133 /* OD: convert UTF-8 string to latin1 */ 00134 /* FL_EXPORT int fl_utf2latin1(const unsigned char *src, int srclen, char *dst); */ 00135 00136 /* F2: Convert 8859-1 string to UTF8 */ 00137 FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen); 00138 /* OD: convert latin1 str to UTF-8 */ 00139 /* FL_EXPORT int fl_latin12utf(const unsigned char *src, int srclen, char *dst); */ 00140 00141 /* F2: Returns true if the current O/S locale is UTF8 */ 00142 FL_EXPORT int fl_utf8locale(); 00143 00144 /* F2: Examine the first len characters of src, to determine if the input text is UTF8 or not 00145 * NOTE: The value returned is not simply boolean - it contains information about the probable 00146 * type of the src text. */ 00147 FL_EXPORT int fl_utf8test(const char *src, unsigned len); 00148 00149 /* XX: return width of "raw" ucs character in columns. 00150 * for internal use only */ 00151 FL_EXPORT int fl_wcwidth_(unsigned int ucs); 00152 00153 /* XX: return width of utf-8 character string in columns. 00154 * NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping, 00155 * depending on original build options */ 00156 FL_EXPORT int fl_wcwidth(const char *src); 00157 00158 /* OD: Return true if the character is non-spacing */ 00159 FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs); 00160 00161 /* F2: Convert UTF8 to a local multi-byte encoding - mainly for win32? */ 00162 FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen); 00163 /* OD: Convert UTF8 to a local multi-byte encoding */ 00164 FL_EXPORT char* fl_utf2mbcs(const char *src); 00165 00166 /* F2: Convert a local multi-byte encoding to UTF8 - mainly for win32? */ 00167 FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen); 00168 /* OD: Convert a local multi-byte encoding to UTF8 */ 00169 /* FL_EXPORT char* fl_mbcs2utf(const char *src); */ 00170 00171 /*****************************************************************************/ 00172 #ifdef WIN32 00173 /* OD: Attempt to convert the UTF8 string to the current locale */ 00174 FL_EXPORT char *fl_utf8_to_locale(const char *s, int len, unsigned int codepage); 00175 00176 /* OD: Attempt to convert a string in the current locale to UTF8 */ 00177 FL_EXPORT char *fl_locale_to_utf8(const char *s, int len, unsigned int codepage); 00178 #endif 00179 00180 /***************************************************************************** 00181 * The following functions are intended to provide portable, UTF8 aware 00182 * versions of standard functions 00183 */ 00184 00185 /* OD: UTF8 aware strncasecmp - converts to lower case Unicode and tests */ 00186 FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n); 00187 00188 /* OD: UTF8 aware strcasecmp - converts to Unicode and tests */ 00189 FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2); 00190 00191 /* OD: return the Unicode lower case value of ucs */ 00192 FL_EXPORT int fl_tolower(unsigned int ucs); 00193 00194 /* OD: return the Unicode upper case value of ucs */ 00195 FL_EXPORT int fl_toupper(unsigned int ucs); 00196 00197 /* OD: converts the UTF8 string to the lower case equivalent */ 00198 FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf); 00199 00200 /* OD: converts the UTF8 string to the upper case equivalent */ 00201 FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf); 00202 00203 /* OD: Portable UTF8 aware chmod wrapper */ 00204 FL_EXPORT int fl_chmod(const char* f, int mode); 00205 00206 /* OD: Portable UTF8 aware access wrapper */ 00207 FL_EXPORT int fl_access(const char* f, int mode); 00208 00209 /* OD: Portable UTF8 aware stat wrapper */ 00210 FL_EXPORT int fl_stat( const char *path, struct stat *buffer ); 00211 00212 /* OD: Portable UTF8 aware getcwd wrapper */ 00213 FL_EXPORT char* fl_getcwd( char *buf, int maxlen); 00214 00215 /* OD: Portable UTF8 aware fopen wrapper */ 00216 FL_EXPORT FILE *fl_fopen(const char *f, const char *mode); 00217 00218 /* OD: Portable UTF8 aware system wrapper */ 00219 FL_EXPORT int fl_system(const char* f); 00220 00221 /* OD: Portable UTF8 aware execvp wrapper */ 00222 FL_EXPORT int fl_execvp(const char *file, char *const *argv); 00223 00224 /* OD: Portable UTF8 aware open wrapper */ 00225 FL_EXPORT int fl_open(const char* f, int o, ...); 00226 00227 /* OD: Portable UTF8 aware unlink wrapper */ 00228 FL_EXPORT int fl_unlink(const char *f); 00229 00230 /* OD: Portable UTF8 aware rmdir wrapper */ 00231 FL_EXPORT int fl_rmdir(const char *f); 00232 00233 /* OD: Portable UTF8 aware getenv wrapper */ 00234 FL_EXPORT char* fl_getenv(const char *name); 00235 00236 /* OD: Portable UTF8 aware execvp wrapper */ 00237 FL_EXPORT int fl_mkdir(const char* f, int mode); 00238 00239 /* OD: Portable UTF8 aware rename wrapper */ 00240 FL_EXPORT int fl_rename(const char* f, const char *t); 00241 00242 00243 /* OD: Given a full pathname, this will create the directory path needed to hold the file named */ 00244 FL_EXPORT void fl_make_path_for_file( const char *path ); 00245 00246 /* OD: recursively create a path in the file system */ 00247 FL_EXPORT char fl_make_path( const char *path ); 00248 00249 00252 /*****************************************************************************/ 00253 00254 #ifdef __cplusplus 00255 } 00256 #endif /* __cplusplus */ 00257 00258 00259 #endif /* _HAVE_FL_UTF8_HDR_ */ 00260 00261 /* 00262 * End of "$Id: fl_utf8.h 8585 2011-04-13 15:43:22Z ianmacarthur $". 00263 */