fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Unicode and UTF-8 functions

Defines

#define ERRORS_TO_ISO8859_1   1
#define ERRORS_TO_CP1252   1
#define STRICT_RFC3629   0
#define NBC   0xFFFF + 1

Functions

FL_EXPORT int fl_utf8bytes (unsigned ucs)
FL_EXPORT int fl_utf8len (char c)
FL_EXPORT int fl_utf8len1 (char c)
FL_EXPORT int fl_utf_nb_char (const unsigned char *buf, int len)
FL_EXPORT unsigned fl_utf8decode (const char *p, const char *end, int *len)
FL_EXPORT int fl_utf8encode (unsigned ucs, char *buf)
FL_EXPORT const char * fl_utf8fwd (const char *p, const char *start, const char *end)
FL_EXPORT const char * fl_utf8back (const char *p, const char *start, const char *end)
FL_EXPORT unsigned fl_utf8toUtf16 (const char *src, unsigned srclen, unsigned short *dst, unsigned dstlen)
FL_EXPORT unsigned fl_utf8towc (const char *src, unsigned srclen, wchar_t *dst, unsigned dstlen)
FL_EXPORT unsigned fl_utf8fromwc (char *dst, unsigned dstlen, const wchar_t *src, unsigned srclen)
FL_EXPORT unsigned fl_utf8toa (const char *src, unsigned srclen, char *dst, unsigned dstlen)
FL_EXPORT unsigned fl_utf8froma (char *dst, unsigned dstlen, const char *src, unsigned srclen)
FL_EXPORT int fl_utf8locale ()
FL_EXPORT int fl_utf8test (const char *src, unsigned len)
FL_EXPORT int fl_wcwidth_ (unsigned int ucs)
FL_EXPORT int fl_wcwidth (const char *src)
FL_EXPORT unsigned int fl_nonspacing (unsigned int ucs)
FL_EXPORT unsigned fl_utf8to_mb (const char *src, unsigned srclen, char *dst, unsigned dstlen)
FL_EXPORT char * fl_utf2mbcs (const char *src)
FL_EXPORT unsigned fl_utf8from_mb (char *dst, unsigned dstlen, const char *src, unsigned srclen)
FL_EXPORT int fl_utf_strncasecmp (const char *s1, const char *s2, int n)
FL_EXPORT int fl_utf_strcasecmp (const char *s1, const char *s2)
FL_EXPORT int fl_tolower (unsigned int ucs)
FL_EXPORT int fl_toupper (unsigned int ucs)
FL_EXPORT int fl_utf_tolower (const unsigned char *str, int len, char *buf)
FL_EXPORT int fl_utf_toupper (const unsigned char *str, int len, char *buf)
FL_EXPORT int fl_chmod (const char *f, int mode)
FL_EXPORT int fl_access (const char *f, int mode)
FL_EXPORT int fl_stat (const char *path, struct stat *buffer)
FL_EXPORT char * fl_getcwd (char *buf, int maxlen)
FL_EXPORT FILE * fl_fopen (const char *f, const char *mode)
FL_EXPORT int fl_system (const char *f)
FL_EXPORT int fl_execvp (const char *file, char *const *argv)
FL_EXPORT int fl_open (const char *f, int o,...)
FL_EXPORT int fl_unlink (const char *f)
FL_EXPORT int fl_rmdir (const char *f)
FL_EXPORT char * fl_getenv (const char *name)
FL_EXPORT int fl_mkdir (const char *f, int mode)
FL_EXPORT int fl_rename (const char *f, const char *t)
FL_EXPORT void fl_make_path_for_file (const char *path)
FL_EXPORT char fl_make_path (const char *path)

Detailed Description

fl global Unicode and UTF-8 handling functions declared in <FL/fl_utf8.h>


Define Documentation

#define ERRORS_TO_CP1252   1

Set to 1 to turn bad UTF8 bytes in the 0x80-0x9f range into the Unicode index for Microsoft's CP1252 character set. You should also set ERRORS_TO_ISO8859_1. With this a huge amount of more available text (such as all web pages) are correctly converted to Unicode.

Definition at line 87 of file fl_utf.c.

#define ERRORS_TO_ISO8859_1   1

Set to 1 to turn bad UTF8 bytes into ISO-8859-1. If this is to zero they are instead turned into the Unicode REPLACEMENT CHARACTER, of value 0xfffd. If this is on fl_utf8decode() will correctly map most (perhaps all) human-readable text that is in ISO-8859-1. This may allow you to completely ignore character sets in your code because virtually everything is either ISO-8859-1 or UTF-8.

