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 --- sys/libn/io.c | 6 ++++++ sys/libn/string.c | 40 ++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'sys') 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