| author | |
| committer | |
| log | 051ee8e626111445c27d6c868cb0cdec6df7409e |
| tree | d144242d665fb7eff76dc3e561989146c84690a1 |
| parent | b483db486842c6d7d348b28ca09e56673e1bd800 |
See #35940 files changed, 164 insertions(+), 158 deletions(-)
doc/langref.md+1-1| ... | ... | @@ -133,7 +133,7 @@ FnCallExpression = "(" list(Expression, ",") ")" |
| 133 | 133 | |
| 134 | 134 | ArrayAccessExpression = "[" Expression "]" |
| 135 | 135 | |
| 136 | SliceExpression = "[" Expression "..." option(Expression) "]" | |
| 136 | SliceExpression = "[" Expression ".." option(Expression) "]" | |
| 137 | 137 | |
| 138 | 138 | ContainerInitExpression = "{" ContainerInitBody "}" |
| 139 | 139 |
example/cat/main.zig+2-2| ... | ... | @@ -40,7 +40,7 @@ fn cat_stream(is: &io.InStream) -> %void { |
| 40 | 40 | var buf: [1024 * 4]u8 = undefined; |
| 41 | 41 | |
| 42 | 42 | while (true) { |
| 43 | const bytes_read = is.read(buf[0...]) %% |err| { | |
| 43 | const bytes_read = is.read(buf[0..]) %% |err| { | |
| 44 | 44 | %%io.stderr.printf("Unable to read from stream: {}\n", @errorName(err)); |
| 45 | 45 | return err; |
| 46 | 46 | }; |
| ... | ... | @@ -49,7 +49,7 @@ fn cat_stream(is: &io.InStream) -> %void { |
| 49 | 49 | break; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | io.stdout.write(buf[0...bytes_read]) %% |err| { | |
| 52 | io.stdout.write(buf[0..bytes_read]) %% |err| { | |
| 53 | 53 | %%io.stderr.printf("Unable to write to stdout: {}\n", @errorName(err)); |
| 54 | 54 | return err; |
| 55 | 55 | }; |
example/guess_number/main.zig+3-3| ... | ... | @@ -8,7 +8,7 @@ pub fn main() -> %void { |
| 8 | 8 | %%io.stdout.printf("Welcome to the Guess Number Game in Zig.\n"); |
| 9 | 9 | |
| 10 | 10 | var seed_bytes: [@sizeOf(usize)]u8 = undefined; |
| 11 | %%os.getRandomBytes(seed_bytes[0...]); | |
| 11 | %%os.getRandomBytes(seed_bytes[0..]); | |
| 12 | 12 | const seed = std.mem.readInt(seed_bytes, usize, true); |
| 13 | 13 | var rand = Rand.init(seed); |
| 14 | 14 | |
| ... | ... | @@ -18,12 +18,12 @@ pub fn main() -> %void { |
| 18 | 18 | %%io.stdout.printf("\nGuess a number between 1 and 100: "); |
| 19 | 19 | var line_buf : [20]u8 = undefined; |
| 20 | 20 | |
| 21 | const line_len = io.stdin.read(line_buf[0...]) %% |err| { | |
| 21 | const line_len = io.stdin.read(line_buf[0..]) %% |err| { | |
| 22 | 22 | %%io.stdout.printf("Unable to read from stdin: {}\n", @errorName(err)); |
| 23 | 23 | return err; |
| 24 | 24 | }; |
| 25 | 25 | |
| 26 | const guess = fmt.parseUnsigned(u8, line_buf[0...line_len - 1], 10) %% { | |
| 26 | const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) %% { | |
| 27 | 27 | %%io.stdout.printf("Invalid number.\n"); |
| 28 | 28 | continue; |
| 29 | 29 | }; |
example/mix_o_files/base64.zig+2-2| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const base64 = @import("std").base64; |
| 2 | 2 | |
| 3 | 3 | export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize { |
| 4 | const src = source_ptr[0...source_len]; | |
| 5 | const dest = dest_ptr[0...dest_len]; | |
| 4 | const src = source_ptr[0..source_len]; | |
| 5 | const dest = dest_ptr[0..dest_len]; | |
| 6 | 6 | return base64.decode(dest, src).len; |
| 7 | 7 | } |
src/parser.cpp+4-4| ... | ... | @@ -284,7 +284,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | Token *ellipsis_tok = &pc->tokens->at(*token_index); |
| 287 | if (ellipsis_tok->id == TokenIdEllipsis) { | |
| 287 | if (ellipsis_tok->id == TokenIdEllipsis3) { | |
| 288 | 288 | *token_index += 1; |
| 289 | 289 | node->data.param_decl.is_var_args = true; |
| 290 | 290 | } else { |
| ... | ... | @@ -879,7 +879,7 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, |
| 879 | 879 | |
| 880 | 880 | Token *ellipsis_or_r_bracket = &pc->tokens->at(*token_index); |
| 881 | 881 | |
| 882 | if (ellipsis_or_r_bracket->id == TokenIdEllipsis) { | |
| 882 | if (ellipsis_or_r_bracket->id == TokenIdEllipsis2) { | |
| 883 | 883 | *token_index += 1; |
| 884 | 884 | |
| 885 | 885 | AstNode *node = ast_create_node(pc, NodeTypeSliceExpr, first_token); |
| ... | ... | @@ -1730,7 +1730,7 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, size_t *token_index, bool m |
| 1730 | 1730 | /* |
| 1731 | 1731 | SwitchExpression = "switch" "(" Expression ")" "{" many(SwitchProng) "}" |
| 1732 | 1732 | SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" option("*") Symbol "|") Expression "," |
| 1733 | SwitchItem : Expression | (Expression "..." Expression) | |
| 1733 | SwitchItem = Expression | (Expression "..." Expression) | |
| 1734 | 1734 | */ |
| 1735 | 1735 | static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 1736 | 1736 | Token *switch_token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -1767,7 +1767,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo |
| 1767 | 1767 | } else for (;;) { |
| 1768 | 1768 | AstNode *expr1 = ast_parse_expression(pc, token_index, true); |
| 1769 | 1769 | Token *ellipsis_tok = &pc->tokens->at(*token_index); |
| 1770 | if (ellipsis_tok->id == TokenIdEllipsis) { | |
| 1770 | if (ellipsis_tok->id == TokenIdEllipsis3) { | |
| 1771 | 1771 | *token_index += 1; |
| 1772 | 1772 | |
| 1773 | 1773 | AstNode *range_node = ast_create_node(pc, NodeTypeSwitchRange, ellipsis_tok); |
src/tokenizer.cpp+8-3| ... | ... | @@ -588,7 +588,7 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 588 | 588 | switch (c) { |
| 589 | 589 | case '.': |
| 590 | 590 | t.state = TokenizeStateSawDotDot; |
| 591 | set_token_id(&t, t.cur_tok, TokenIdEllipsis); | |
| 591 | set_token_id(&t, t.cur_tok, TokenIdEllipsis2); | |
| 592 | 592 | break; |
| 593 | 593 | default: |
| 594 | 594 | t.pos -= 1; |
| ... | ... | @@ -601,10 +601,14 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 601 | 601 | switch (c) { |
| 602 | 602 | case '.': |
| 603 | 603 | t.state = TokenizeStateStart; |
| 604 | set_token_id(&t, t.cur_tok, TokenIdEllipsis3); | |
| 604 | 605 | end_token(&t); |
| 605 | 606 | break; |
| 606 | 607 | default: |
| 607 | tokenize_error(&t, "invalid character: '%c'", c); | |
| 608 | t.pos -= 1; | |
| 609 | end_token(&t); | |
| 610 | t.state = TokenizeStateStart; | |
| 611 | continue; | |
| 608 | 612 | } |
| 609 | 613 | break; |
| 610 | 614 | case TokenizeStateSawGreaterThan: |
| ... | ... | @@ -1436,7 +1440,8 @@ const char * token_name(TokenId id) { |
| 1436 | 1440 | case TokenIdDivEq: return "/="; |
| 1437 | 1441 | case TokenIdDot: return "."; |
| 1438 | 1442 | case TokenIdDoubleQuestion: return "??"; |
| 1439 | case TokenIdEllipsis: return "..."; | |
| 1443 | case TokenIdEllipsis3: return "..."; | |
| 1444 | case TokenIdEllipsis2: return ".."; | |
| 1440 | 1445 | case TokenIdEof: return "EOF"; |
| 1441 | 1446 | case TokenIdEq: return "="; |
| 1442 | 1447 | case TokenIdFatArrow: return "=>"; |
src/tokenizer.hpp+2-1| ... | ... | @@ -40,7 +40,8 @@ enum TokenId { |
| 40 | 40 | TokenIdDivEq, |
| 41 | 41 | TokenIdDot, |
| 42 | 42 | TokenIdDoubleQuestion, |
| 43 | TokenIdEllipsis, | |
| 43 | TokenIdEllipsis3, | |
| 44 | TokenIdEllipsis2, | |
| 44 | 45 | TokenIdEof, |
| 45 | 46 | TokenIdEq, |
| 46 | 47 | TokenIdFatArrow, |
std/array_list.zig+2-2| ... | ... | @@ -27,11 +27,11 @@ pub fn ArrayList(comptime T: type) -> type{ |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | pub fn toSlice(l: &Self) -> []T { |
| 30 | return l.items[0...l.len]; | |
| 30 | return l.items[0..l.len]; | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | pub fn toSliceConst(l: &const Self) -> []const T { |
| 34 | return l.items[0...l.len]; | |
| 34 | return l.items[0..l.len]; | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | pub fn append(l: &Self, item: &const T) -> %void { |
std/base64.zig+5-5| ... | ... | @@ -56,7 +56,7 @@ pub fn encodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8) |
| 56 | 56 | out_index += 1; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | return dest[0...out_index]; | |
| 59 | return dest[0..out_index]; | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | pub fn decodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8) -> []u8 { |
| ... | ... | @@ -67,7 +67,7 @@ pub fn decodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8) |
| 67 | 67 | ascii6[c] = u8(i); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | return decodeWithAscii6BitMap(dest, source, ascii6[0...], alphabet[64]); | |
| 70 | return decodeWithAscii6BitMap(dest, source, ascii6[0..], alphabet[64]); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | pub fn decodeWithAscii6BitMap(dest: []u8, source: []const u8, ascii6: []const u8, pad_char: u8) -> []u8 { |
| ... | ... | @@ -115,7 +115,7 @@ pub fn decodeWithAscii6BitMap(dest: []u8, source: []const u8, ascii6: []const u8 |
| 115 | 115 | dest_index += 1; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | return dest[0...dest_index]; | |
| 118 | return dest[0..dest_index]; | |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | pub fn calcEncodedSize(source_len: usize) -> usize { |
| ... | ... | @@ -174,11 +174,11 @@ fn testBase64Case(expected_decoded: []const u8, expected_encoded: []const u8) { |
| 174 | 174 | |
| 175 | 175 | var buf: [100]u8 = undefined; |
| 176 | 176 | |
| 177 | const actual_decoded = decode(buf[0...], expected_encoded); | |
| 177 | const actual_decoded = decode(buf[0..], expected_encoded); | |
| 178 | 178 | assert(actual_decoded.len == expected_decoded.len); |
| 179 | 179 | assert(mem.eql(u8, expected_decoded, actual_decoded)); |
| 180 | 180 | |
| 181 | const actual_encoded = encode(buf[0...], expected_decoded); | |
| 181 | const actual_encoded = encode(buf[0..], expected_decoded); | |
| 182 | 182 | assert(actual_encoded.len == expected_encoded.len); |
| 183 | 183 | assert(mem.eql(u8, expected_encoded, actual_encoded)); |
| 184 | 184 | } |
std/buf_map.zig+1-1| ... | ... | @@ -58,7 +58,7 @@ pub const BufMap = struct { |
| 58 | 58 | |
| 59 | 59 | fn free(self: &BufMap, value: []const u8) { |
| 60 | 60 | // remove the const |
| 61 | const mut_value = @ptrCast(&u8, value.ptr)[0...value.len]; | |
| 61 | const mut_value = @ptrCast(&u8, value.ptr)[0..value.len]; | |
| 62 | 62 | self.hash_map.allocator.free(mut_value); |
| 63 | 63 | } |
| 64 | 64 |
std/buf_set.zig+1-1| ... | ... | @@ -47,7 +47,7 @@ pub const BufSet = struct { |
| 47 | 47 | |
| 48 | 48 | fn free(self: &BufSet, value: []const u8) { |
| 49 | 49 | // remove the const |
| 50 | const mut_value = @ptrCast(&u8, value.ptr)[0...value.len]; | |
| 50 | const mut_value = @ptrCast(&u8, value.ptr)[0..value.len]; | |
| 51 | 51 | self.hash_map.allocator.free(mut_value); |
| 52 | 52 | } |
| 53 | 53 |
std/buffer.zig+5-5| ... | ... | @@ -43,11 +43,11 @@ pub const Buffer = struct { |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | pub fn toSlice(self: &Buffer) -> []u8 { |
| 46 | return self.list.toSlice()[0...self.len()]; | |
| 46 | return self.list.toSlice()[0..self.len()]; | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | pub fn toSliceConst(self: &const Buffer) -> []const u8 { |
| 50 | return self.list.toSliceConst()[0...self.len()]; | |
| 50 | return self.list.toSliceConst()[0..self.len()]; | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | pub fn resize(self: &Buffer, new_len: usize) -> %void { |
| ... | ... | @@ -66,7 +66,7 @@ pub const Buffer = struct { |
| 66 | 66 | pub fn append(self: &Buffer, m: []const u8) -> %void { |
| 67 | 67 | const old_len = self.len(); |
| 68 | 68 | %return self.resize(old_len + m.len); |
| 69 | mem.copy(u8, self.list.toSlice()[old_len...], m); | |
| 69 | mem.copy(u8, self.list.toSlice()[old_len..], m); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | pub fn appendByte(self: &Buffer, byte: u8) -> %void { |
| ... | ... | @@ -80,14 +80,14 @@ pub const Buffer = struct { |
| 80 | 80 | |
| 81 | 81 | pub fn startsWith(self: &const Buffer, m: []const u8) -> bool { |
| 82 | 82 | if (self.len() < m.len) return false; |
| 83 | return mem.eql(u8, self.list.items[0...m.len], m); | |
| 83 | return mem.eql(u8, self.list.items[0..m.len], m); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | pub fn endsWith(self: &const Buffer, m: []const u8) -> bool { |
| 87 | 87 | const l = self.len(); |
| 88 | 88 | if (l < m.len) return false; |
| 89 | 89 | const start = l - m.len; |
| 90 | return mem.eql(u8, self.list.items[start...], m); | |
| 90 | return mem.eql(u8, self.list.items[start..], m); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | pub fn replaceContents(self: &const Buffer, m: []const u8) -> %void { |
std/build.zig+1-1| ... | ... | @@ -335,7 +335,7 @@ pub const Builder = struct { |
| 335 | 335 | }; |
| 336 | 336 | self.addRPath(rpath); |
| 337 | 337 | } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') { |
| 338 | const lib_path = word[2...]; | |
| 338 | const lib_path = word[2..]; | |
| 339 | 339 | self.addLibPath(lib_path); |
| 340 | 340 | } else { |
| 341 | 341 | %%io.stderr.printf("Unrecognized C flag from NIX_LDFLAGS: {}\n", word); |
std/cstr.zig+2-2| ... | ... | @@ -20,11 +20,11 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 { |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | pub fn toSliceConst(str: &const u8) -> []const u8 { |
| 23 | return str[0...len(str)]; | |
| 23 | return str[0..len(str)]; | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | pub fn toSlice(str: &u8) -> []u8 { |
| 27 | return str[0...len(str)]; | |
| 27 | return str[0..len(str)]; | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | test "cstr fns" { |
std/debug.zig+3-3| ... | ... | @@ -149,8 +149,8 @@ fn printLineFromFile(allocator: &mem.Allocator, out_stream: &io.OutStream, line_ |
| 149 | 149 | var column: usize = 1; |
| 150 | 150 | var abs_index: usize = 0; |
| 151 | 151 | while (true) { |
| 152 | const amt_read = %return f.read(buf[0...]); | |
| 153 | const slice = buf[0...amt_read]; | |
| 152 | const amt_read = %return f.read(buf[0..]); | |
| 153 | const slice = buf[0..amt_read]; | |
| 154 | 154 | |
| 155 | 155 | for (slice) |byte| { |
| 156 | 156 | if (line == line_info.line) { |
| ... | ... | @@ -939,7 +939,7 @@ var some_mem: [100 * 1024]u8 = undefined; |
| 939 | 939 | var some_mem_index: usize = 0; |
| 940 | 940 | |
| 941 | 941 | fn globalAlloc(self: &mem.Allocator, n: usize) -> %[]u8 { |
| 942 | const result = some_mem[some_mem_index ... some_mem_index + n]; | |
| 942 | const result = some_mem[some_mem_index .. some_mem_index + n]; | |
| 943 | 943 | some_mem_index += n; |
| 944 | 944 | return result; |
| 945 | 945 | } |
std/elf.zig+1-1| ... | ... | @@ -91,7 +91,7 @@ pub const Elf = struct { |
| 91 | 91 | elf.auto_close_stream = false; |
| 92 | 92 | |
| 93 | 93 | var magic: [4]u8 = undefined; |
| 94 | %return elf.in_stream.readNoEof(magic[0...]); | |
| 94 | %return elf.in_stream.readNoEof(magic[0..]); | |
| 95 | 95 | if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat; |
| 96 | 96 | |
| 97 | 97 | elf.is_64 = switch (%return elf.in_stream.readByte()) { |
std/endian.zig+1-1| ... | ... | @@ -15,6 +15,6 @@ pub fn swapIf(is_be: bool, comptime T: type, x: T) -> T { |
| 15 | 15 | |
| 16 | 16 | pub fn swap(comptime T: type, x: T) -> T { |
| 17 | 17 | var buf: [@sizeOf(T)]u8 = undefined; |
| 18 | mem.writeInt(buf[0...], x, false); | |
| 18 | mem.writeInt(buf[0..], x, false); | |
| 19 | 19 | return mem.readInt(buf, T, true); |
| 20 | 20 | } |
std/fmt.zig+19-19| ... | ... | @@ -38,14 +38,14 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool, |
| 38 | 38 | '{' => { |
| 39 | 39 | // TODO if you make this an if statement with `and` then it breaks |
| 40 | 40 | if (start_index < i) { |
| 41 | if (!output(context, fmt[start_index...i])) | |
| 41 | if (!output(context, fmt[start_index..i])) | |
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | state = State.OpenBrace; |
| 45 | 45 | }, |
| 46 | 46 | '}' => { |
| 47 | 47 | if (start_index < i) { |
| 48 | if (!output(context, fmt[start_index...i])) | |
| 48 | if (!output(context, fmt[start_index..i])) | |
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | state = State.CloseBrace; |
| ... | ... | @@ -123,7 +123,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool, |
| 123 | 123 | }, |
| 124 | 124 | State.IntegerWidth => switch (c) { |
| 125 | 125 | '}' => { |
| 126 | width = comptime %%parseUnsigned(usize, fmt[width_start...i], 10); | |
| 126 | width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10); | |
| 127 | 127 | if (!formatInt(args[next_arg], radix, uppercase, width, context, output)) |
| 128 | 128 | return false; |
| 129 | 129 | next_arg += 1; |
| ... | ... | @@ -135,7 +135,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool, |
| 135 | 135 | }, |
| 136 | 136 | State.BufWidth => switch (c) { |
| 137 | 137 | '}' => { |
| 138 | width = comptime %%parseUnsigned(usize, fmt[width_start...i], 10); | |
| 138 | width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10); | |
| 139 | 139 | if (!formatBuf(args[next_arg], width, context, output)) |
| 140 | 140 | return false; |
| 141 | 141 | next_arg += 1; |
| ... | ... | @@ -166,7 +166,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool, |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | if (start_index < fmt.len) { |
| 169 | if (!output(context, fmt[start_index...])) | |
| 169 | if (!output(context, fmt[start_index..])) | |
| 170 | 170 | return false; |
| 171 | 171 | } |
| 172 | 172 | |
| ... | ... | @@ -198,7 +198,7 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)->bool) -> bool { |
| 201 | return output(context, (&c)[0...1]); | |
| 201 | return output(context, (&c)[0..1]); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | pub fn formatBuf(buf: []const u8, width: usize, |
| ... | ... | @@ -210,7 +210,7 @@ pub fn formatBuf(buf: []const u8, width: usize, |
| 210 | 210 | var leftover_padding = if (width > buf.len) (width - buf.len) else return true; |
| 211 | 211 | const pad_byte: u8 = ' '; |
| 212 | 212 | while (leftover_padding > 0) : (leftover_padding -= 1) { |
| 213 | if (!output(context, (&pad_byte)[0...1])) | |
| 213 | if (!output(context, (&pad_byte)[0..1])) | |
| 214 | 214 | return false; |
| 215 | 215 | } |
| 216 | 216 | |
| ... | ... | @@ -234,7 +234,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, |
| 234 | 234 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 235 | 235 | if (value < 0) { |
| 236 | 236 | const minus_sign: u8 = '-'; |
| 237 | if (!output(context, (&minus_sign)[0...1])) | |
| 237 | if (!output(context, (&minus_sign)[0..1])) | |
| 238 | 238 | return false; |
| 239 | 239 | const new_value = uint(-(value + 1)) + 1; |
| 240 | 240 | const new_width = if (width == 0) 0 else (width - 1); |
| ... | ... | @@ -243,7 +243,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, |
| 243 | 243 | return formatIntUnsigned(uint(value), base, uppercase, width, context, output); |
| 244 | 244 | } else { |
| 245 | 245 | const plus_sign: u8 = '+'; |
| 246 | if (!output(context, (&plus_sign)[0...1])) | |
| 246 | if (!output(context, (&plus_sign)[0..1])) | |
| 247 | 247 | return false; |
| 248 | 248 | const new_value = uint(value); |
| 249 | 249 | const new_width = if (width == 0) 0 else (width - 1); |
| ... | ... | @@ -269,24 +269,24 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, |
| 269 | 269 | break; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | const digits_buf = buf[index...]; | |
| 272 | const digits_buf = buf[index..]; | |
| 273 | 273 | const padding = if (width > digits_buf.len) (width - digits_buf.len) else 0; |
| 274 | 274 | |
| 275 | 275 | if (padding > index) { |
| 276 | 276 | const zero_byte: u8 = '0'; |
| 277 | 277 | var leftover_padding = padding - index; |
| 278 | 278 | while (true) { |
| 279 | if (!output(context, (&zero_byte)[0...1])) | |
| 279 | if (!output(context, (&zero_byte)[0..1])) | |
| 280 | 280 | return false; |
| 281 | 281 | leftover_padding -= 1; |
| 282 | 282 | if (leftover_padding == 0) |
| 283 | 283 | break; |
| 284 | 284 | } |
| 285 | mem.set(u8, buf[0...index], '0'); | |
| 285 | mem.set(u8, buf[0..index], '0'); | |
| 286 | 286 | return output(context, buf); |
| 287 | 287 | } else { |
| 288 | const padded_buf = buf[index - padding...]; | |
| 289 | mem.set(u8, padded_buf[0...padding], '0'); | |
| 288 | const padded_buf = buf[index - padding..]; | |
| 289 | mem.set(u8, padded_buf[0..padding], '0'); | |
| 290 | 290 | return output(context, padded_buf); |
| 291 | 291 | } |
| 292 | 292 | } |
| ... | ... | @@ -304,7 +304,7 @@ const FormatIntBuf = struct { |
| 304 | 304 | index: usize, |
| 305 | 305 | }; |
| 306 | 306 | fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) -> bool { |
| 307 | mem.copy(u8, context.out_buf[context.index...], bytes); | |
| 307 | mem.copy(u8, context.out_buf[context.index..], bytes); | |
| 308 | 308 | context.index += bytes.len; |
| 309 | 309 | return true; |
| 310 | 310 | } |
| ... | ... | @@ -350,14 +350,14 @@ const BufPrintContext = struct { |
| 350 | 350 | |
| 351 | 351 | fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) -> bool { |
| 352 | 352 | mem.copy(u8, context.remaining, bytes); |
| 353 | context.remaining = context.remaining[bytes.len...]; | |
| 353 | context.remaining = context.remaining[bytes.len..]; | |
| 354 | 354 | return true; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> []u8 { |
| 358 | 358 | var context = BufPrintContext { .remaining = buf, }; |
| 359 | 359 | _ = format(&context, bufPrintWrite, fmt, args); |
| 360 | return buf[0...buf.len - context.remaining.len]; | |
| 360 | return buf[0..buf.len - context.remaining.len]; | |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 { |
| ... | ... | @@ -374,7 +374,7 @@ fn countSize(size: &usize, bytes: []const u8) -> bool { |
| 374 | 374 | |
| 375 | 375 | test "buf print int" { |
| 376 | 376 | var buffer: [max_int_digits]u8 = undefined; |
| 377 | const buf = buffer[0...]; | |
| 377 | const buf = buffer[0..]; | |
| 378 | 378 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110")); |
| 379 | 379 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678")); |
| 380 | 380 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e")); |
| ... | ... | @@ -391,7 +391,7 @@ test "buf print int" { |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) -> []u8 { |
| 394 | return buf[0...formatIntBuf(buf, value, base, uppercase, width)]; | |
| 394 | return buf[0..formatIntBuf(buf, value, base, uppercase, width)]; | |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | test "parse u64 digit too big" { |
std/io.zig+7-7| ... | ... | @@ -113,7 +113,7 @@ pub const OutStream = struct { |
| 113 | 113 | while (src_index < bytes.len) { |
| 114 | 114 | const dest_space_left = self.buffer.len - self.index; |
| 115 | 115 | const copy_amt = math.min(dest_space_left, bytes.len - src_index); |
| 116 | mem.copy(u8, self.buffer[self.index...], bytes[src_index...src_index + copy_amt]); | |
| 116 | mem.copy(u8, self.buffer[self.index..], bytes[src_index..src_index + copy_amt]); | |
| 117 | 117 | self.index += copy_amt; |
| 118 | 118 | assert(self.index <= self.buffer.len); |
| 119 | 119 | if (self.index == self.buffer.len) { |
| ... | ... | @@ -152,7 +152,7 @@ pub const OutStream = struct { |
| 152 | 152 | |
| 153 | 153 | pub fn flush(self: &OutStream) -> %void { |
| 154 | 154 | if (self.index != 0) { |
| 155 | %return os.posixWrite(self.fd, self.buffer[0...self.index]); | |
| 155 | %return os.posixWrite(self.fd, self.buffer[0..self.index]); | |
| 156 | 156 | self.index = 0; |
| 157 | 157 | } |
| 158 | 158 | } |
| ... | ... | @@ -236,13 +236,13 @@ pub const InStream = struct { |
| 236 | 236 | |
| 237 | 237 | pub fn readByte(is: &InStream) -> %u8 { |
| 238 | 238 | var result: [1]u8 = undefined; |
| 239 | %return is.readNoEof(result[0...]); | |
| 239 | %return is.readNoEof(result[0..]); | |
| 240 | 240 | return result[0]; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | pub fn readByteSigned(is: &InStream) -> %i8 { |
| 244 | 244 | var result: [1]i8 = undefined; |
| 245 | %return is.readNoEof(([]u8)(result[0...])); | |
| 245 | %return is.readNoEof(([]u8)(result[0..])); | |
| 246 | 246 | return result[0]; |
| 247 | 247 | } |
| 248 | 248 | |
| ... | ... | @@ -256,7 +256,7 @@ pub const InStream = struct { |
| 256 | 256 | |
| 257 | 257 | pub fn readInt(is: &InStream, is_be: bool, comptime T: type) -> %T { |
| 258 | 258 | var bytes: [@sizeOf(T)]u8 = undefined; |
| 259 | %return is.readNoEof(bytes[0...]); | |
| 259 | %return is.readNoEof(bytes[0..]); | |
| 260 | 260 | return mem.readInt(bytes, T, is_be); |
| 261 | 261 | } |
| 262 | 262 | |
| ... | ... | @@ -264,7 +264,7 @@ pub const InStream = struct { |
| 264 | 264 | assert(size <= @sizeOf(T)); |
| 265 | 265 | assert(size <= 8); |
| 266 | 266 | var input_buf: [8]u8 = undefined; |
| 267 | const input_slice = input_buf[0...size]; | |
| 267 | const input_slice = input_buf[0..size]; | |
| 268 | 268 | %return is.readNoEof(input_slice); |
| 269 | 269 | return mem.readInt(input_slice, T, is_be); |
| 270 | 270 | } |
| ... | ... | @@ -349,7 +349,7 @@ pub const InStream = struct { |
| 349 | 349 | |
| 350 | 350 | var actual_buf_len: usize = 0; |
| 351 | 351 | while (true) { |
| 352 | const dest_slice = buf.toSlice()[actual_buf_len...]; | |
| 352 | const dest_slice = buf.toSlice()[actual_buf_len..]; | |
| 353 | 353 | const bytes_read = %return is.read(dest_slice); |
| 354 | 354 | actual_buf_len += bytes_read; |
| 355 | 355 |
std/mem.zig+11-11| ... | ... | @@ -31,7 +31,7 @@ pub const Allocator = struct { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | fn destroy(self: &Allocator, ptr: var) { |
| 34 | self.free(ptr[0...1]); | |
| 34 | self.free(ptr[0..1]); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | fn alloc(self: &Allocator, comptime T: type, n: usize) -> %[]T { |
| ... | ... | @@ -69,7 +69,7 @@ pub const IncrementingAllocator = struct { |
| 69 | 69 | .reallocFn = realloc, |
| 70 | 70 | .freeFn = free, |
| 71 | 71 | }, |
| 72 | .bytes = @intToPtr(&u8, addr)[0...capacity], | |
| 72 | .bytes = @intToPtr(&u8, addr)[0..capacity], | |
| 73 | 73 | .end_index = 0, |
| 74 | 74 | }; |
| 75 | 75 | }, |
| ... | ... | @@ -87,7 +87,7 @@ pub const IncrementingAllocator = struct { |
| 87 | 87 | if (new_end_index > self.bytes.len) { |
| 88 | 88 | return error.NoMem; |
| 89 | 89 | } |
| 90 | const result = self.bytes[self.end_index...new_end_index]; | |
| 90 | const result = self.bytes[self.end_index..new_end_index]; | |
| 91 | 91 | self.end_index = new_end_index; |
| 92 | 92 | return result; |
| 93 | 93 | } |
| ... | ... | @@ -165,7 +165,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) -> ?usi |
| 165 | 165 | var i: usize = 0; |
| 166 | 166 | const end = haystack.len - needle.len; |
| 167 | 167 | while (i <= end) : (i += 1) { |
| 168 | if (eql(T, haystack[i...i + needle.len], needle)) | |
| 168 | if (eql(T, haystack[i .. i + needle.len], needle)) | |
| 169 | 169 | return i; |
| 170 | 170 | } |
| 171 | 171 | return null; |
| ... | ... | @@ -253,7 +253,7 @@ test "mem.split" { |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) -> bool { |
| 256 | return if (needle.len > haystack.len) false else eql(T, haystack[0...needle.len], needle); | |
| 256 | return if (needle.len > haystack.len) false else eql(T, haystack[0 .. needle.len], needle); | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | const SplitIterator = struct { |
| ... | ... | @@ -273,7 +273,7 @@ const SplitIterator = struct { |
| 273 | 273 | while (self.index < self.s.len and self.s[self.index] != self.c) : (self.index += 1) {} |
| 274 | 274 | const end = self.index; |
| 275 | 275 | |
| 276 | return self.s[start...end]; | |
| 276 | return self.s[start..end]; | |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /// Returns a slice of the remaining bytes. Does not affect iterator state. |
| ... | ... | @@ -281,7 +281,7 @@ const SplitIterator = struct { |
| 281 | 281 | // move to beginning of token |
| 282 | 282 | var index: usize = self.index; |
| 283 | 283 | while (index < self.s.len and self.s[index] == self.c) : (index += 1) {} |
| 284 | return self.s[index...]; | |
| 284 | return self.s[index..]; | |
| 285 | 285 | } |
| 286 | 286 | }; |
| 287 | 287 | |
| ... | ... | @@ -320,16 +320,16 @@ test "testWriteInt" { |
| 320 | 320 | fn testWriteIntImpl() { |
| 321 | 321 | var bytes: [4]u8 = undefined; |
| 322 | 322 | |
| 323 | writeInt(bytes[0...], u32(0x12345678), true); | |
| 323 | writeInt(bytes[0..], u32(0x12345678), true); | |
| 324 | 324 | assert(eql(u8, bytes, []u8{ 0x12, 0x34, 0x56, 0x78 })); |
| 325 | 325 | |
| 326 | writeInt(bytes[0...], u32(0x78563412), false); | |
| 326 | writeInt(bytes[0..], u32(0x78563412), false); | |
| 327 | 327 | assert(eql(u8, bytes, []u8{ 0x12, 0x34, 0x56, 0x78 })); |
| 328 | 328 | |
| 329 | writeInt(bytes[0...], u16(0x1234), true); | |
| 329 | writeInt(bytes[0..], u16(0x1234), true); | |
| 330 | 330 | assert(eql(u8, bytes, []u8{ 0x00, 0x00, 0x12, 0x34 })); |
| 331 | 331 | |
| 332 | writeInt(bytes[0...], u16(0x1234), false); | |
| 332 | writeInt(bytes[0..], u16(0x1234), false); | |
| 333 | 333 | assert(eql(u8, bytes, []u8{ 0x34, 0x12, 0x00, 0x00 })); |
| 334 | 334 | } |
| 335 | 335 |
std/net.zig+5-5| ... | ... | @@ -34,7 +34,7 @@ const Connection = struct { |
| 34 | 34 | const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null); |
| 35 | 35 | const recv_err = linux.getErrno(recv_ret); |
| 36 | 36 | switch (recv_err) { |
| 37 | 0 => return buf[0...recv_ret], | |
| 37 | 0 => return buf[0..recv_ret], | |
| 38 | 38 | errno.EINVAL => unreachable, |
| 39 | 39 | errno.EFAULT => unreachable, |
| 40 | 40 | errno.ENOTSOCK => return error.NotSocket, |
| ... | ... | @@ -81,7 +81,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address { |
| 81 | 81 | //switch (parseIpLiteral(hostname)) { |
| 82 | 82 | // Ok => |addr| { |
| 83 | 83 | // out_addrs[0] = addr; |
| 84 | // return out_addrs[0...1]; | |
| 84 | // return out_addrs[0..1]; | |
| 85 | 85 | // }, |
| 86 | 86 | // else => {}, |
| 87 | 87 | //}; |
| ... | ... | @@ -134,7 +134,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection { |
| 134 | 134 | |
| 135 | 135 | pub fn connect(hostname: []const u8, port: u16) -> %Connection { |
| 136 | 136 | var addrs_buf: [1]Address = undefined; |
| 137 | const addrs_slice = %return lookup(hostname, addrs_buf[0...]); | |
| 137 | const addrs_slice = %return lookup(hostname, addrs_buf[0..]); | |
| 138 | 138 | const main_addr = &addrs_slice[0]; |
| 139 | 139 | |
| 140 | 140 | return connectAddr(main_addr, port); |
| ... | ... | @@ -186,7 +186,7 @@ fn parseIp6(buf: []const u8) -> %Address { |
| 186 | 186 | var result: Address = undefined; |
| 187 | 187 | result.family = linux.AF_INET6; |
| 188 | 188 | result.scope_id = 0; |
| 189 | const ip_slice = result.addr[0...]; | |
| 189 | const ip_slice = result.addr[0..]; | |
| 190 | 190 | |
| 191 | 191 | var x: u16 = 0; |
| 192 | 192 | var saw_any_digits = false; |
| ... | ... | @@ -280,7 +280,7 @@ fn parseIp6(buf: []const u8) -> %Address { |
| 280 | 280 | |
| 281 | 281 | fn parseIp4(buf: []const u8) -> %u32 { |
| 282 | 282 | var result: u32 = undefined; |
| 283 | const out_ptr = ([]u8)((&result)[0...1]); | |
| 283 | const out_ptr = ([]u8)((&result)[0..1]); | |
| 284 | 284 | |
| 285 | 285 | var x: u8 = 0; |
| 286 | 286 | var index: u8 = 0; |
std/os/child_process.zig+2-2| ... | ... | @@ -225,7 +225,7 @@ fn forkChildErrReport(fd: i32, err: error) -> noreturn { |
| 225 | 225 | const ErrInt = @IntType(false, @sizeOf(error) * 8); |
| 226 | 226 | fn writeIntFd(fd: i32, value: ErrInt) -> %void { |
| 227 | 227 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 228 | mem.writeInt(bytes[0...], value, true); | |
| 228 | mem.writeInt(bytes[0..], value, true); | |
| 229 | 229 | |
| 230 | 230 | var index: usize = 0; |
| 231 | 231 | while (index < bytes.len) { |
| ... | ... | @@ -259,6 +259,6 @@ fn readIntFd(fd: i32) -> %ErrInt { |
| 259 | 259 | index += amt_written; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | return mem.readInt(bytes[0...], ErrInt, true); | |
| 262 | return mem.readInt(bytes[0..], ErrInt, true); | |
| 263 | 263 | } |
| 264 | 264 |
std/os/index.zig+18-18| ... | ... | @@ -172,7 +172,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?& |
| 172 | 172 | var need_free = false; |
| 173 | 173 | |
| 174 | 174 | if (file_path.len < stack_buf.len) { |
| 175 | path0 = stack_buf[0...file_path.len + 1]; | |
| 175 | path0 = stack_buf[0..file_path.len + 1]; | |
| 176 | 176 | } else if (allocator) |a| { |
| 177 | 177 | path0 = %return a.alloc(u8, file_path.len + 1); |
| 178 | 178 | need_free = true; |
| ... | ... | @@ -311,7 +311,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con |
| 311 | 311 | while (it.next()) |search_path| { |
| 312 | 312 | mem.copy(u8, path_buf, search_path); |
| 313 | 313 | path_buf[search_path.len] = '/'; |
| 314 | mem.copy(u8, path_buf[search_path.len + 1 ...], exe_path); | |
| 314 | mem.copy(u8, path_buf[search_path.len + 1 ..], exe_path); | |
| 315 | 315 | path_buf[search_path.len + exe_path.len + 1] = 0; |
| 316 | 316 | err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr)); |
| 317 | 317 | assert(err > 0); |
| ... | ... | @@ -352,11 +352,11 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap { |
| 352 | 352 | for (environ_raw) |ptr| { |
| 353 | 353 | var line_i: usize = 0; |
| 354 | 354 | while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {} |
| 355 | const key = ptr[0...line_i]; | |
| 355 | const key = ptr[0..line_i]; | |
| 356 | 356 | |
| 357 | 357 | var end_i: usize = line_i; |
| 358 | 358 | while (ptr[end_i] != 0) : (end_i += 1) {} |
| 359 | const value = ptr[line_i + 1...end_i]; | |
| 359 | const value = ptr[line_i + 1..end_i]; | |
| 360 | 360 | |
| 361 | 361 | %return result.set(key, value); |
| 362 | 362 | } |
| ... | ... | @@ -367,13 +367,13 @@ pub fn getEnv(key: []const u8) -> ?[]const u8 { |
| 367 | 367 | for (environ_raw) |ptr| { |
| 368 | 368 | var line_i: usize = 0; |
| 369 | 369 | while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {} |
| 370 | const this_key = ptr[0...line_i]; | |
| 370 | const this_key = ptr[0..line_i]; | |
| 371 | 371 | if (!mem.eql(u8, key, this_key)) |
| 372 | 372 | continue; |
| 373 | 373 | |
| 374 | 374 | var end_i: usize = line_i; |
| 375 | 375 | while (ptr[end_i] != 0) : (end_i += 1) {} |
| 376 | const this_value = ptr[line_i + 1...end_i]; | |
| 376 | const this_value = ptr[line_i + 1..end_i]; | |
| 377 | 377 | |
| 378 | 378 | return this_value; |
| 379 | 379 | } |
| ... | ... | @@ -417,7 +417,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con |
| 417 | 417 | mem.copy(u8, existing_buf, existing_path); |
| 418 | 418 | existing_buf[existing_path.len] = 0; |
| 419 | 419 | |
| 420 | const new_buf = full_buf[existing_path.len + 1...]; | |
| 420 | const new_buf = full_buf[existing_path.len + 1..]; | |
| 421 | 421 | mem.copy(u8, new_buf, new_path); |
| 422 | 422 | new_buf[new_path.len] = 0; |
| 423 | 423 | |
| ... | ... | @@ -456,10 +456,10 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: |
| 456 | 456 | var rand_buf: [12]u8 = undefined; |
| 457 | 457 | const tmp_path = %return allocator.alloc(u8, new_path.len + base64.calcEncodedSize(rand_buf.len)); |
| 458 | 458 | defer allocator.free(tmp_path); |
| 459 | mem.copy(u8, tmp_path[0...], new_path); | |
| 459 | mem.copy(u8, tmp_path[0..], new_path); | |
| 460 | 460 | while (true) { |
| 461 | %return getRandomBytes(rand_buf[0...]); | |
| 462 | _ = base64.encodeWithAlphabet(tmp_path[new_path.len...], rand_buf, b64_fs_alphabet); | |
| 461 | %return getRandomBytes(rand_buf[0..]); | |
| 462 | _ = base64.encodeWithAlphabet(tmp_path[new_path.len..], rand_buf, b64_fs_alphabet); | |
| 463 | 463 | if (symLink(allocator, existing_path, tmp_path)) { |
| 464 | 464 | return rename(allocator, tmp_path, new_path); |
| 465 | 465 | } else |err| { |
| ... | ... | @@ -510,9 +510,9 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [ |
| 510 | 510 | var rand_buf: [12]u8 = undefined; |
| 511 | 511 | const tmp_path = %return allocator.alloc(u8, dest_path.len + base64.calcEncodedSize(rand_buf.len)); |
| 512 | 512 | defer allocator.free(tmp_path); |
| 513 | mem.copy(u8, tmp_path[0...], dest_path); | |
| 514 | %return getRandomBytes(rand_buf[0...]); | |
| 515 | _ = base64.encodeWithAlphabet(tmp_path[dest_path.len...], rand_buf, b64_fs_alphabet); | |
| 513 | mem.copy(u8, tmp_path[0..], dest_path); | |
| 514 | %return getRandomBytes(rand_buf[0..]); | |
| 515 | _ = base64.encodeWithAlphabet(tmp_path[dest_path.len..], rand_buf, b64_fs_alphabet); | |
| 516 | 516 | |
| 517 | 517 | var out_stream = %return io.OutStream.openMode(tmp_path, mode, allocator); |
| 518 | 518 | defer out_stream.close(); |
| ... | ... | @@ -521,7 +521,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [ |
| 521 | 521 | var in_stream = %return io.InStream.open(source_path, allocator); |
| 522 | 522 | defer in_stream.close(); |
| 523 | 523 | |
| 524 | const buf = out_stream.buffer[0...]; | |
| 524 | const buf = out_stream.buffer[0..]; | |
| 525 | 525 | while (true) { |
| 526 | 526 | const amt = %return in_stream.read(buf); |
| 527 | 527 | out_stream.index = amt; |
| ... | ... | @@ -539,7 +539,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) |
| 539 | 539 | mem.copy(u8, old_buf, old_path); |
| 540 | 540 | old_buf[old_path.len] = 0; |
| 541 | 541 | |
| 542 | const new_buf = full_buf[old_path.len + 1...]; | |
| 542 | const new_buf = full_buf[old_path.len + 1..]; | |
| 543 | 543 | mem.copy(u8, new_buf, new_path); |
| 544 | 544 | new_buf[new_path.len] = 0; |
| 545 | 545 | |
| ... | ... | @@ -601,7 +601,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { |
| 601 | 601 | |
| 602 | 602 | var end_index: usize = resolved_path.len; |
| 603 | 603 | while (true) { |
| 604 | makeDir(allocator, resolved_path[0...end_index]) %% |err| { | |
| 604 | makeDir(allocator, resolved_path[0..end_index]) %% |err| { | |
| 605 | 605 | if (err == error.PathAlreadyExists) { |
| 606 | 606 | // TODO stat the file and return an error if it's not a directory |
| 607 | 607 | // this is important because otherwise a dangling symlink |
| ... | ... | @@ -691,7 +691,7 @@ start_over: |
| 691 | 691 | const full_entry_path = full_entry_buf.toSlice(); |
| 692 | 692 | mem.copy(u8, full_entry_path, full_path); |
| 693 | 693 | full_entry_path[full_path.len] = '/'; |
| 694 | mem.copy(u8, full_entry_path[full_path.len + 1...], entry.name); | |
| 694 | mem.copy(u8, full_entry_path[full_path.len + 1..], entry.name); | |
| 695 | 695 | |
| 696 | 696 | %return deleteTree(allocator, full_entry_path); |
| 697 | 697 | } |
| ... | ... | @@ -856,6 +856,6 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 856 | 856 | result_buf = %return allocator.realloc(u8, result_buf, result_buf.len * 2); |
| 857 | 857 | continue; |
| 858 | 858 | } |
| 859 | return result_buf[0...ret_val]; | |
| 859 | return result_buf[0..ret_val]; | |
| 860 | 860 | } |
| 861 | 861 | } |
std/os/path.zig+15-15| ... | ... | @@ -39,7 +39,7 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { |
| 39 | 39 | inline while (true) { |
| 40 | 40 | const arg = ([]const u8)(paths[path_i]); |
| 41 | 41 | path_i += 1; |
| 42 | mem.copy(u8, buf[buf_index...], arg); | |
| 42 | mem.copy(u8, buf[buf_index..], arg); | |
| 43 | 43 | buf_index += arg.len; |
| 44 | 44 | if (path_i >= paths.len) break; |
| 45 | 45 | if (buf[buf_index - 1] != sep) { |
| ... | ... | @@ -48,7 +48,7 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | return buf[0...buf_index]; | |
| 51 | return buf[0..buf_index]; | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | test "os.path.join" { |
| ... | ... | @@ -110,7 +110,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { |
| 110 | 110 | } |
| 111 | 111 | %defer allocator.free(result); |
| 112 | 112 | |
| 113 | for (paths[first_index...]) |p, i| { | |
| 113 | for (paths[first_index..]) |p, i| { | |
| 114 | 114 | var it = mem.split(p, '/'); |
| 115 | 115 | while (it.next()) |component| { |
| 116 | 116 | if (mem.eql(u8, component, ".")) { |
| ... | ... | @@ -126,7 +126,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { |
| 126 | 126 | } else { |
| 127 | 127 | result[result_index] = '/'; |
| 128 | 128 | result_index += 1; |
| 129 | mem.copy(u8, result[result_index...], component); | |
| 129 | mem.copy(u8, result[result_index..], component); | |
| 130 | 130 | result_index += component.len; |
| 131 | 131 | } |
| 132 | 132 | } |
| ... | ... | @@ -137,7 +137,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { |
| 137 | 137 | result_index += 1; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | return result[0...result_index]; | |
| 140 | return result[0..result_index]; | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "os.path.resolve" { |
| ... | ... | @@ -153,24 +153,24 @@ fn testResolve(args: ...) -> []u8 { |
| 153 | 153 | |
| 154 | 154 | pub fn dirname(path: []const u8) -> []const u8 { |
| 155 | 155 | if (path.len == 0) |
| 156 | return path[0...0]; | |
| 156 | return path[0..0]; | |
| 157 | 157 | var end_index: usize = path.len - 1; |
| 158 | 158 | while (path[end_index] == '/') { |
| 159 | 159 | if (end_index == 0) |
| 160 | return path[0...1]; | |
| 160 | return path[0..1]; | |
| 161 | 161 | end_index -= 1; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | while (path[end_index] != '/') { |
| 165 | 165 | if (end_index == 0) |
| 166 | return path[0...0]; | |
| 166 | return path[0..0]; | |
| 167 | 167 | end_index -= 1; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | if (end_index == 0 and path[end_index] == '/') |
| 171 | return path[0...1]; | |
| 171 | return path[0..1]; | |
| 172 | 172 | |
| 173 | return path[0...end_index]; | |
| 173 | return path[0..end_index]; | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "os.path.dirname" { |
| ... | ... | @@ -202,11 +202,11 @@ pub fn basename(path: []const u8) -> []const u8 { |
| 202 | 202 | end_index += 1; |
| 203 | 203 | while (path[start_index] != '/') { |
| 204 | 204 | if (start_index == 0) |
| 205 | return path[0...end_index]; | |
| 205 | return path[0..end_index]; | |
| 206 | 206 | start_index -= 1; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | return path[start_index + 1...end_index]; | |
| 209 | return path[start_index + 1..end_index]; | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | test "os.path.basename" { |
| ... | ... | @@ -265,10 +265,10 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u |
| 265 | 265 | } |
| 266 | 266 | if (to_rest.len == 0) { |
| 267 | 267 | // shave off the trailing slash |
| 268 | return result[0...result_index - 1]; | |
| 268 | return result[0..result_index - 1]; | |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | mem.copy(u8, result[result_index...], to_rest); | |
| 271 | mem.copy(u8, result[result_index..], to_rest); | |
| 272 | 272 | return result; |
| 273 | 273 | } |
| 274 | 274 | |
| ... | ... | @@ -303,7 +303,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 303 | 303 | defer os.posixClose(fd); |
| 304 | 304 | |
| 305 | 305 | var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined; |
| 306 | const proc_path = fmt.bufPrint(buf[0...], "/proc/self/fd/{}", fd); | |
| 306 | const proc_path = fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd); | |
| 307 | 307 | |
| 308 | 308 | return os.readLink(allocator, proc_path); |
| 309 | 309 | } |
std/rand.zig+4-4| ... | ... | @@ -39,7 +39,7 @@ pub const Rand = struct { |
| 39 | 39 | return (r.rng.get() & 0b1) == 0; |
| 40 | 40 | } else { |
| 41 | 41 | var result: [@sizeOf(T)]u8 = undefined; |
| 42 | r.fillBytes(result[0...]); | |
| 42 | r.fillBytes(result[0..]); | |
| 43 | 43 | return mem.readInt(result, T, false); |
| 44 | 44 | } |
| 45 | 45 | } |
| ... | ... | @@ -48,12 +48,12 @@ pub const Rand = struct { |
| 48 | 48 | pub fn fillBytes(r: &Rand, buf: []u8) { |
| 49 | 49 | var bytes_left = buf.len; |
| 50 | 50 | while (bytes_left >= @sizeOf(usize)) { |
| 51 | mem.writeInt(buf[buf.len - bytes_left...], r.rng.get(), false); | |
| 51 | mem.writeInt(buf[buf.len - bytes_left..], r.rng.get(), false); | |
| 52 | 52 | bytes_left -= @sizeOf(usize); |
| 53 | 53 | } |
| 54 | 54 | if (bytes_left > 0) { |
| 55 | 55 | var rand_val_array: [@sizeOf(usize)]u8 = undefined; |
| 56 | mem.writeInt(rand_val_array[0...], r.rng.get(), false); | |
| 56 | mem.writeInt(rand_val_array[0..], r.rng.get(), false); | |
| 57 | 57 | while (bytes_left > 0) { |
| 58 | 58 | buf[buf.len - bytes_left] = rand_val_array[@sizeOf(usize) - bytes_left]; |
| 59 | 59 | bytes_left -= 1; |
| ... | ... | @@ -71,7 +71,7 @@ pub const Rand = struct { |
| 71 | 71 | var rand_val_array: [@sizeOf(T)]u8 = undefined; |
| 72 | 72 | |
| 73 | 73 | while (true) { |
| 74 | r.fillBytes(rand_val_array[0...]); | |
| 74 | r.fillBytes(rand_val_array[0..]); | |
| 75 | 75 | const rand_val = mem.readInt(rand_val_array, T, false); |
| 76 | 76 | if (rand_val < upper_bound) { |
| 77 | 77 | return start + (rand_val % range); |
std/sort.zig+3-3| ... | ... | @@ -70,7 +70,7 @@ test "testSort" { |
| 70 | 70 | |
| 71 | 71 | for (u8cases) |case| { |
| 72 | 72 | var buf: [8]u8 = undefined; |
| 73 | const slice = buf[0...case[0].len]; | |
| 73 | const slice = buf[0..case[0].len]; | |
| 74 | 74 | mem.copy(u8, slice, case[0]); |
| 75 | 75 | sort(u8, slice, u8asc); |
| 76 | 76 | assert(mem.eql(u8, slice, case[1])); |
| ... | ... | @@ -87,7 +87,7 @@ test "testSort" { |
| 87 | 87 | |
| 88 | 88 | for (i32cases) |case| { |
| 89 | 89 | var buf: [8]i32 = undefined; |
| 90 | const slice = buf[0...case[0].len]; | |
| 90 | const slice = buf[0..case[0].len]; | |
| 91 | 91 | mem.copy(i32, slice, case[0]); |
| 92 | 92 | sort(i32, slice, i32asc); |
| 93 | 93 | assert(mem.eql(i32, slice, case[1])); |
| ... | ... | @@ -106,7 +106,7 @@ test "testSortDesc" { |
| 106 | 106 | |
| 107 | 107 | for (rev_cases) |case| { |
| 108 | 108 | var buf: [8]i32 = undefined; |
| 109 | const slice = buf[0...case[0].len]; | |
| 109 | const slice = buf[0..case[0].len]; | |
| 110 | 110 | mem.copy(i32, slice, case[0]); |
| 111 | 111 | sort(i32, slice, i32desc); |
| 112 | 112 | assert(mem.eql(i32, slice, case[1])); |
std/special/bootstrap.zig+2-2| ... | ... | @@ -39,11 +39,11 @@ fn callMainAndExit() -> noreturn { |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void { |
| 42 | std.os.args.raw = argv[0...argc]; | |
| 42 | std.os.args.raw = argv[0..argc]; | |
| 43 | 43 | |
| 44 | 44 | var env_count: usize = 0; |
| 45 | 45 | while (envp[env_count] != null) : (env_count += 1) {} |
| 46 | std.os.environ_raw = @ptrCast(&&u8, envp)[0...env_count]; | |
| 46 | std.os.environ_raw = @ptrCast(&&u8, envp)[0..env_count]; | |
| 47 | 47 | |
| 48 | 48 | std.debug.user_main_fn = root.main; |
| 49 | 49 |
std/special/build_runner.zig+3-3| ... | ... | @@ -58,14 +58,14 @@ pub fn main() -> %void { |
| 58 | 58 | while (arg_i < os.args.count()) : (arg_i += 1) { |
| 59 | 59 | const arg = os.args.at(arg_i); |
| 60 | 60 | if (mem.startsWith(u8, arg, "-D")) { |
| 61 | const option_contents = arg[2...]; | |
| 61 | const option_contents = arg[2..]; | |
| 62 | 62 | if (option_contents.len == 0) { |
| 63 | 63 | %%io.stderr.printf("Expected option name after '-D'\n\n"); |
| 64 | 64 | return usage(&builder, false, &io.stderr); |
| 65 | 65 | } |
| 66 | 66 | if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { |
| 67 | const option_name = option_contents[0...name_end]; | |
| 68 | const option_value = option_contents[name_end + 1...]; | |
| 67 | const option_name = option_contents[0..name_end]; | |
| 68 | const option_value = option_contents[name_end + 1..]; | |
| 69 | 69 | if (builder.addUserInputOption(option_name, option_value)) |
| 70 | 70 | return usage(&builder, false, &io.stderr); |
| 71 | 71 | } else { |
std/special/zigrt.zig+2-2| ... | ... | @@ -9,10 +9,10 @@ export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> nore |
| 9 | 9 | @setDebugSafety(this, false); |
| 10 | 10 | |
| 11 | 11 | if (builtin.__zig_panic_implementation_provided) { |
| 12 | @import("@root").panic(message_ptr[0...message_len]); | |
| 12 | @import("@root").panic(message_ptr[0..message_len]); | |
| 13 | 13 | } else if (builtin.os == builtin.Os.freestanding) { |
| 14 | 14 | while (true) {} |
| 15 | 15 | } else { |
| 16 | @import("std").debug.panic("{}", message_ptr[0...message_len]); | |
| 16 | @import("std").debug.panic("{}", message_ptr[0..message_len]); | |
| 17 | 17 | } |
| 18 | 18 | } |
test/cases/array.zig+1-1| ... | ... | @@ -70,7 +70,7 @@ const Str = struct { |
| 70 | 70 | a: []Sub, |
| 71 | 71 | }; |
| 72 | 72 | test "setGlobalVarArrayViaSliceEmbeddedInStruct" { |
| 73 | var s = Str { .a = s_array[0...]}; | |
| 73 | var s = Str { .a = s_array[0..]}; | |
| 74 | 74 | |
| 75 | 75 | s.a[0].b = 1; |
| 76 | 76 | s.a[1].b = 2; |
test/cases/cast.zig+4-4| ... | ... | @@ -148,7 +148,7 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) -> []const u8 { |
| 148 | 148 | return []const u8 {}; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | return slice[0...1]; | |
| 151 | return slice[0..1]; | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "implicitly cast from [N]T to ?[]const T" { |
| ... | ... | @@ -177,13 +177,13 @@ fn gimmeErrOrSlice() -> %[]u8 { |
| 177 | 177 | test "peer type resolution: [0]u8, []const u8, and %[]u8" { |
| 178 | 178 | { |
| 179 | 179 | var data = "hi"; |
| 180 | const slice = data[0...]; | |
| 180 | const slice = data[0..]; | |
| 181 | 181 | assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); |
| 182 | 182 | assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); |
| 183 | 183 | } |
| 184 | 184 | comptime { |
| 185 | 185 | var data = "hi"; |
| 186 | const slice = data[0...]; | |
| 186 | const slice = data[0..]; | |
| 187 | 187 | assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); |
| 188 | 188 | assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); |
| 189 | 189 | } |
| ... | ... | @@ -193,7 +193,7 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 { |
| 193 | 193 | return []u8{}; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | return slice[0...1]; | |
| 196 | return slice[0..1]; | |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | test "resolve undefined with integer" { |
test/cases/const_slice_child.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ fn bar(argc: usize) { |
| 24 | 24 | const args = %%debug.global_allocator.alloc([]const u8, argc); |
| 25 | 25 | for (args) |_, i| { |
| 26 | 26 | const ptr = argv[i]; |
| 27 | args[i] = ptr[0...strlen(ptr)]; | |
| 27 | args[i] = ptr[0..strlen(ptr)]; | |
| 28 | 28 | } |
| 29 | 29 | foo(args); |
| 30 | 30 | } |
test/cases/enum_with_members.zig+4-4| ... | ... | @@ -19,9 +19,9 @@ test "enumWithMembers" { |
| 19 | 19 | const b = ET.UINT { 42 }; |
| 20 | 20 | var buf: [20]u8 = undefined; |
| 21 | 21 | |
| 22 | assert(%%a.print(buf[0...]) == 3); | |
| 23 | assert(mem.eql(u8, buf[0...3], "-42")); | |
| 22 | assert(%%a.print(buf[0..]) == 3); | |
| 23 | assert(mem.eql(u8, buf[0..3], "-42")); | |
| 24 | 24 | |
| 25 | assert(%%b.print(buf[0...]) == 2); | |
| 26 | assert(mem.eql(u8, buf[0...2], "42")); | |
| 25 | assert(%%b.print(buf[0..]) == 2); | |
| 26 | assert(mem.eql(u8, buf[0..2], "42")); | |
| 27 | 27 | } |
test/cases/eval.zig+2-2| ... | ... | @@ -145,7 +145,7 @@ test "constSlice" { |
| 145 | 145 | comptime { |
| 146 | 146 | const a = "1234567890"; |
| 147 | 147 | assert(a.len == 10); |
| 148 | const b = a[1...2]; | |
| 148 | const b = a[1..2]; | |
| 149 | 149 | assert(b.len == 1); |
| 150 | 150 | assert(b[0] == '2'); |
| 151 | 151 | } |
| ... | ... | @@ -255,7 +255,7 @@ test "callMethodOnBoundFnReferringToVarInstance" { |
| 255 | 255 | test "ptrToLocalArrayArgumentAtComptime" { |
| 256 | 256 | comptime { |
| 257 | 257 | var bytes: [10]u8 = undefined; |
| 258 | modifySomeBytes(bytes[0...]); | |
| 258 | modifySomeBytes(bytes[0..]); | |
| 259 | 259 | assert(bytes[0] == 'a'); |
| 260 | 260 | assert(bytes[9] == 'b'); |
| 261 | 261 | } |
test/cases/for.zig+3-3| ... | ... | @@ -18,8 +18,8 @@ test "continueInForLoop" { |
| 18 | 18 | test "forLoopWithPointerElemVar" { |
| 19 | 19 | const source = "abcdefg"; |
| 20 | 20 | var target: [source.len]u8 = undefined; |
| 21 | mem.copy(u8, target[0...], source); | |
| 22 | mangleString(target[0...]); | |
| 21 | mem.copy(u8, target[0..], source); | |
| 22 | mangleString(target[0..]); | |
| 23 | 23 | assert(mem.eql(u8, target, "bcdefgh")); |
| 24 | 24 | } |
| 25 | 25 | fn mangleString(s: []u8) { |
| ... | ... | @@ -53,5 +53,5 @@ test "basicForLoop" { |
| 53 | 53 | buf_index += 1; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | assert(mem.eql(u8, buffer[0...buf_index], expected_result)); | |
| 56 | assert(mem.eql(u8, buffer[0..buf_index], expected_result)); | |
| 57 | 57 | } |
test/cases/misc.zig+6-6| ... | ... | @@ -173,14 +173,14 @@ test "slicing" { |
| 173 | 173 | |
| 174 | 174 | array[5] = 1234; |
| 175 | 175 | |
| 176 | var slice = array[5...10]; | |
| 176 | var slice = array[5..10]; | |
| 177 | 177 | |
| 178 | 178 | if (slice.len != 5) unreachable; |
| 179 | 179 | |
| 180 | 180 | const ptr = &slice[0]; |
| 181 | 181 | if (ptr[0] != 1234) unreachable; |
| 182 | 182 | |
| 183 | var slice_rest = array[10...]; | |
| 183 | var slice_rest = array[10..]; | |
| 184 | 184 | if (slice_rest.len != 10) unreachable; |
| 185 | 185 | } |
| 186 | 186 | |
| ... | ... | @@ -260,7 +260,7 @@ test "generic malloc free" { |
| 260 | 260 | } |
| 261 | 261 | const some_mem : [100]u8 = undefined; |
| 262 | 262 | fn memAlloc(comptime T: type, n: usize) -> %[]T { |
| 263 | return @ptrCast(&T, &some_mem[0])[0...n]; | |
| 263 | return @ptrCast(&T, &some_mem[0])[0..n]; | |
| 264 | 264 | } |
| 265 | 265 | fn memFree(comptime T: type, memory: []T) { } |
| 266 | 266 | |
| ... | ... | @@ -396,7 +396,7 @@ test "C string concatenation" { |
| 396 | 396 | test "cast slice to u8 slice" { |
| 397 | 397 | assert(@sizeOf(i32) == 4); |
| 398 | 398 | var big_thing_array = []i32{1, 2, 3, 4}; |
| 399 | const big_thing_slice: []i32 = big_thing_array[0...]; | |
| 399 | const big_thing_slice: []i32 = big_thing_array[0..]; | |
| 400 | 400 | const bytes = ([]u8)(big_thing_slice); |
| 401 | 401 | assert(bytes.len == 4 * 4); |
| 402 | 402 | bytes[4] = 0; |
| ... | ... | @@ -509,9 +509,9 @@ test "volatile load and store" { |
| 509 | 509 | |
| 510 | 510 | test "slice string literal has type []const u8" { |
| 511 | 511 | comptime { |
| 512 | assert(@typeOf("aoeu"[0...]) == []const u8); | |
| 512 | assert(@typeOf("aoeu"[0..]) == []const u8); | |
| 513 | 513 | const array = []i32{1, 2, 3, 4}; |
| 514 | assert(@typeOf(array[0...]) == []const i32); | |
| 514 | assert(@typeOf(array[0..]) == []const i32); | |
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 |
test/cases/slice.zig+2-2| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | |
| 3 | const x = @intToPtr(&i32, 0x1000)[0...0x500]; | |
| 4 | const y = x[0x100...]; | |
| 3 | const x = @intToPtr(&i32, 0x1000)[0..0x500]; | |
| 4 | const y = x[0x100..]; | |
| 5 | 5 | test "compile time slice of pointer to hard coded address" { |
| 6 | 6 | assert(usize(x.ptr) == 0x1000); |
| 7 | 7 | assert(x.len == 0x500); |
test/cases/struct.zig+2-2| ... | ... | @@ -305,7 +305,7 @@ test "packedArray24Bits" { |
| 305 | 305 | |
| 306 | 306 | var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1); |
| 307 | 307 | bytes[bytes.len - 1] = 0xaa; |
| 308 | const ptr = &([]FooArray24Bits)(bytes[0...bytes.len - 1])[0]; | |
| 308 | const ptr = &([]FooArray24Bits)(bytes[0..bytes.len - 1])[0]; | |
| 309 | 309 | assert(ptr.a == 0); |
| 310 | 310 | assert(ptr.b[0].field == 0); |
| 311 | 311 | assert(ptr.b[1].field == 0); |
| ... | ... | @@ -354,7 +354,7 @@ test "alignedArrayOfPackedStruct" { |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned); |
| 357 | const ptr = &([]FooArrayOfAligned)(bytes[0...bytes.len])[0]; | |
| 357 | const ptr = &([]FooArrayOfAligned)(bytes[0..bytes.len])[0]; | |
| 358 | 358 | |
| 359 | 359 | assert(ptr.a[0].a == 0xbb); |
| 360 | 360 | assert(ptr.a[0].b == 0xbb); |
test/cases/struct_contains_slice_of_itself.zig+2-2| ... | ... | @@ -27,12 +27,12 @@ test "struct contains slice of itself" { |
| 27 | 27 | }, |
| 28 | 28 | Node { |
| 29 | 29 | .payload = 3, |
| 30 | .children = other_nodes[0...], | |
| 30 | .children = other_nodes[0..], | |
| 31 | 31 | }, |
| 32 | 32 | }; |
| 33 | 33 | const root = Node { |
| 34 | 34 | .payload = 1234, |
| 35 | .children = nodes[0...], | |
| 35 | .children = nodes[0..], | |
| 36 | 36 | }; |
| 37 | 37 | assert(root.payload == 1234); |
| 38 | 38 | assert(root.children[0].payload == 1); |
test/compile_errors.zig+2-2| ... | ... | @@ -1112,7 +1112,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1112 | 1112 | cases.add("bogus method call on slice", |
| 1113 | 1113 | \\var self = "aoeu"; |
| 1114 | 1114 | \\fn f(m: []const u8) { |
| 1115 | \\ m.copy(u8, self[0...], m); | |
| 1115 | \\ m.copy(u8, self[0..], m); | |
| 1116 | 1116 | \\} |
| 1117 | 1117 | \\export fn entry() -> usize { @sizeOf(@typeOf(f)) } |
| 1118 | 1118 | , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'"); |
| ... | ... | @@ -1467,7 +1467,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1467 | 1467 | \\pub fn pass(in: []u8) -> []u8 { |
| 1468 | 1468 | \\ var out = &s_buffer; |
| 1469 | 1469 | \\ *out[0] = in[0]; |
| 1470 | \\ return (*out)[0...1]; | |
| 1470 | \\ return (*out)[0..1]; | |
| 1471 | 1471 | \\} |
| 1472 | 1472 | \\ |
| 1473 | 1473 | \\export fn entry() -> usize { @sizeOf(@typeOf(pass)) } |