Definition at line 79 of file fl_utf.c.

#define NBC   0xFFFF + 1

Definition at line 88 of file fl_utf8.cxx.

#define STRICT_RFC3629   0

A number of Unicode code points are in fact illegal and should not be produced by a UTF-8 converter. Turn this on will replace the bytes in those encodings with errors. If you do this then converting arbitrary 16-bit data to UTF-8 and then back is not an identity, which will probably break a lot of software.

Definition at line 95 of file fl_utf.c.


Function Documentation

int fl_access ( const char *  f,
int  mode 
)

Definition at line 690 of file fl_utf8.cxx.

References fl_utf8toUtf16(), NULL, and xchar.

Referenced by fl_make_path().

int fl_chmod ( const char *  f,
int  mode 
)

Definition at line 674 of file fl_utf8.cxx.

References fl_utf8toUtf16(), NULL, and xchar.

int fl_execvp ( const char *  file,
char *const *  argv 
)

Definition at line 626 of file fl_utf8.cxx.

References fl_utf2mbcs(), fl_utf8toUtf16(), i, NULL, and xchar.

char * fl_getcwd ( char *  buf,
int  maxlen 
)

Definition at line 723 of file fl_utf8.cxx.

References b, fl_utf8fromwc(), NULL, and xchar.

Referenced by fl_filename_absolute(), and fl_filename_relative().

char * fl_getenv ( const char *  name)

Definition at line 531 of file fl_utf8.cxx.

References buf, fl_utf8fromwc(), fl_utf8toUtf16(), NULL, and xchar.

Referenced by fl_filename_expand().

char fl_make_path ( const char *  path)

Definition at line 818 of file fl_utf8.cxx.

References fl_access(), and fl_mkdir().

Referenced by fl_make_path_for_file().

void fl_make_path_for_file ( const char *  path)

Definition at line 834 of file fl_utf8.cxx.

References fl_make_path().

int fl_mkdir ( const char *  f,
int  mode 
)

Definition at line 765 of file fl_utf8.cxx.

References fl_utf8toUtf16(), NULL, and xchar.

Referenced by fl_make_path().

unsigned int fl_nonspacing ( unsigned int  ucs)

returns true if the character is non-spacing.

Todo:
explain what non-spacing means.

Definition at line 400 of file fl_utf8.cxx.

References XUtf8IsNonSpacing().

Referenced by fl_width().

int fl_open ( const char *  f,
int  o,
  ... 
)

Definition at line 560 of file fl_utf8.cxx.

References fl_utf8toUtf16(), NULL, and xchar.

int fl_rename ( const char *  f,
const char *  t 
)

Definition at line 798 of file fl_utf8.cxx.

References fl_utf8toUtf16(), NULL, and xchar.

int fl_rmdir ( const char *  f)

Definition at line 782 of file fl_utf8.cxx.

References fl_utf8toUtf16(), NULL, and xchar.

int fl_stat ( const char *  path,
struct stat *  buffer 
)
int fl_system ( const char *  f)

Definition at line 606 of file fl_utf8.cxx.

References fl_utf2mbcs(), fl_utf8toUtf16(), NULL, and xchar.

int fl_tolower ( unsigned int  ucs)

return the Unicode lower case value of ucs

Definition at line 268 of file fl_utf8.cxx.

References XUtf8Tolower().

Referenced by fl_shortcut_label(), Fl_Text_Buffer::search_backward(), Fl_Text_Buffer::search_forward(), and Fl::test_shortcut().

int fl_toupper ( unsigned int  ucs)

return the Unicode upper case value of ucs

Definition at line 276 of file fl_utf8.cxx.

Referenced by fl_shortcut_label().

int fl_unlink ( const char *  f)

Definition at line 749 of file fl_utf8.cxx.

References fl_utf8toUtf16(), NULL, and xchar.

char * fl_utf2mbcs ( const char *  s)

converts UTF8 to a local multi-byte character string.

Definition at line 477 of file fl_utf8.cxx.

References buf, fl_utf8toUtf16(), NULL, and xchar.

Referenced by fl_execvp(), and fl_system().

const char * fl_utf8back ( const char *  p,
const char *  start,
const char *  end 
)

Move p backward until it points to the start of a UTF-8 character. If it already points at the start of one then it is returned unchanged. Any UTF-8 errors are treated as though each byte of the error is an individual character.

