aboutsummaryrefslogtreecommitdiff
path: root/include/str.h
blob: 85051e4001fca381daadd1a25a7baa5d7c07d036 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

typedef byte* string;

typedef struct str·Hdr
{
    vlong len;
    vlong cap;
    byte  buf[];
} str·Hdr;

// -------------------------------------------------------------------------
// UTF-8 functions.
// Perhaps break into own unit
// TODO: Add to(upper|lower|title)

typedef uint32 Rune;

enum
{
    UTFmax    = 4,
    RuneSync  = 0x80,
    RuneSelf  = 0x80,
    RuneErr   = 0xFFFD,
    RuneMax   = 0x10FFFF,
};

int     utf8·fullRune(byte *s, int n);
byte   *utf8·findRune(byte *s, long i);
int     utf8·charToRune(Rune *r, byte *s);
int     utf8·runeToChar(byte *s, Rune *r);
int     utf8·len(byte *s);
int     utf8·runeLen(Rune r);
int     utf8·isLetter(Rune r);
int     utf8·isDigit(Rune r);
int     utf8·isSpace(Rune r);
int     utf8·isTitle(Rune r);

// -------------------------------------------------------------------------
// Dynamic string functions

string  str·newCap(const byte *s, vlong len, vlong cap);
string  str·newLen(const byte *s, vlong len);
string  str·new(const byte *s);
string  str·newf(const byte *fmt, ...);
void    str·free(string s);
int     str·len(const string s);
int     str·cap(const string s);
string  str·clear(string s);
string  str·grow(string s, vlong delta);
string  str·fit(string s);
string  str·appendCount(string s, vlong len, const byte *b);
string  str·append(string s, const byte* b);
string  str·appendf(string s, const byte* fmt, ...);
string  str·appendByte(string s, const byte b);
bool    str·equals(const string s, const string t);
int     str·find(string s, const byte* substr);
void    str·lower(string s);
void    str·upper(string s);
void    str·replace(string s, const byte* from, const byte* to);
string* str·split(string s, const byte* tok);
string  str·join(vlong len, byte** fields, const byte* sep);