• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

fl_utf8.h

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

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.