FLTK 1.3.2

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

fl_utf8.h
Go to the documentation of this file.

    00001 /* "$Id: fl_utf8.h 8864 2011-07-19 04:49:30Z greg.ercolano $"
    00002  *
    00003  * Author: Jean-Marc Lienher ( http://oksid.ch )
    00004  * Copyright 2000-2010 by O'ksi'D.
    00005  *
    00006  * This library is free software. Distribution and use rights are outlined in
    00007  * the file "COPYING" which should have been included with this file.  If this
    00008  * file is missing or damaged, see the license at:
    00009  *
    00010  *     http://www.fltk.org/COPYING.php
    00011  *
    00012  * Please report all bugs and problems on the following page:
    00013  *
    00014  *     http://www.fltk.org/str.php
    00015  */
    00016
    00017 /* Merged in some functionality from the fltk-2 version. IMM.
    00018  * The following code is an attempt to merge the functions incorporated in FLTK2
    00019  * with the functions provided in OksiD's fltk-1.1.6-utf8 port
    00020  */
    00021
    00027 #ifndef _HAVE_FL_UTF8_HDR_
    00028 #define _HAVE_FL_UTF8_HDR_
    00029
    00030 #include "Fl_Export.H"
    00031 #include "fl_types.h"
    00032
    00033 #include <stdio.h>
    00034 #include <string.h>
    00035 #include <stdlib.h>
    00036
    00037 #ifdef WIN32
    00038 #  include <sys/types.h>
    00039 #  include <sys/stat.h>
    00040 #  include <locale.h>
    00041 #  include <ctype.h>
    00042 #  define xchar wchar_t
    00043 #  if !defined(FL_DLL) && !defined(__CYGWIN__)
    00044 #    undef strdup
    00045 #    define strdup _strdup
    00046 #    undef putenv
    00047 #    define putenv _putenv
    00048 #    undef stricmp
    00049 #    define stricmp _stricmp
    00050 #    undef strnicmp
    00051 #    define strnicmp _strnicmp
    00052 #    undef hypot
    00053 #    define hypot _hypot
    00054 #    undef chdir
    00055 #    define chdir _chdir
    00056 #  endif
    00057 #elif defined(__APPLE__)
    00058 #  include <wchar.h>
    00059 #  include <sys/stat.h>
    00060 #  define xchar wchar_t
    00061 #else /* X11 */
    00062 #  include <sys/types.h>
    00063 #  include <sys/stat.h>
    00064 #  include "Xutf8.h"
    00065 #  include <X11/Xlocale.h>
    00066 #  include <X11/Xlib.h>
    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 UTF8 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 UTF8 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 UTF8 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 UTF8 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 UTF8 string into UTF16 */
    00114 FL_EXPORT unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
    00115
    00116 /* F2: Convert a UTF8 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 UTF8 - 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 UTF8 string into ASCII, eliding untranslatable glyphs */
    00123 FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen);
    00124 /* OD: convert UTF-8 string to latin1 */
    00125 /* FL_EXPORT int fl_utf2latin1(const unsigned char *src, int srclen, char *dst); */
    00126
    00127 /* F2: Convert 8859-1 string to UTF8 */
    00128 FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen);
    00129 /* OD: convert latin1 str to UTF-8 */
    00130 /* FL_EXPORT int fl_latin12utf(const unsigned char *src, int srclen, char *dst); */
    00131
    00132 /* F2: Returns true if the current O/S locale is UTF8 */
    00133 FL_EXPORT int fl_utf8locale();
    00134
    00135 /* F2: Examine the first len characters of src, to determine if the input text is UTF8 or not
    00136  * NOTE: The value returned is not simply boolean - it contains information about the probable
    00137  * type of the src text. */
    00138 FL_EXPORT int fl_utf8test(const char *src, unsigned len);
    00139
    00140 /* XX: return width of "raw" ucs character in columns.
    00141  * for internal use only */
    00142 FL_EXPORT int fl_wcwidth_(unsigned int ucs);
    00143
    00144 /* XX: return width of utf-8 character string in columns.
    00145  * NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping,
    00146  * depending on original build options */
    00147 FL_EXPORT int fl_wcwidth(const char *src);
    00148
    00149 /* OD: Return true if the character is non-spacing */
    00150 FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs);
    00151
    00152 /* F2: Convert UTF8 to a local multi-byte encoding - mainly for win32? */
    00153 FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen);
    00154 /* OD: Convert UTF8 to a local multi-byte encoding */
    00155 FL_EXPORT char* fl_utf2mbcs(const char *src);
    00156
    00157 /* F2: Convert a local multi-byte encoding to UTF8 - mainly for win32? */
    00158 FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen);
    00159 /* OD: Convert a local multi-byte encoding to UTF8 */
    00160 /* FL_EXPORT char* fl_mbcs2utf(const char *src); */
    00161
    00162 /*****************************************************************************/
    00163 #ifdef WIN32
    00164 /* OD: Attempt to convert the UTF8 string to the current locale */
    00165 FL_EXPORT char *fl_utf8_to_locale(const char *s, int len, unsigned int codepage);
    00166
    00167 /* OD: Attempt to convert a string in the current locale to UTF8 */
    00168 FL_EXPORT char *fl_locale_to_utf8(const char *s, int len, unsigned int codepage);
    00169 #endif
    00170
    00171 /*****************************************************************************
    00172  * The following functions are intended to provide portable, UTF8 aware
    00173  * versions of standard functions
    00174  */
    00175
    00176 /* OD: UTF8 aware strncasecmp - converts to lower case Unicode and tests */
    00177 FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n);
    00178
    00179 /* OD: UTF8 aware strcasecmp - converts to Unicode and tests */
    00180 FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2);
    00181
    00182 /* OD: return the Unicode lower case value of ucs */
    00183 FL_EXPORT int fl_tolower(unsigned int ucs);
    00184
    00185 /* OD: return the Unicode upper case value of ucs */
    00186 FL_EXPORT int fl_toupper(unsigned int ucs);
    00187
    00188 /* OD: converts the UTF8 string to the lower case equivalent */
    00189 FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf);
    00190
    00191 /* OD: converts the UTF8 string to the upper case equivalent */
    00192 FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf);
    00193
    00194 /* OD: Portable UTF8 aware chmod wrapper */
    00195 FL_EXPORT int fl_chmod(const char* f, int mode);
    00196
    00197 /* OD: Portable UTF8 aware access wrapper */
    00198 FL_EXPORT int fl_access(const char* f, int mode);
    00199
    00200 /* OD: Portable UTF8 aware stat wrapper */
    00201 FL_EXPORT int fl_stat( const char *path, struct stat *buffer );
    00202
    00203 /* OD: Portable UTF8 aware getcwd wrapper */
    00204 FL_EXPORT char* fl_getcwd( char *buf, int maxlen);
    00205
    00206 /* OD: Portable UTF8 aware fopen wrapper */
    00207 FL_EXPORT FILE *fl_fopen(const char *f, const char *mode);
    00208
    00209 /* OD: Portable UTF8 aware system wrapper */
    00210 FL_EXPORT int fl_system(const char* f);
    00211
    00212 /* OD: Portable UTF8 aware execvp wrapper */
    00213 FL_EXPORT int fl_execvp(const char *file, char *const *argv);
    00214
    00215 /* OD: Portable UTF8 aware open wrapper */
    00216 FL_EXPORT int fl_open(const char* f, int o, ...);
    00217
    00218 /* OD: Portable UTF8 aware unlink wrapper */
    00219 FL_EXPORT int fl_unlink(const char *f);
    00220
    00221 /* OD: Portable UTF8 aware rmdir wrapper */
    00222 FL_EXPORT int fl_rmdir(const char *f);
    00223
    00224 /* OD: Portable UTF8 aware getenv wrapper */
    00225 FL_EXPORT char* fl_getenv(const char *name);
    00226
    00227 /* OD: Portable UTF8 aware execvp wrapper */
    00228 FL_EXPORT int fl_mkdir(const char* f, int mode);
    00229
    00230 /* OD: Portable UTF8 aware rename wrapper */
    00231 FL_EXPORT int fl_rename(const char* f, const char *t);
    00232
    00233
    00234 /* OD: Given a full pathname, this will create the directory path needed to hold the file named */
    00235 FL_EXPORT void fl_make_path_for_file( const char *path );
    00236
    00237 /* OD: recursively create a path in the file system */
    00238 FL_EXPORT char fl_make_path( const char *path );
    00239
    00240
    00243 /*****************************************************************************/
    00244
    00245 #ifdef __cplusplus
    00246 }
    00247 #endif /* __cplusplus */
    00248
    00249
    00250 #endif /* _HAVE_FL_UTF8_HDR_ */
    00251
    00252 /*
    00253  * End of "$Id: fl_utf8.h 8864 2011-07-19 04:49:30Z greg.ercolano $".
    00254  */