From d709c18f5f837820557f28a4dab9a83f2a727fe2 Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Sat, 8 Jul 2023 00:10:04 +0200 Subject: [PATCH] std/lib/core: rename DString.str to DString.as_str (#834) Signed-off-by: Pierre Curto --- lib/std/core/builtin.c3 | 2 +- lib/std/core/dstring.c3 | 6 +++--- lib/std/core/string.c3 | 2 +- lib/std/encoding/json.c3 | 8 ++++---- lib/std/io/io.c3 | 4 ++-- lib/std/io/io_printf.c3 | 2 +- lib/std/os/subprocess.c3 | 4 ++-- resources/examples/contextfree/boolerr.c3 | 4 ++-- resources/examples/plus_minus.c3 | 2 +- test/test_suite/stdlib/map.c3t | 4 ++-- test/unit/stdlib/io/dstringstream.c3 | 2 +- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 9ebef4e77..39e2d2b44 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -113,7 +113,7 @@ fn void panicf(String fmt, String file, String function, uint line, args...) DString s; s.init(.using = mem); s.printf(fmt, ...args); - panic(s.str(), file, function, line); + panic(s.as_str(), file, function, line); }; } diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index b989006a1..50a747449 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -93,7 +93,7 @@ fn void DString.chop(self, usz new_size) self.data().len = new_size; } -fn String DString.str(self) +fn String DString.as_str(self) { StringData* data = (StringData*)self; if (!data) return ""; @@ -261,14 +261,14 @@ fn void DString.append_chars(&self, String str) fn Char32[] DString.copy_utf32(&self, Allocator* using = mem::heap()) { - return self.str().to_utf32(using) @inline!!; + return self.as_str().to_utf32(using) @inline!!; } fn void DString.append_string(&self, DString str) { StringData* other = (StringData*)str; if (!other) return; - self.append(str.str()); + self.append(str.as_str()); } fn void DString.clear(self) diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 2fd017e41..a7c91a0e3 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -46,7 +46,7 @@ macro String tprintf(String fmt, ...) DString str; str.tinit(); str.printf(fmt, $vasplat()); - return str.str(); + return str.as_str(); } macro bool char_in_set(char c, String set) diff --git a/lib/std/encoding/json.c3 b/lib/std/encoding/json.c3 index 3f1cfe357..2a2bb4d56 100644 --- a/lib/std/encoding/json.c3 +++ b/lib/std/encoding/json.c3 @@ -62,7 +62,7 @@ fn Object*! JsonParser.parse_from_token(&self, JsonTokenType token) case RBRACE: case RBRACKET: case COLON: return JsonParsingError.UNEXPECTED_CHARACTER?; - case STRING: return object::new_string(self.last_string.str(), self.allocator); + case STRING: return object::new_string(self.last_string.as_str(), self.allocator); case NUMBER: return object::new_float(self.last_number, self.allocator); case TRUE: return object::new_bool(true); case FALSE: return object::new_bool(false); @@ -119,7 +119,7 @@ fn JsonTokenType! JsonParser.lex_number(&self, char c) } } self.pushback(); - double! d = t.str().to_double() ?? JsonParsingError.INVALID_NUMBER?; + double! d = t.as_str().to_double() ?? JsonParsingError.INVALID_NUMBER?; self.last_number = d!; return NUMBER; }; @@ -137,14 +137,14 @@ fn Object*! JsonParser.parse_map(&self) { if (token != JsonTokenType.STRING) return JsonParsingError.UNEXPECTED_CHARACTER?; DString string = self.last_string; - if (map.has_key(string.str())) return JsonParsingError.DUPLICATE_MEMBERS?; + if (map.has_key(string.as_str())) return JsonParsingError.DUPLICATE_MEMBERS?; // Copy the key to our temp holder. We do this to work around the issue // if the temp allocator should be used as the default allocator. temp_key.clear(); temp_key.append(string); self.parse_expected(COLON)!; Object* element = self.parse_any()!; - map.set(temp_key.str(), element); + map.set(temp_key.as_str(), element); token = self.advance()!; if (token == JsonTokenType.COMMA) { diff --git a/lib/std/io/io.c3 b/lib/std/io/io.c3 index ee3be5334..22f0295be 100644 --- a/lib/std/io/io.c3 +++ b/lib/std/io/io.c3 @@ -58,7 +58,7 @@ macro void print(x) $case ZString: (void)stdout().print(x.as_str()); $case DString: - (void)stdout().print(x.str()); + (void)stdout().print(x.as_str()); $default: $if @convertible(x, String): (void)stdout().print((String)x); @@ -77,7 +77,7 @@ macro void printn(x = "") $case ZString: (void)stdout().printn(x.as_str()); $case DString: - (void)stdout().printn(x.str()); + (void)stdout().printn(x.as_str()); $default: $if @convertible(x, String): (void)stdout().printn((String)x); diff --git a/lib/std/io/io_printf.c3 b/lib/std/io/io_printf.c3 index b211ebeff..7c5311a16 100644 --- a/lib/std/io/io_printf.c3 +++ b/lib/std/io/io_printf.c3 @@ -179,7 +179,7 @@ fn void! Formatter.out_str(&self, any arg) @private if (self.print_with_function(arg)!) return; if (arg.type == DString.typeid) { - return self.out_substr(((DString*)arg).str()); + return self.out_substr(((DString*)arg).as_str()); } return self.out_str(any { arg.ptr, arg.type.inner }); case POINTER: diff --git a/lib/std/os/subprocess.c3 b/lib/std/os/subprocess.c3 index 376b529ce..d7d8a200d 100644 --- a/lib/std/os/subprocess.c3 +++ b/lib/std/os/subprocess.c3 @@ -113,7 +113,7 @@ fn Char16* convert_command_line_win32(String[] command_line) @inline @if(env::WI str.append('"'); } str.append('\0'); - return str.str().to_utf16(.using = mem::temp())!!; + return str.as_str().to_utf16(.using = mem::temp())!!; } /** @@ -154,7 +154,7 @@ fn SubProcess! create(String[] command_line, SubProcessOptions options = {}, Str env.append("\0"); } env.append("\0"); - used_environment = env.str().to_utf16(.using = mem::temp()).ptr!; + used_environment = env.as_str().to_utf16(.using = mem::temp()).ptr!; } int fd = win32::_open_osfhandle((iptr)wr, 0); if (fd != -1) diff --git a/resources/examples/contextfree/boolerr.c3 b/resources/examples/contextfree/boolerr.c3 index 81fb8a594..ef822f569 100644 --- a/resources/examples/contextfree/boolerr.c3 +++ b/resources/examples/contextfree/boolerr.c3 @@ -21,7 +21,7 @@ struct StringData @private fn void Summary.print(Summary *s, File out) { - String title = s.title ? s.title.str() : "missing"; + String title = s.title ? s.title.as_str() : "missing"; out.printf("Summary({ .title = %s, .ok = %s})", title, s.ok); } @@ -128,7 +128,7 @@ fn void main() io::printf(" Summary: "); summary.print(io::stdout()); io::printn(""); - String title_sure = summary.title ? summary.title.str() : ""; + String title_sure = summary.title ? summary.title.as_str() : ""; io::printf(" Title: %s\n", title_sure); bool! has_title = readWhetherTitleNonEmpty(url); // This looks a bit less than elegant, but as you see it's mostly due to having to diff --git a/resources/examples/plus_minus.c3 b/resources/examples/plus_minus.c3 index 2a75e23a3..464e50312 100644 --- a/resources/examples/plus_minus.c3 +++ b/resources/examples/plus_minus.c3 @@ -18,7 +18,7 @@ fn void main(String[] args) defer s.free(); // Grab the string as a slice. - String numbers = s.str(); + String numbers = s.as_str(); // Track our current value int val = 0; diff --git a/test/test_suite/stdlib/map.c3t b/test/test_suite/stdlib/map.c3t index 909678a1b..6aab66915 100644 --- a/test/test_suite/stdlib/map.c3t +++ b/test/test_suite/stdlib/map.c3t @@ -13,7 +13,7 @@ fn String Foo.to_string(Foo* foo, Allocator* allocator = mem::heap()) @dynamic { DString s = dstring::new_with_capacity(128, allocator); s.printf("{%s, %p}", foo.x, foo.bar); - return s.str(); + return s.as_str(); } @@ -74,7 +74,7 @@ entry: store %any %9, ptr %10, align 16 %11 = call i64 @std.core.dstring.DString.printf(ptr %retparam, ptr %s, ptr @.str.12, i64 8, ptr %varargslots, i64 2) %12 = load ptr, ptr %s, align 8 - %13 = call { ptr, i64 } @std.core.dstring.DString.str(ptr %12) + %13 = call { ptr, i64 } @std.core.dstring.DString.as_str(ptr %12) store { ptr, i64 } %13, ptr %result, align 8 %14 = load { ptr, i64 }, ptr %result, align 8 ret { ptr, i64 } %14 diff --git a/test/unit/stdlib/io/dstringstream.c3 b/test/unit/stdlib/io/dstringstream.c3 index e42df587f..16646dc47 100644 --- a/test/unit/stdlib/io/dstringstream.c3 +++ b/test/unit/stdlib/io/dstringstream.c3 @@ -12,6 +12,6 @@ fn void! test_writing() String test_str = "2134"; r.init(test_str); s.read_from(r.as_stream())!; - String o = foo.str(); + String o = foo.as_str(); assert(o == "hello-what?2134"); }