start is the start of the string and is used to limit the backwards search for the start of a UTF-8 character.

end is the end of the string and is assumed to be a break between characters. It is assumed to be greater than p.

If you wish to decrement a UTF-8 pointer, pass p-1 to this.

Definition at line 263 of file fl_utf.c.

References fl_utf8decode().

int fl_utf8bytes ( unsigned  ucs)

Return the number of bytes needed to encode the given UCS4 character in UTF8.

Parameters:
[in]ucsUCS4 encoded character
Returns:
number of bytes required

Returns number of bytes that utf8encode() will use to encode the character ucs.

Definition at line 282 of file fl_utf.c.

unsigned fl_utf8decode ( const char *  p,
const char *  end,
int *  len 
)

Decode a single UTF-8 encoded character starting at p. The resulting Unicode value (in the range 0-0x10ffff) is returned, and len is set to the number of bytes in the UTF-8 encoding (adding len to p will point at the next character).

If p points at an illegal UTF-8 encoding, including one that would go past end, or where a code is uses more bytes than necessary, then *(unsigned char*)p is translated as though it is in the Microsoft CP1252 character set and len is set to 1. Treating errors this way allows this to decode almost any ISO-8859-1 or CP1252 text that has been mistakenly placed where UTF-8 is expected, and has proven very useful.

If you want errors to be converted to error characters (as the standards recommend), adding a test to see if the length is unexpectedly 1 will work:

    if (*p & 0x80) { // what should be a multibyte encoding
      code = fl_utf8decode(p,end,&len);
      if (len<2) code = 0xFFFD; // Turn errors into REPLACEMENT CHARACTER
    } else { // handle the 1-byte utf8 encoding:
      code = *p;
      len = 1;
    }

Direct testing for the 1-byte case (as shown above) will also speed up the scanning of strings where the majority of characters are ASCII.

Definition at line 140 of file fl_utf.c.

Referenced by Fl_Text_Buffer::char_at(), fl_utf8back(), fl_utf8fwd(), fl_utf8test(), fl_utf8toa(), fl_utf8toUtf16(), fl_utf8towc(), fl_utf_strncasecmp(), fl_utf_tolower(), fl_utf_toupper(), fl_wcwidth(), fl_width(), Fl_Input_::index(), Fl_Widget::label_shortcut(), Fl_PostScript_Graphics_Driver::rtl_draw(), Fl_Text_Buffer::search_backward(), Fl_Text_Buffer::search_forward(), Fl_Widget::test_shortcut(), Fl::test_shortcut(), and Fl_PostScript_Graphics_Driver::transformed_draw().

int fl_utf8encode ( unsigned  ucs,
char *  buf 
)

Write the UTF-8 encoding of ucs into buf and return the number of bytes written. Up to 4 bytes may be written. If you know that ucs is less than 0x10000 then at most 3 bytes will be written. If you wish to speed this up, remember that anything less than 0x80 is written as a single byte.

If ucs is greater than 0x10ffff this is an illegal character according to RFC 3629. These are converted as though they are 0xFFFD (REPLACEMENT CHARACTER).

RFC 3629 also says many other values for ucs are illegal (in the range 0xd800 to 0xdfff, or ending with 0xfffe or 0xffff). However I encode these as though they are legal, so that utf8encode/fl_utf8decode will be the identity for all codes between 0 and 0x10ffff.

Definition at line 312 of file fl_utf.c.

Referenced by carbonTextHandler(), fl_handle(), fl_shortcut_label(), fl_utf_tolower(), fl_utf_toupper(), and Fl_PostScript_Graphics_Driver::rtl_draw().

unsigned fl_utf8from_mb ( char *  dst,
unsigned  dstlen,
const char *  src,
unsigned  srclen 
)

Convert a filename from the locale-specific multibyte encoding used by Windows to UTF-8 as used by FLTK.

Up to dstlen bytes are written to dst, including a null terminator. The return value is the number of bytes that would be written, not counting the null terminator. If greater or equal to dstlen then if you malloc a new array of size n+1 you will have the space needed for the entire string. If dstlen is zero then nothing is written and this call just measures the storage space needed.

On Unix or on Windows when a UTF-8 locale is in effect, this does not change the data. You may also want to check if fl_utf8test() returns non-zero, so that the filesystem can store filenames in UTF-8 encoding regardless of the locale.

Definition at line 776 of file fl_utf.c.

