Skip to content

Commit

Permalink
std/lib/core: rename DString.str to DString.as_str (#834)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Curto <[email protected]>
  • Loading branch information
pierrec authored Jul 7, 2023
1 parent 8780df8 commit d709c18
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/std/core/builtin.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/std/core/dstring.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/std/core/string.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/std/encoding/json.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};
Expand All @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/std/io/io.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/std/io/io_printf.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lib/std/os/subprocess.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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())!!;
}

/**
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions resources/examples/contextfree/boolerr.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resources/examples/plus_minus.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/test_suite/stdlib/map.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/stdlib/io/dstringstream.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit d709c18

Please sign in to comment.