2015-06-15 23:24:41 +03:00
|
|
|
/*
|
2009-03-14 05:11:31 +03:00
|
|
|
* Author: Jean-Marc Lienher ( http://oksid.ch )
|
2010-11-29 00:06:39 +03:00
|
|
|
* Copyright 2000-2010 by O'ksi'D.
|
2021-05-02 18:04:16 +03:00
|
|
|
* Copyright 2016-2021 by Bill Spitzak and others.
|
2009-03-14 05:11:31 +03:00
|
|
|
*
|
2011-07-19 08:49:30 +04:00
|
|
|
* This library is free software. Distribution and use rights are outlined in
|
|
|
|
* the file "COPYING" which should have been included with this file. If this
|
|
|
|
* file is missing or damaged, see the license at:
|
2009-03-14 05:11:31 +03:00
|
|
|
*
|
2020-02-10 13:55:34 +03:00
|
|
|
* https://www.fltk.org/COPYING.php
|
2009-03-14 05:11:31 +03:00
|
|
|
*
|
2020-07-01 19:03:10 +03:00
|
|
|
* Please see the following page on how to report bugs and issues:
|
2009-03-14 05:11:31 +03:00
|
|
|
*
|
2020-07-01 19:03:10 +03:00
|
|
|
* https://www.fltk.org/bugs.php
|
2009-03-14 05:11:31 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Merged in some functionality from the fltk-2 version. IMM.
|
|
|
|
* The following code is an attempt to merge the functions incorporated in FLTK2
|
|
|
|
* with the functions provided in OksiD's fltk-1.1.6-utf8 port
|
|
|
|
*/
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2009-04-15 12:35:28 +04:00
|
|
|
/**
|
|
|
|
\file fl_utf8.h
|
2015-06-16 16:42:25 +03:00
|
|
|
\brief header for Unicode and UTF-8 character handling
|
2009-04-15 12:35:28 +04:00
|
|
|
*/
|
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
#ifndef _HAVE_FL_UTF8_HDR_
|
2008-09-19 21:40:20 +04:00
|
|
|
#define _HAVE_FL_UTF8_HDR_
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2010-04-15 12:56:37 +04:00
|
|
|
#include "Fl_Export.H"
|
|
|
|
#include "fl_types.h"
|
2022-04-03 21:10:08 +03:00
|
|
|
#include <stdio.h> // FILE *fl_fopen()
|
|
|
|
#include <sys/stat.h> // struct stat
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
#ifdef __cplusplus
|
2008-04-08 04:09:16 +04:00
|
|
|
extern "C" {
|
2015-06-15 23:24:41 +03:00
|
|
|
#endif
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2009-04-15 12:35:28 +04:00
|
|
|
/** \addtogroup fl_unicode
|
|
|
|
@{
|
|
|
|
*/
|
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/* F2: comes from FLTK2 */
|
|
|
|
/* OD: comes from OksiD */
|
|
|
|
|
2009-04-15 12:35:28 +04:00
|
|
|
/**
|
2015-06-15 23:24:41 +03:00
|
|
|
Return the number of bytes needed to encode the given UCS4 character in UTF-8.
|
2009-04-15 12:35:28 +04:00
|
|
|
\param [in] ucs UCS4 encoded character
|
|
|
|
\return number of bytes required
|
|
|
|
*/
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_utf8bytes(unsigned ucs);
|
|
|
|
|
|
|
|
/* OD: returns the byte length of the first UTF-8 char sequence (returns -1 if not valid) */
|
|
|
|
FL_EXPORT int fl_utf8len(char c);
|
2011-04-13 19:43:22 +04:00
|
|
|
|
2010-12-06 21:22:22 +03:00
|
|
|
/* OD: returns the byte length of the first UTF-8 char sequence (returns +1 if not valid) */
|
|
|
|
FL_EXPORT int fl_utf8len1(char c);
|
2011-04-13 19:43:22 +04:00
|
|
|
|
2023-01-20 18:13:00 +03:00
|
|
|
/* OD: returns the byte length of a UTF-8 text */
|
2023-01-20 18:20:01 +03:00
|
|
|
FL_EXPORT int fl_utf8strlen(const char *text, int len);
|
2023-01-20 18:13:00 +03:00
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/* OD: returns the number of Unicode chars in the UTF-8 string */
|
|
|
|
FL_EXPORT int fl_utf_nb_char(const unsigned char *buf, int len);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert the next UTF-8 char-sequence into a Unicode value (and say how many bytes were used) */
|
2009-04-18 15:51:32 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8decode(const char* p, const char* end, int* len);
|
2011-04-13 19:43:22 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Encode a Unicode value into a UTF-8 sequence, return the number of bytes used */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_utf8encode(unsigned ucs, char* buf);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Move forward to the next valid UTF-8 sequence start betwen start and end */
|
2009-04-18 15:51:32 +04:00
|
|
|
FL_EXPORT const char* fl_utf8fwd(const char* p, const char* start, const char* end);
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Move backward to the previous valid UTF-8 sequence start */
|
2009-04-18 15:51:32 +04:00
|
|
|
FL_EXPORT const char* fl_utf8back(const char* p, const char* start, const char* end);
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2011-04-13 19:43:22 +04:00
|
|
|
/* XX: Convert a single 32-bit Unicode value into UTF16 */
|
|
|
|
FL_EXPORT unsigned fl_ucs_to_Utf16(const unsigned ucs, unsigned short *dst, const unsigned dstlen);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert a UTF-8 string into UTF16 */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert a UTF-8 string into a wide character string - makes UTF16 on win32, "UCS4" elsewhere */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8towc(const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert a wide character string to UTF-8 - takes in UTF16 on win32, "UCS4" elsewhere */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8fromwc(char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert a UTF-8 string into ASCII, eliding untranslatable glyphs */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert 8859-1 string to UTF-8 */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Returns true if the current O/S locale is UTF-8 */
|
2016-02-27 20:27:21 +03:00
|
|
|
FL_EXPORT int fl_utf8locale(void);
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Examine the first len characters of src, to determine if the input text is UTF-8 or not
|
2008-04-08 04:09:16 +04:00
|
|
|
* NOTE: The value returned is not simply boolean - it contains information about the probable
|
|
|
|
* type of the src text. */
|
|
|
|
FL_EXPORT int fl_utf8test(const char *src, unsigned len);
|
|
|
|
|
2010-04-21 01:43:31 +04:00
|
|
|
/* XX: return width of "raw" ucs character in columns.
|
|
|
|
* for internal use only */
|
|
|
|
FL_EXPORT int fl_wcwidth_(unsigned int ucs);
|
|
|
|
|
2016-04-09 13:42:17 +03:00
|
|
|
/* XX: return width of UTF-8 character string in columns.
|
2010-04-21 01:43:31 +04:00
|
|
|
* NOTE: this may also do C1 control character (0x80 to 0x9f) to CP1252 mapping,
|
|
|
|
* depending on original build options */
|
|
|
|
FL_EXPORT int fl_wcwidth(const char *src);
|
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/* OD: Return true if the character is non-spacing */
|
|
|
|
FL_EXPORT unsigned int fl_nonspacing(unsigned int ucs);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert UTF-8 to a local multi-byte encoding - mainly for win32? */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8to_mb(const char *src, unsigned srclen, char *dst, unsigned dstlen);
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Convert UTF-8 to a local multi-byte encoding */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT char* fl_utf2mbcs(const char *src);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* F2: Convert a local multi-byte encoding to UTF-8 - mainly for win32? */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT unsigned fl_utf8from_mb(char *dst, unsigned dstlen, const char *src, unsigned srclen);
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2018-02-09 17:39:42 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* these two Windows-only functions are kept for API compatibility */
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Attempt to convert the UTF-8 string to the current locale */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT char *fl_utf8_to_locale(const char *s, int len, unsigned int codepage);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Attempt to convert a string in the current locale to UTF-8 */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT char *fl_locale_to_utf8(const char *s, int len, unsigned int codepage);
|
2018-02-09 17:39:42 +03:00
|
|
|
#endif /* _WIN32 */
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2009-03-14 05:11:31 +03:00
|
|
|
/*****************************************************************************
|
2015-06-15 23:24:41 +03:00
|
|
|
* The following functions are intended to provide portable, UTF-8 aware
|
2009-03-14 05:11:31 +03:00
|
|
|
* versions of standard functions
|
|
|
|
*/
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: UTF-8 aware strncasecmp - converts to lower case Unicode and tests */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_utf_strncasecmp(const char *s1, const char *s2, int n);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: UTF-8 aware strcasecmp - converts to Unicode and tests */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_utf_strcasecmp(const char *s1, const char *s2);
|
|
|
|
|
|
|
|
/* OD: return the Unicode lower case value of ucs */
|
|
|
|
FL_EXPORT int fl_tolower(unsigned int ucs);
|
|
|
|
|
|
|
|
/* OD: return the Unicode upper case value of ucs */
|
|
|
|
FL_EXPORT int fl_toupper(unsigned int ucs);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: converts the UTF-8 string to the lower case equivalent */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_utf_tolower(const unsigned char *str, int len, char *buf);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: converts the UTF-8 string to the upper case equivalent */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_utf_toupper(const unsigned char *str, int len, char *buf);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware chmod wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_chmod(const char* f, int mode);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware access wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_access(const char* f, int mode);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware stat wrapper */
|
2017-11-10 15:56:00 +03:00
|
|
|
FL_EXPORT int fl_stat(const char *path, struct stat *buffer);
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware getcwd wrapper */
|
2017-11-10 15:56:00 +03:00
|
|
|
FL_EXPORT char *fl_getcwd(char *buf, int len);
|
|
|
|
|
|
|
|
/* Portable UTF-8 aware chdir wrapper */
|
|
|
|
FL_EXPORT int fl_chdir(const char *path);
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware fopen wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT FILE *fl_fopen(const char *f, const char *mode);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware system wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_system(const char* f);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware execvp wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_execvp(const char *file, char *const *argv);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware open wrapper */
|
2017-11-10 15:56:00 +03:00
|
|
|
FL_EXPORT int fl_open(const char *fname, int oflags, ...);
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2017-11-10 15:56:00 +03:00
|
|
|
FL_EXPORT int fl_open_ext(const char *fname, int binary, int oflags, ...);
|
2017-10-12 17:42:12 +03:00
|
|
|
|
2022-12-17 21:13:30 +03:00
|
|
|
/* Portable wrapper around unix-style close() function */
|
|
|
|
FL_EXPORT int fl_close_fd(int fd);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware unlink wrapper */
|
2017-10-15 13:18:53 +03:00
|
|
|
FL_EXPORT int fl_unlink(const char *fname);
|
2008-04-08 04:09:16 +04:00
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware rmdir wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_rmdir(const char *f);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware getenv wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT char* fl_getenv(const char *name);
|
|
|
|
|
2020-02-10 13:55:34 +03:00
|
|
|
/* Portable UTF-8 aware putenv wrapper */
|
|
|
|
FL_EXPORT int fl_putenv(const char *var);
|
|
|
|
|
2021-05-02 18:04:16 +03:00
|
|
|
/* OD: Portable UTF-8 aware mkdir wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_mkdir(const char* f, int mode);
|
|
|
|
|
2015-06-15 23:24:41 +03:00
|
|
|
/* OD: Portable UTF-8 aware rename wrapper */
|
2008-04-08 04:09:16 +04:00
|
|
|
FL_EXPORT int fl_rename(const char* f, const char *t);
|
|
|
|
|
|
|
|
|
|
|
|
/* OD: Given a full pathname, this will create the directory path needed to hold the file named */
|
|
|
|
FL_EXPORT void fl_make_path_for_file( const char *path );
|
|
|
|
|
|
|
|
/* OD: recursively create a path in the file system */
|
|
|
|
FL_EXPORT char fl_make_path( const char *path );
|
|
|
|
|
2009-04-15 12:35:28 +04:00
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
2008-04-08 04:09:16 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
2009-03-14 05:11:31 +03:00
|
|
|
#endif /* _HAVE_FL_UTF8_HDR_ */
|