From 65264ba6d1f7e7402009f33b60e3263bf1f02498 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 17 Apr 2020 18:04:04 -0700 Subject: init: prototype of code skeleton --- include/str.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 include/str.h (limited to 'include/str.h') diff --git a/include/str.h b/include/str.h new file mode 100644 index 0000000..c728bf0 --- /dev/null +++ b/include/str.h @@ -0,0 +1,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, const byte* b, vlong len); +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(byte** fields, vlong numFields, const byte* sep); -- cgit v1.2.1