FLTK 1.3.0
fl_utf8.h
Go to the documentation of this file.
00001 /* "$Id$"
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 
00031 /*** NOTE : all functions are LIMITED to 24 bits Unicode values !!! ***/
00032 
00038 #ifndef _HAVE_FL_UTF8_HDR_
00039 #define _HAVE_FL_UTF8_HDR_
00040 
00041 #include "Fl_Export.H"
00042 #include "fl_types.h"
00043 
00044 #include <stdio.h>
00045 #include <string.h>
00046 #include <stdlib.h>
00047 
00048 #ifdef WIN32
00049 #  include <sys/types.h>
00050 #  include <sys/stat.h>
00051 #  include <locale.h>
00052 #  include <ctype.h>
00053 #  define xchar wchar_t
00054 #  if !defined(FL_DLL) && !defined(__CYGWIN__)
00055 #    undef strdup
00056 #    define strdup _strdup
00057 #    undef putenv
00058 #    define putenv _putenv
00059 #    undef stricmp
00060 #    define stricmp _stricmp
00061 #    undef strnicmp
00062 #    define strnicmp _strnicmp
00063 #    undef hypot
00064 #    define hypot _hypot
00065 #    undef chdir
00066 #    define chdir _chdir
00067 #  endif
00068 #elif defined(__APPLE__)
00069 #  include <wchar.h>
00070 #  include <sys/stat.h>
00071 #  define xchar wchar_t
00072 #else /* X11 */
00073 #  include <sys/types.h>
00074 #  include <sys/stat.h>
00075 #  include "Xutf8.h"
00076 #  include <X11/Xlocale.h>
00077 #  include <X11/Xlib.h>
00078 #  include <locale.h>
00079 #  define xchar unsigned short
00080 #endif
00081 
00082 #  ifdef __cplusplus
00083 extern "C" {
00084 #  endif
00085 
00090 /* F2: comes from FLTK2 */
00091 /* OD: comes from OksiD */
00092 
00098 FL_EXPORT int fl_utf8bytes(unsigned ucs);
00099 
00100 /* OD: returns the byte length of the first UTF-8 char sequence (returns -1 if not valid) */
00101 FL_EXPORT int fl_utf8len(char c);
00102   
00103 /* OD: returns the byte length of the first UTF-8 char sequence (returns +1 if not valid) */
00104 FL_EXPORT int fl_utf8len1(char c);
00105   
00106 /* OD: returns the number of Unicode chars in the UTF-8 string */
00107 FL_EXPORT int fl_utf_nb_char(const unsigned char *buf, int len);
00108 
00109 /* F2: Convert the next UTF8 char-sequence into a Unicode value (and say how many bytes were used) */
00110 FL_EXPORT unsigned fl_utf8decode(const char* p, const char* end, int* len);
00111   
00112 /* F2: Encode a Unicode value into a UTF8 sequence, return the number of bytes used */
00113 FL_EXPORT int fl_utf8encode(unsigned ucs, char* buf);
00114 
00115 /* F2: Move forward to the next valid UTF8 sequence start betwen start and end */
00116 FL_EXPORT const char* fl_utf8fwd(const char* p, const char* start, const char* end);
00117 
00118 /* F2: Move backward to the previous valid UTF8 sequence start */
00119 FL_EXPORT const char* fl_utf8back(const char* p, const char* start, const char* end);
00120 
00121 /* F2: Convert a UTF8 string into UTF16 */
00122 FL_EXPORT unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
00123 
00124 /* F2: Convert a UTF8 string into a wide character string - makes UTF16 on win32, "UCS4" elsewhere */
00125 FL_EXPORT unsigned fl_utf8towc(const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen);
00126 
00127 /* F2: Convert a wide character string to UTF8 - takes in UTF16 on win32, "UCS4" elsewhere */
00128 FL_EXPORT unsigned fl_utf8fromwc(char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen);
00129 
00130 /* F2: Convert a UTF8 string into ASCII, eliding untranslatable glyphs */
00131 FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen);
00132 /* OD: convert UTF-8 string to latin1 */
00133 /* FL_EXPORT int fl_utf2latin1(const unsigned char *src, int srclen, char *dst); */
00134 
00135 /* F2: Convert 8859-1 string to UTF8 */
00136 FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen);
00137 /* OD: convert latin1 str to UTF-8 */
00138 /* FL_EXPORT int fl_latin12utf(const unsigned char *src, int srclen, char *dst); */
00139 
00140 /* F2: Returns true if the current O/S locale is UTF8 */
00141 FL_EXPORT int fl_utf8locale();
00142 
00143 /* F2: Examine the first len characters of src, to determine if the input text is UTF8 or not
00144  * NOTE: The value returned is not simply boolean - it contains information about the probable
00145  * type of the src text. */
00146 FL_EXPORT int fl_utf8test(const char *src, unsigned len);
00147 
00148 /* XX: return width of "raw" ucs character in columns.
00149  * for internal use only */
00150 FL_EXPORT int fl_wcwidth_(unsigned int ucs);
00151 
00152 /* XX: return width of utf-8 character string in columns.
00153  * NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping,
00154  * depending on original build options */
00155 FL_EXPORT int fl_wcwidth(const char *src);
00156 
00157 /* OD: Return true if the character is non-spacing */
00158 FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs);
00159 
00160 /* F2: Convert UTF8 to a local multi-byte encoding - mainly for win32? */
00161 FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen);
00162 /* OD: Convert UTF8 to a local multi-byte encoding */
00163 FL_EXPORT char* fl_utf2mbcs(const char *src);
00164 
00165 /* F2: Convert a local multi-byte encoding to UTF8 - mainly for win32? */
00166 FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen);
00167 /* OD: Convert a local multi-byte encoding to UTF8 */
00168 /* FL_EXPORT char* fl_mbcs2utf(const char *src); */
00169 
00170 /*****************************************************************************/
00171 #ifdef WIN32
00172 /* OD: Attempt to convert the UTF8 string to the current locale */
00173 FL_EXPORT char *fl_utf8_to_locale(const char *s, int len, unsigned int codepage);
00174 
00175 /* OD: Attempt to convert a string in the current locale to UTF8 */
00176 FL_EXPORT char *fl_locale_to_utf8(const char *s, int len, unsigned int codepage);
00177 #endif
00178 
00179 /*****************************************************************************
00180  * The following functions are intended to provide portable, UTF8 aware
00181  * versions of standard functions
00182  */
00183 
00184 /* OD: UTF8 aware strncasecmp - converts to lower case Unicode and tests */
00185 FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n);
00186 
00187 /* OD: UTF8 aware strcasecmp - converts to Unicode and tests */
00188 FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2);
00189 
00190 /* OD: return the Unicode lower case value of ucs */
00191 FL_EXPORT int fl_tolower(unsigned int ucs);
00192 
00193 /* OD: return the Unicode upper case value of ucs */
00194 FL_EXPORT int fl_toupper(unsigned int ucs);
00195 
00196 /* OD: converts the UTF8 string to the lower case equivalent */
00197 FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf);
00198 
00199 /* OD: converts the UTF8 string to the upper case equivalent */
00200 FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf);
00201 
00202 /* OD: Portable UTF8 aware chmod wrapper */
00203 FL_EXPORT int fl_chmod(const char* f, int mode);
00204 
00205 /* OD: Portable UTF8 aware access wrapper */
00206 FL_EXPORT int fl_access(const char* f, int mode);
00207 
00208 /* OD: Portable UTF8 aware stat wrapper */
00209 FL_EXPORT int fl_stat( const char *path, struct stat *buffer );
00210 
00211 /* OD: Portable UTF8 aware getcwd wrapper */
00212 FL_EXPORT char* fl_getcwd( char *buf, int maxlen);
00213 
00214 /* OD: Portable UTF8 aware fopen wrapper */
00215 FL_EXPORT FILE *fl_fopen(const char *f, const char *mode);
00216 
00217 /* OD: Portable UTF8 aware system wrapper */
00218 FL_EXPORT int fl_system(const char* f);
00219 
00220 /* OD: Portable UTF8 aware execvp wrapper */
00221 FL_EXPORT int fl_execvp(const char *file, char *const *argv);
00222 
00223 /* OD: Portable UTF8 aware open wrapper */
00224 FL_EXPORT int fl_open(const char* f, int o, ...);
00225 
00226 /* OD: Portable UTF8 aware unlink wrapper */
00227 FL_EXPORT int fl_unlink(const char *f);
00228 
00229 /* OD: Portable UTF8 aware rmdir wrapper */
00230 FL_EXPORT int fl_rmdir(const char *f);
00231 
00232 /* OD: Portable UTF8 aware getenv wrapper */
00233 FL_EXPORT char* fl_getenv(const char *name);
00234 
00235 /* OD: Portable UTF8 aware execvp wrapper */
00236 FL_EXPORT int fl_mkdir(const char* f, int mode);
00237 
00238 /* OD: Portable UTF8 aware rename wrapper */
00239 FL_EXPORT int fl_rename(const char* f, const char *t);
00240 
00241 
00242 /* OD: Given a full pathname, this will create the directory path needed to hold the file named */
00243 FL_EXPORT void fl_make_path_for_file( const char *path );
00244 
00245 /* OD: recursively create a path in the file system */
00246 FL_EXPORT char fl_make_path( const char *path );
00247 
00248 
00251 /*****************************************************************************/
00252 
00253 #ifdef __cplusplus
00254 }
00255 #endif /* __cplusplus */
00256 
00257 
00258 #endif /* _HAVE_FL_UTF8_HDR_ */
00259 
00260 /*
00261  * End of "$Id$".
00262  */