Program Listing for File utf.h

Return to documentation for file (src/lovejoy/utf.h)

#include "common.h"
#include <string.h>

#pragma once

#define is_utf(c) (((c) & 0xC0) != 0x80)

static inline
string to_string(const byte *c)
    { return ((string){ .len = strlen(c), .value = (byte *)c }); }

/* Conversions. */

runic utf8_to_ucs4(runic dest, string src);

string ucs4_to_utf8(string dest, runic src);

string rune_to_utf8(string dest, rune ch);

/* Moving through stirngs. */

usize byte_offset(string, usize);

usize char_num(string, usize);

rune read_rune(string s, usize *i);

u0 next_rune(string, usize *);

u0 prev_rune(string, usize *);

/* Unicode Escapes. */

usize read_escape(string src, rune *dest);

string escape_rune(string dest, rune ch);

string utf8_unescape(string dest, string src);

string utf8_escape(string dest, string src, bool escape_quotes);

/* UTF-8 oriented standard function replacements. */

string utf_strchr(string s, rune ch, usize *i);

usize utf_strlen(string s);

usize utf_seqlen(string);

bool is_locale_utf8(byte *locale);

/* Utility. */
bool octal_digit(byte c);
bool hex_digit(byte c);