Blame FL/fl_utf8.h

Packit Service 9ac617
/*
Packit Service 9ac617
 * "$Id: fl_utf8.h 11266 2016-03-02 12:15:08Z AlbrechtS $"
Packit Service 9ac617
 *
Packit Service 9ac617
 * Author: Jean-Marc Lienher ( http://oksid.ch )
Packit Service 9ac617
 * Copyright 2000-2010 by O'ksi'D.
Packit Service 9ac617
 *
Packit Service 9ac617
 * This library is free software. Distribution and use rights are outlined in
Packit Service 9ac617
 * the file "COPYING" which should have been included with this file.  If this
Packit Service 9ac617
 * file is missing or damaged, see the license at:
Packit Service 9ac617
 *
Packit Service 9ac617
 *     http://www.fltk.org/COPYING.php
Packit Service 9ac617
 *
Packit Service 9ac617
 * Please report all bugs and problems on the following page:
Packit Service 9ac617
 *
Packit Service 9ac617
 *     http://www.fltk.org/str.php
Packit Service 9ac617
 */
Packit Service 9ac617
Packit Service 9ac617
/* Merged in some functionality from the fltk-2 version. IMM.
Packit Service 9ac617
 * The following code is an attempt to merge the functions incorporated in FLTK2
Packit Service 9ac617
 * with the functions provided in OksiD's fltk-1.1.6-utf8 port
Packit Service 9ac617
 */