References buf, fl_utf8fromwc(), fl_utf8locale(), and length.

Referenced by fl_filename_list().

unsigned fl_utf8froma ( char *  dst,
unsigned  dstlen,
const char *  src,
unsigned  srclen 
)

Convert an ISO-8859-1 (ie normal c-string) byte stream to UTF-8.

It is possible this should convert Microsoft's CP1252 to UTF-8 instead. This would translate the codes in the range 0x80-0x9f to different characters. Currently it does not do this.

Up to dstlen bytes are written to dst, including a null terminator. The return value is the number of bytes that would be written, not counting the null terminator. If greater or equal to dstlen then if you malloc a new array of size n+1 you will have the space needed for the entire string. If dstlen is zero then nothing is written and this call just measures the storage space needed.

srclen is the number of bytes in src to convert.

If the return value equals srclen then this indicates that no conversion is necessary, as only ASCII characters are in the string.

Definition at line 623 of file fl_utf.c.

unsigned fl_utf8fromwc ( char *  dst,
unsigned  dstlen,
const wchar_t *  src,
unsigned  srclen 
)

Turn "wide characters" as returned by some system calls (especially on Windows) into UTF-8.

Up to dstlen bytes are written to dst, including a null terminator. The return value is the number of bytes that would be written, not counting the null terminator. If greater or equal to dstlen then if you malloc a new array of size n+1 you will have the space needed for the entire string. If dstlen is zero then nothing is written and this call just measures the storage space needed.

srclen is the number of words in src to convert. On Windows this is not necessarily the number of characters, due to there possibly being "surrogate pairs" in the UTF-16 encoding used. On Unix wchar_t is 32 bits and each location is a character.

On Unix if a src word is greater than 0x10ffff then this is an illegal character according to RFC 3629. These are converted as though they are 0xFFFD (REPLACEMENT CHARACTER). Characters in the range 0xd800 to 0xdfff, or ending with 0xfffe or 0xffff are also illegal according to RFC 3629. However I encode these as though they are legal, so that fl_utf8towc will return the original data.

On Windows "surrogate pairs" are converted to a single character and UTF-8 encoded (as 4 bytes). Mismatched halves of surrogate pairs are converted as though they are individual characters.

Definition at line 535 of file fl_utf.c.

References i.

Referenced by fl_getcwd(), fl_getenv(), fl_scandir(), and fl_utf8from_mb().

const char * fl_utf8fwd ( const char *  p,
const char *  start,
const char *  end 
)

Move p forward until it points to the start of a UTF-8 character. If it already points at the start of one then it is returned unchanged. Any UTF-8 errors are treated as though each byte of the error is an individual character.

start is the start of the string and is used to limit the backwards search for the start of a utf8 character.

end is the end of the string and is assumed to be a break between characters. It is assumed to be greater than p.

This function is for moving a pointer that was jumped to the middle of a string, such as when doing a binary search for a position. You should use either this or fl_utf8back() depending on which direction your algorithim can handle the pointer moving. Do not use this to scan strings, use fl_utf8decode() instead.

Definition at line 232 of file fl_utf.c.

References fl_utf8decode().

int fl_utf8len ( char  c)

return the byte length of the UTF-8 sequence with first byte c, or -1 if c is not valid. This function is helpful for finding faulty UTF8 sequences.

See also:
fl_utf8len1

Definition at line 120 of file fl_utf8.cxx.

Referenced by fl_utf_nb_char(), fl_wcwidth(), Fl_Input_::handle_mouse(), Fl_Input_::position(), and Fl_Input_::replace().

int fl_utf8len1 ( char  c)

Return the byte length of the UTF-8 sequence with first byte c, or 1 if c is not valid. This function can be used to scan faulty UTF8 sequence, albeit ignoring invalid codes.

See also:
fl_utf8len

Definition at line 149 of file fl_utf8.cxx.

Referenced by Fl_Text_Display::find_x(), Fl_Text_Display::handle_vline(), Fl_Text_Display::measure_proportional_character(), Fl_Text_Buffer::next_char(), Fl_Text_Display::overstrike(), Fl_Text_Buffer::search_backward(), and Fl_Text_Buffer::search_forward().

int fl_utf8locale ( void  )

Return true if the "locale" seems to indicate that UTF-8 encoding is used. If true the fl_utf8to_mb and fl_utf8from_mb don't do anything useful.

