From ec21325b36adc7f52179ea010ff7bb19d121a6c1 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 26 Apr 2020 17:36:49 -0700 Subject: chore: moved string into main libn header --- include/.include/str.h | 62 -------------------------------------------------- include/libn.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 63 deletions(-) delete mode 100644 include/.include/str.h (limited to 'include') diff --git a/include/.include/str.h b/include/.include/str.h deleted file mode 100644 index 29b5e1e..0000000 --- a/include/.include/str.h +++ /dev/null @@ -1,62 +0,0 @@ -#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); diff --git a/include/libn.h b/include/libn.h index 66eabaf..b994159 100644 --- a/include/libn.h +++ b/include/libn.h @@ -106,7 +106,65 @@ error coro·free(Coro *c); // Strings // TODO(nnoll): Move here? -#include ".include/str.h" +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, +}; + +/* utf8 helpers */ +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); + +/* string helpers */ +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); // ----------------------------------------------------------------------------- // I/O -- cgit v1.2.1