From e596ebd0c129913b7135210b23a50336b6f8556f Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 21 Apr 2020 19:18:40 -0700 Subject: chore: updating naming conventions --- .gitignore | 1 + include/.include/str.h | 26 +++++++++++++------------- include/libn.h | 1 + sys/libn/io.c | 6 ++++++ sys/libn/string.c | 40 ++++++++++++++++++++-------------------- 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 90ea2fd..470c533 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ lib/ dep/ build/ +data/ vendor/ sys/cc sys/nixos diff --git a/include/.include/str.h b/include/.include/str.h index 85051e4..29b5e1e 100644 --- a/include/.include/str.h +++ b/include/.include/str.h @@ -25,22 +25,22 @@ enum 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·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); +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·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); @@ -49,10 +49,10 @@ 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·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); +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); diff --git a/include/libn.h b/include/libn.h index 0fbcdc7..203a477 100644 --- a/include/libn.h +++ b/include/libn.h @@ -98,6 +98,7 @@ enum SeekPos Stream *io·open(byte *name, byte *mode); error io·close(Stream *s); byte io·getbyte(Stream *s); +error io·ungetbyte(Stream *s, byte c); vlong io·read(Stream *s, int sz, int n, void *buf); int io·readln(Stream *s, int n, byte* buf); error io·putbyte(Stream *s, byte c); diff --git a/sys/libn/io.c b/sys/libn/io.c index 789bc7b..922dec3 100644 --- a/sys/libn/io.c +++ b/sys/libn/io.c @@ -25,6 +25,12 @@ io·getbyte(Stream *s) return fgetc(s); } +error +io·ungetbyte(Stream *s, byte c) +{ + return ungetc(c, s); +} + vlong io·read(Stream *s, int sz, int n, void *buf) { diff --git a/sys/libn/string.c b/sys/libn/string.c index f084623..9bcef90 100644 --- a/sys/libn/string.c +++ b/sys/libn/string.c @@ -27,7 +27,7 @@ enum }; int -utf8·charToRune(Rune* r, byte* s) +utf8·chartorune(Rune* r, byte* s) { int c[UTFmax], i; Rune l; @@ -65,7 +65,7 @@ bad: } int -utf8·runeToChar(byte* s, Rune* r) +utf8·runetochar(byte* s, Rune* r) { int i, j; Rune c; @@ -95,14 +95,14 @@ utf8·runeToChar(byte* s, Rune* r) } int -utf8·runeLen(Rune r) +utf8·runelen(Rune r) { byte s[10]; - return utf8·runeToChar(s, &r); + return utf8·runetochar(s, &r); } int -utf8·fullRune(byte* s, int n) +utf8·fullrune(byte* s, int n) { int i; Rune c; @@ -119,7 +119,7 @@ utf8·fullRune(byte* s, int n) } byte* -utf8·findRune(byte* s, long c) +utf8·findrune(byte* s, long c) { long c1; Rune r; @@ -135,7 +135,7 @@ utf8·findRune(byte* s, long c) s++; continue; } - n = utf8·charToRune(&r, s); + n = utf8·chartorune(&r, s); if (r == c) return s; s += n; } @@ -156,7 +156,7 @@ utf8·findRune(byte* s, long c) // len defines the length of the C substring that we will copy into our buffer. // The backing buffer will have capacity cap. string -str·newCap(const byte* s, vlong len, vlong cap) +str·newcap(const byte* s, vlong len, vlong cap) { struct str·Hdr* h; @@ -185,13 +185,13 @@ cleanup: // New returns a new dynamic string object, initialized from the given C string. // The backing buffer capacity is equivalent to the string length. string -str·newLen(const byte* s, vlong len) +str·newlen(const byte* s, vlong len) { vlong sl = (s == nil) ? 0 : strlen(s); if (sl < len) panicf("attempted to take a bigger substring than string length"); vlong cap = (len == 0) ? 1 : len; - return str·newCap(s, len, cap); + return str·newcap(s, len, cap); } // New returns a new dynamic string object, initialized from the given C string. @@ -200,7 +200,7 @@ string str·new(const byte* s) { vlong len = (s == nil) ? 0 : strlen(s); - return str·newLen(s, len); + return str·newlen(s, len); } // Newf returns a new dynamic string object @@ -212,7 +212,7 @@ str·newf(const byte* fmt, ...) vlong n = vsnprintf(nil, 0, fmt, args); va_end(args); - string s = str·newCap(nil, 0, n); + string s = str·newcap(nil, 0, n); va_start(args, fmt); vsnprintf(s, n + 1, fmt, args); @@ -313,7 +313,7 @@ str·fit(string s) // string to our buffer. The result is reallocated if not enough room is present // in the buffer. string -str·appendCount(string s, vlong n, const byte* b) +str·appendcount(string s, vlong n, const byte* b) { vlong bl = strlen(b); if (n > bl) panicf("attempted to make a substring longer than string"); @@ -335,14 +335,14 @@ str·appendCount(string s, vlong n, const byte* b) string str·append(string s, const byte* b) { - return str·appendCount(s, strlen(b), b); + return str·appendcount(s, strlen(b), b); } // AppendByte will append the given byte to our string. // NOTE: As the byte is on the stack, it is not null-terminated. // Can not pass to the above functions. string -str·appendByte(string s, const byte b) +str·appendbyte(string s, const byte b) { s = str·grow(s, 1); if (s == nil) return nil; @@ -412,7 +412,7 @@ str·find(string s, const byte* substr) // // Lower will force all runes in the string to be lowercase. void -str·Lower(string s) +str·lower(string s) { byte *b, *e; b = s; @@ -473,7 +473,7 @@ str·split(string s, const byte* tok) for (vlong i = 0; i < sL - tokL; i++) { if ((tokL == 1 && s[i] == tokL) || !memcmp(s + i, tok, tokL)) { - bufpush(fields, str·newLen(s + start, i - start)); + bufpush(fields, str·newlen(s + start, i - start)); if (fields[buflen(fields) - 1] == nil) goto cleanup; start = i + tokL; @@ -481,7 +481,7 @@ str·split(string s, const byte* tok) } } - bufpush(fields, str·newLen(s + start, sL - start)); + bufpush(fields, str·newlen(s + start, sL - start)); return fields; @@ -496,12 +496,12 @@ cleanup: string str·join(vlong len, byte** fields, const byte* sep) { - string s = str·newCap(nil, 0, 10); + string s = str·newcap(nil, 0, 10); int j = 0; for (j = 0; j < len; j++) { s = str·append(s, fields[j]); - if (j < len - 1) { s = str·appendCount(s, 1, sep); } + if (j < len - 1) { s = str·appendcount(s, 1, sep); } } return s; -- cgit v1.2.1