Packit Service 9ac617
Packit Service 9ac617
/**
Packit Service 9ac617
  \file fl_utf8.h
Packit Service 9ac617
  \brief header for Unicode and UTF-8 character handling
Packit Service 9ac617
*/
Packit Service 9ac617
Packit Service 9ac617
#ifndef _HAVE_FL_UTF8_HDR_
Packit Service 9ac617
#define _HAVE_FL_UTF8_HDR_
Packit Service 9ac617
Packit Service 9ac617
#include "Fl_Export.H"
Packit Service 9ac617
#include "fl_types.h"
Packit Service 9ac617
Packit Service 9ac617
#include <stdio.h>
Packit Service 9ac617
#include <string.h>
Packit Service 9ac617
#include <stdlib.h>
Packit Service 9ac617
Packit Service 9ac617
#ifdef WIN32
Packit Service 9ac617
#  include <sys/types.h>
Packit Service 9ac617
#  include <sys/stat.h>
Packit Service 9ac617
#  include <locale.h>
Packit Service 9ac617
#  include <ctype.h>
Packit Service 9ac617
#  define xchar wchar_t
Packit Service 9ac617
#  if !defined(FL_DLL) && !defined(__CYGWIN__)
Packit Service 9ac617
#    undef strdup
Packit Service 9ac617
#    define strdup _strdup
Packit Service 9ac617
#    undef putenv
Packit Service 9ac617
#    define putenv _putenv
Packit Service 9ac617
#    undef stricmp
Packit Service 9ac617
#    define stricmp _stricmp
Packit Service 9ac617
#    undef strnicmp
Packit Service 9ac617
#    define strnicmp _strnicmp
Packit Service 9ac617
#    undef chdir
Packit Service 9ac617
#    define chdir _chdir
Packit Service 9ac617
#  endif
Packit Service 9ac617
#elif defined(__APPLE__)
Packit Service 9ac617
#  include <wchar.h>
Packit Service 9ac617
#  include <sys/stat.h>
Packit Service 9ac617
#  define xchar wchar_t
Packit Service 9ac617
#else /* X11 */
Packit Service 9ac617
#  include <sys/types.h>
Packit Service 9ac617
#  include <sys/stat.h>
Packit Service 9ac617
#  if defined(FL_LIBRARY) /* don't expose X11 headers in user space */
Packit Service 9ac617
#    include <X11/Xlocale.h>
Packit Service 9ac617
#    include <X11/Xlib.h>
Packit Service 9ac617
#  endif /* defined(FL_LIBRARY) -- don't expose X11 headers in user space */
Packit Service 9ac617
#  include <locale.h>
Packit Service 9ac617
#  define xchar unsigned short
Packit Service 9ac617
#endif
Packit Service 9ac617
Packit Service 9ac617
#ifdef __cplusplus
Packit Service 9ac617
extern "C" {
Packit Service 9ac617
#endif
Packit Service 9ac617
Packit Service 9ac617
/** \addtogroup fl_unicode
Packit Service 9ac617
    @{
Packit Service 9ac617
*/
Packit Service 9ac617
Packit Service 9ac617
/* F2: comes from FLTK2 */
Packit Service 9ac617
/* OD: comes from OksiD */
Packit Service 9ac617
Packit Service 9ac617
/**
Packit Service 9ac617
  Return the number of bytes needed to encode the given UCS4 character in UTF-8.
Packit Service 9ac617
  \param [in] ucs UCS4 encoded character
Packit Service 9ac617
  \return number of bytes required
Packit Service 9ac617
 */
Packit Service 9ac617
FL_EXPORT int fl_utf8bytes(unsigned ucs);
Packit Service 9ac617
Packit Service 9ac617
/* OD: returns the byte length of the first UTF-8 char sequence (returns -1 if not valid) */
Packit Service 9ac617
FL_EXPORT int fl_utf8len(char c);
Packit Service 9ac617
Packit Service 9ac617
/* OD: returns the byte length of the first UTF-8 char sequence (returns +1 if not valid) */
Packit Service 9ac617
FL_EXPORT int fl_utf8len1(char c);
Packit Service 9ac617
Packit Service 9ac617
/* OD: returns the number of Unicode chars in the UTF-8 string */
Packit Service 9ac617
FL_EXPORT int fl_utf_nb_char(const unsigned char *buf, int len);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert the next UTF-8 char-sequence into a Unicode value (and say how many bytes were used) */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8decode(const char* p, const char* end, int* len);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Encode a Unicode value into a UTF-8 sequence, return the number of bytes used */
Packit Service 9ac617
FL_EXPORT int fl_utf8encode(unsigned ucs, char* buf);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Move forward to the next valid UTF-8 sequence start betwen start and end */
Packit Service 9ac617
FL_EXPORT const char* fl_utf8fwd(const char* p, const char* start, const char* end);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Move backward to the previous valid UTF-8 sequence start */
Packit Service 9ac617
FL_EXPORT const char* fl_utf8back(const char* p, const char* start, const char* end);
Packit Service 9ac617
Packit Service 9ac617
/* XX: Convert a single 32-bit Unicode value into UTF16 */
Packit Service 9ac617
FL_EXPORT unsigned fl_ucs_to_Utf16(const unsigned ucs, unsigned short *dst, const unsigned dstlen);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert a UTF-8 string into UTF16 */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert a UTF-8 string into a wide character string - makes UTF16 on win32, "UCS4" elsewhere */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8towc(const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert a wide character string to UTF-8 - takes in UTF16 on win32, "UCS4" elsewhere */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8fromwc(char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert a UTF-8 string into ASCII, eliding untranslatable glyphs */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert 8859-1 string to UTF-8 */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Returns true if the current O/S locale is UTF-8 */
Packit Service 9ac617
FL_EXPORT int fl_utf8locale(void);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Examine the first len characters of src, to determine if the input text is UTF-8 or not
Packit Service 9ac617
 * NOTE: The value returned is not simply boolean - it contains information about the probable
Packit Service 9ac617
 * type of the src text. */
Packit Service 9ac617
FL_EXPORT int fl_utf8test(const char *src, unsigned len);
Packit Service 9ac617
Packit Service 9ac617
/* XX: return width of "raw" ucs character in columns.
Packit Service 9ac617
 * for internal use only */
Packit Service 9ac617
FL_EXPORT int fl_wcwidth_(unsigned int ucs);
Packit Service 9ac617
Packit Service 9ac617
/* XX: return width of utf-8 character string in columns.
Packit Service 9ac617
 * NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping,
Packit Service 9ac617
 * depending on original build options */
Packit Service 9ac617
FL_EXPORT int fl_wcwidth(const char *src);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Return true if the character is non-spacing */
Packit Service 9ac617
FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert UTF-8 to a local multi-byte encoding - mainly for win32? */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen);
Packit Service 9ac617
/* OD: Convert UTF-8 to a local multi-byte encoding */
Packit Service 9ac617
FL_EXPORT char* fl_utf2mbcs(const char *src);
Packit Service 9ac617
Packit Service 9ac617
/* F2: Convert a local multi-byte encoding to UTF-8 - mainly for win32? */
Packit Service 9ac617
FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen);
Packit Service 9ac617
Packit Service 9ac617
/*****************************************************************************/
Packit Service 9ac617
#ifdef WIN32
Packit Service 9ac617
/* OD: Attempt to convert the UTF-8 string to the current locale */
Packit Service 9ac617
FL_EXPORT char *fl_utf8_to_locale(const char *s, int len, unsigned int codepage);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Attempt to convert a string in the current locale to UTF-8 */
Packit Service 9ac617
FL_EXPORT char *fl_locale_to_utf8(const char *s, int len, unsigned int codepage);
Packit Service 9ac617
#endif
Packit Service 9ac617
Packit Service 9ac617
/*****************************************************************************
Packit Service 9ac617
 * The following functions are intended to provide portable, UTF-8 aware
Packit Service 9ac617
 * versions of standard functions
Packit Service 9ac617
 */
Packit Service 9ac617
Packit Service 9ac617
/* OD: UTF-8 aware strncasecmp - converts to lower case Unicode and tests */
Packit Service 9ac617
FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n);
Packit Service 9ac617
Packit Service 9ac617
/* OD: UTF-8 aware strcasecmp - converts to Unicode and tests */
Packit Service 9ac617
FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2);
Packit Service 9ac617
Packit Service 9ac617
/* OD: return the Unicode lower case value of ucs */
Packit Service 9ac617
FL_EXPORT int fl_tolower(unsigned int ucs);
Packit Service 9ac617
Packit Service 9ac617
/* OD: return the Unicode upper case value of ucs */
Packit Service 9ac617
FL_EXPORT int fl_toupper(unsigned int ucs);
Packit Service 9ac617
Packit Service 9ac617
/* OD: converts the UTF-8 string to the lower case equivalent */
Packit Service 9ac617
FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf);
Packit Service 9ac617
Packit Service 9ac617
/* OD: converts the UTF-8 string to the upper case equivalent */
Packit Service 9ac617
FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware chmod wrapper */
Packit Service 9ac617
FL_EXPORT int fl_chmod(const char* f, int mode);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware access wrapper */
Packit Service 9ac617
FL_EXPORT int fl_access(const char* f, int mode);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware stat wrapper */
Packit Service 9ac617
FL_EXPORT int fl_stat( const char *path, struct stat *buffer );
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware getcwd wrapper */
Packit Service 9ac617
FL_EXPORT char* fl_getcwd( char *buf, int maxlen);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware fopen wrapper */
Packit Service 9ac617
FL_EXPORT FILE *fl_fopen(const char *f, const char *mode);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware system wrapper */
Packit Service 9ac617
FL_EXPORT int fl_system(const char* f);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware execvp wrapper */
Packit Service 9ac617
FL_EXPORT int fl_execvp(const char *file, char *const *argv);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware open wrapper */
Packit Service 9ac617
FL_EXPORT int fl_open(const char* f, int o, ...);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware unlink wrapper */
Packit Service 9ac617
FL_EXPORT int fl_unlink(const char *f);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware rmdir wrapper */
Packit Service 9ac617
FL_EXPORT int fl_rmdir(const char *f);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware getenv wrapper */
Packit Service 9ac617
FL_EXPORT char* fl_getenv(const char *name);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware execvp wrapper */
Packit Service 9ac617
FL_EXPORT int fl_mkdir(const char* f, int mode);
Packit Service 9ac617
Packit Service 9ac617
/* OD: Portable UTF-8 aware rename wrapper */
Packit Service 9ac617
FL_EXPORT int fl_rename(const char* f, const char *t);
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
/* OD: Given a full pathname, this will create the directory path needed to hold the file named */
Packit Service 9ac617
FL_EXPORT void fl_make_path_for_file( const char *path );
Packit Service 9ac617
Packit Service 9ac617
/* OD: recursively create a path in the file system */
Packit Service 9ac617
FL_EXPORT char fl_make_path( const char *path );
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
/** @} */
Packit Service 9ac617
Packit Service 9ac617
/*****************************************************************************/
Packit Service 9ac617
Packit Service 9ac617
#ifdef __cplusplus
Packit Service 9ac617
}
Packit Service 9ac617
#endif /* __cplusplus */
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
#endif /* _HAVE_FL_UTF8_HDR_ */
Packit Service 9ac617
Packit Service 9ac617
/*
Packit Service 9ac617
 * End of "$Id: fl_utf8.h 11266 2016-03-02 12:15:08Z AlbrechtS $".
Packit Service 9ac617
 */