It is highly recommended that you change your system so this does return true. On Windows this is done by setting the "codepage" to CP_UTF8. On Unix this is done by setting $LC_CTYPE to a string containing the letters "utf" or "UTF" in it, or by deleting all $LC* and $LANG environment variables. In the future it is likely that all non-Asian Unix systems will return true, due to the compatibility of UTF-8 with ISO-8859-1.

Definition at line 669 of file fl_utf.c.

Referenced by fl_utf8from_mb(), and fl_utf8to_mb().

int fl_utf8test ( const char *  src,
unsigned  srclen 
)

Examines the first srclen bytes in src and returns a verdict on whether it is UTF-8 or not.

  • Returns 0 if there is any illegal UTF-8 sequences, using the same rules as fl_utf8decode(). Note that some UCS values considered illegal by RFC 3629, such as 0xffff, are considered legal by this.
  • Returns 1 if there are only single-byte characters (ie no bytes have the high bit set). This is legal UTF-8, but also indicates plain ASCII. It also returns 1 if srclen is zero.
  • Returns 2 if there are only characters less than 0x800.
  • Returns 3 if there are only characters less than 0x10000.
  • Returns 4 if there are characters in the 0x10000 to 0x10ffff range.

Because there are many illegal sequences in UTF-8, it is almost impossible for a string in another encoding to be confused with UTF-8. This is very useful for transitioning Unix to UTF-8 filenames, you can simply test each filename with this to decide if it is UTF-8 or in the locale encoding. My hope is that if this is done we will be able to cleanly transition to a locale-less encoding.

Definition at line 843 of file fl_utf.c.

References fl_utf8decode().

unsigned fl_utf8to_mb ( const char *  src,
unsigned  srclen,
char *  dst,
unsigned  dstlen 
)

Convert the UTF-8 used by FLTK to the locale-specific encoding used for filenames (and sometimes used for data in files). Unfortunately due to stupid design you will have to do this as needed for filenames. This is a bug on both Unix and Windows.

Up to dstlen bytes are written to dst, including a null terminator. The return value is the number of bytes that would be written, not counting the null terminator. If greater or equal to dstlen then if you malloc a new array of size n+1 you will have the space needed for the entire string. If dstlen is zero then nothing is written and this call just measures the storage space needed.

If fl_utf8locale() returns true then this does not change the data.

Definition at line 702 of file fl_utf.c.

References buf, fl_utf8locale(), fl_utf8towc(), and length.

Referenced by fl_filename_list().

unsigned fl_utf8toa ( const char *  src,
unsigned  srclen,
char *  dst,
unsigned  dstlen 
)

Convert a UTF-8 sequence into an array of 1-byte characters.

If the UTF-8 decodes to a character greater than 0xff then it is replaced with '?'.

Errors in the UTF-8 are converted as individual bytes, same as fl_utf8decode() does. This allows ISO-8859-1 text mistakenly identified as UTF-8 to be printed correctly (and possibly CP1512 on Windows).

src points at the UTF-8, and srclen is the number of bytes to convert.

Up to dstlen bytes are written to dst, including a null terminator. The return value is the number of bytes that would be written, not counting the null terminator. If greater or equal to dstlen then if you malloc a new array of size n+1 you will have the space needed for the entire string. If dstlen is zero then nothing is written and this call just measures the storage space needed.

Definition at line 474 of file fl_utf.c.

References fl_utf8decode().

unsigned fl_utf8toUtf16 ( const char *  src,
unsigned  srclen,
unsigned short *  dst,
unsigned  dstlen 
)

Convert a UTF-8 sequence into an array of wchar_t. These are used by some system calls, especially on Windows.

src points at the UTF-8, and srclen is the number of bytes to convert.

dst points at an array to write, and dstlen is the number of locations in this array. At most dstlen-1 words will be written there, plus a 0 terminating word. Thus this function will never overwrite the buffer and will always return a zero-terminated string. If dstlen is zero then dst can be null and no data is written, but the length is returned.

The return value is the number of words that would be written to dst if it were long enough, not counting the terminating zero. If the return value is greater or equal to dstlen it indicates truncation, you can then allocate a new array of size return+1 and call this again.

Errors in the UTF-8 are converted as though each byte in the erroneous string is in the Microsoft CP1252 encoding. This allows ISO-8859-1 text mistakenly identified as UTF-8 to be printed correctly.

