aboutsummaryrefslogtreecommitdiff
path: root/include/libutf.h
blob: 25d6deeb1067f950ae9955c5979d13cba4f73608 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

typedef uint32 rune;

#define UTFmax   4
#define RuneErr  0xFFFDu
#define RuneMax  0x10FFFFu

#define utf8·onebyte(c)       (((c)&0x80u)==0x00u)
#define utf8·twobyte(c)       (((c)&0xE0u)==0xC0u)
#define utf8·threebyte(c)     (((c)&0xF0u)==0xE0u)
#define utf8·fourbyte(c)      (((c)&0xF8u)==0xF0u)

/*
 * UTF-8 functions.
 */
int     utf8·len(char *s);       // returns number of runes for s
int     utf8·runelen(rune r);    // returns number of bytes for rune
int     utf8·runewidth(rune r);  // returns number of printed columns for rune

int     utf8·decode(char *, rune *);       // decode 1 rune from char stream, store into rune, return number of bytes
int     utf8·encode(rune *, char *);       // encode 1 rune from rune stream, store into char, return number of bytes
int     utf8·decodeprev(char *s, rune *r); // decode 1 rune from char stream, reading backwards, store into rune, return number of bytes

char   *utf8·find(char *s, rune);     // find rune in char stream
char   *utf8·findlast(char* s, rune); // find last rune in char stream

int     utf8·canfit(char *, int); // XXX: odd function...

int     utf8·isalpha(rune r);
int     utf8·isdigit(rune r);
int     utf8·isspace(rune r);
int     utf8·istitle(rune r);
int     utf8·ispunct(rune r);

rune    utf8·toupper(rune r);
rune    utf8·tolower(rune r);
rune    utf8·totitle(rune r);