mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
std/lib/core: rename DString.str to DString.as_str (#834)
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user