Notice that sizeof(wchar_t) is 2 on Windows and is 4 on Linux and most other systems. Where wchar_t is 16 bits, Unicode characters in the range 0x10000 to 0x10ffff are converted to "surrogate pairs" which take two words each (this is called UTF-16 encoding). If wchar_t is 32 bits this rather nasty problem is avoided.

Definition at line 371 of file fl_utf.c.

References fl_utf8decode().

Referenced by fl_access(), fl_chmod(), fl_execvp(), fl_fopen(), fl_getenv(), fl_mkdir(), fl_open(), fl_rename(), fl_rmdir(), fl_scandir(), fl_stat(), fl_system(), fl_text_extents(), fl_unlink(), fl_utf2mbcs(), fl_utf8towc(), and FLDataObject::GetData().

unsigned fl_utf8towc ( const char *  src,
unsigned  srclen,
wchar_t *  dst,
unsigned  dstlen 
)

Converts a UTF-8 string into a wide character string.

This function generates 32-bit wchar_t (e.g. "ucs4" as it were) except on Windows where it returns UTF-16 with surrogate pairs where required.

Note that Windows includes Cygwin, i.e. compiled with Cygwin's POSIX layer (cygwin1.dll, --enable-cygwin), either native (GDI) or X11.

Definition at line 418 of file fl_utf.c.

References fl_utf8decode(), and fl_utf8toUtf16().

Referenced by fl_utf8to_mb().

int fl_utf_nb_char ( const unsigned char *  buf,
int  len 
)

returns the number of Unicode chars in the UTF-8 string

Definition at line 175 of file fl_utf8.cxx.

References fl_utf8len(), and i.

Referenced by fl_expand_text(), and menuwindow::menuwindow().

int fl_utf_strcasecmp ( const char *  s1,
const char *  s2 
)

UTF-8 aware strcasecmp - converts to Unicode and tests.

Todo:
Correct the incorrect logic where length of strings tested

Definition at line 252 of file fl_utf8.cxx.

References fl_utf_strncasecmp().

int fl_utf_strncasecmp ( const char *  s1,
const char *  s2,
int  n 
)

UTF-8 aware strncasecmp - converts to lower case Unicode and tests.

Todo:

Correct the incorrect logic where length of strings tested

Clarify whether n means number of bytes, or characters.

Definition at line 202 of file fl_utf8.cxx.

References fl_utf8decode(), i, and XUtf8Tolower().

Referenced by fl_utf_strcasecmp().

int fl_utf_tolower ( const unsigned char *  str,
int  len,
char *  buf 
)

converts the str string to the lower case equivalent into buf. Warning: to be safe buf length must be at least 3 * len [for 16-bit Unicode]

Definition at line 285 of file fl_utf8.cxx.

References fl_utf8decode(), fl_utf8encode(), i, and XUtf8Tolower().

int fl_utf_toupper ( const unsigned char *  str,
int  len,
char *  buf 
)

converts the str string to the upper case equivalent into buf. Warning: to be safe buf length must be at least 3 * len [for 16-bit Unicode]

Definition at line 316 of file fl_utf8.cxx.

References fl_utf8decode(), fl_utf8encode(), and i.

int fl_wcwidth ( const char *  src)

extended wrapper around fl_wcwidth_(unsigned int ucs) function.

Parameters:
[in]srcpointer to start of UTF-8 byte sequence
Returns:
width of character in columns

Depending on build options, this function may map C1 control characters (0x80 to 0x9f) to CP1252, and return the width of that character instead. This is not the same behaviour as fl_wcwidth_(unsigned int ucs) .

Note that other control characters and DEL will still return -1, so if you want different behaviour, you need to test for those characters before calling fl_wcwidth(), and handle them separately.

Definition at line 898 of file fl_utf.c.

References fl_utf8decode(), fl_utf8len(), fl_wcwidth_(), and width.

int fl_wcwidth_ ( unsigned int  ucs)

wrapper to adapt Markus Kuhn's implementation of wcwidth() for FLTK

Parameters:
[in]ucsUnicode character value
Returns:
width of character in columns

See http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c for Markus Kuhn's original implementation of wcwidth() and wcswidth() (defined in IEEE Std 1002.1-2001) for Unicode.

WARNING: this function returns widths for "raw" Unicode characters. It does not even try to map C1 control characters (0x80 to 0x9F) to CP1252, and C0/C1 control characters and DEL will return -1. You are advised to use fl_width(const char* src) instead.

Definition at line 881 of file fl_utf.c.

References mk_wcwidth().

Referenced by fl_wcwidth().