stage2 更多的工具库
This commit is contained in:
1 parent
4141e7d574
commit
16a1f030d4
15 files changed
+1914
-109
No files matched your search
@@ -19,7 +19,7 @@ fn append_u64(out: *ByteBuffer, value: u64, radix: u8, uppercase: bool): Status
|
||||
var count: usize = 0;
|
||||
|
||||
if value == 0 {
|
||||
digits[0] = 48;
|
||||
digits[0] = '0';
|
||||
count = 1;
|
||||
} else {
|
||||
var v = value;
|
||||
@@ -50,7 +50,7 @@ fn append_u64(out: *ByteBuffer, value: u64, radix: u8, uppercase: bool): Status
|
||||
fn append_i64(out: *ByteBuffer, value: i64, radix: u8, uppercase: bool): Status {
|
||||
if !valid_radix(radix) { ret .Err(make(.InvalidArgument)); }
|
||||
if value < 0 {
|
||||
match ByteBuffer.append_byte(out, 45) { // '-'
|
||||
match ByteBuffer.append_byte(out, '-') {
|
||||
.Ok => {},
|
||||
.Err(error) => { ret .Err(error); },
|
||||
}
|
||||
@@ -221,14 +221,14 @@ fn test_composition_and_growth() {
|
||||
var i: i32 = 0;
|
||||
while i < 200 {
|
||||
expect_ok(append_i64(&b, i as i64, 10, false));
|
||||
expect_ok(ByteBuffer.append_byte(&b, 44)); // ','
|
||||
expect_ok(ByteBuffer.append_byte(&b, ',')); // ','
|
||||
i = i + 1;
|
||||
}
|
||||
expect_ok(append_i64(&b, 200, 10, false));
|
||||
@assert(ByteBuffer.size(b) > 0, "growth content");
|
||||
var s = ByteBuffer.as_slice(b);
|
||||
@assert(s.ptr[0] == 48, "starts with 0");
|
||||
@assert(s.ptr[1] == 44, "0 then comma");
|
||||
@assert(s.ptr[0] == '0', "starts with 0");
|
||||
@assert(s.ptr[1] == ',', "0 then comma");
|
||||
|
||||
ByteBuffer.drop(&b);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user