mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Core library clean up: Make range expressions more consistent and replace uses of .. with ..=
This commit is contained in:
@@ -91,7 +91,7 @@ equal_fold :: proc(u, v: []byte) -> bool {
|
|||||||
|
|
||||||
if tr < utf8.RUNE_SELF {
|
if tr < utf8.RUNE_SELF {
|
||||||
switch sr {
|
switch sr {
|
||||||
case 'A'..'Z':
|
case 'A'..='Z':
|
||||||
if tr == (sr+'a')-'A' {
|
if tr == (sr+'a')-'A' {
|
||||||
continue loop;
|
continue loop;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,18 +139,18 @@ append_token :: proc(a, b: ^Token) -> ^Token {
|
|||||||
|
|
||||||
is_hex_digit :: proc(x: byte) -> bool {
|
is_hex_digit :: proc(x: byte) -> bool {
|
||||||
switch x {
|
switch x {
|
||||||
case '0'..'9', 'a'..'f', 'A'..'F':
|
case '0'..='9', 'a'..='f', 'A'..='F':
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
from_hex :: proc(x: byte) -> i32 {
|
from_hex :: proc(x: byte) -> i32 {
|
||||||
switch x {
|
switch x {
|
||||||
case '0'..'9':
|
case '0'..='9':
|
||||||
return i32(x) - '0';
|
return i32(x) - '0';
|
||||||
case 'a'..'f':
|
case 'a'..='f':
|
||||||
return i32(x) - 'a' + 10;
|
return i32(x) - 'a' + 10;
|
||||||
case 'A'..'F':
|
case 'A'..='F':
|
||||||
return i32(x) - 'A' + 10;
|
return i32(x) - 'A' + 10;
|
||||||
}
|
}
|
||||||
return 16;
|
return 16;
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import "core:unicode/utf8"
|
|||||||
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
|
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
|
||||||
hex_to_int :: proc(c: byte) -> int {
|
hex_to_int :: proc(c: byte) -> int {
|
||||||
switch c {
|
switch c {
|
||||||
case '0'..'9': return int(c-'0');
|
case '0'..='9': return int(c-'0');
|
||||||
case 'a'..'f': return int(c-'a')+10;
|
case 'a'..='f': return int(c-'a')+10;
|
||||||
case 'A'..'F': return int(c-'A')+10;
|
case 'A'..='F': return int(c-'A')+10;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool
|
|||||||
case '"': r = '"';
|
case '"': r = '"';
|
||||||
case '\'': r = '\'';
|
case '\'': r = '\'';
|
||||||
|
|
||||||
case '0'..'7':
|
case '0'..='7':
|
||||||
v := int(c-'0');
|
v := int(c-'0');
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -224,11 +224,11 @@ scan_string :: proc(t: ^Tokenizer) -> string {
|
|||||||
|
|
||||||
digit_val :: proc(r: rune) -> int {
|
digit_val :: proc(r: rune) -> int {
|
||||||
switch r {
|
switch r {
|
||||||
case '0'..'9':
|
case '0'..='9':
|
||||||
return int(r-'0');
|
return int(r-'0');
|
||||||
case 'A'..'F':
|
case 'A'..='F':
|
||||||
return int(r-'A' + 10);
|
return int(r-'A' + 10);
|
||||||
case 'a'..'f':
|
case 'a'..='f':
|
||||||
return int(r-'a' + 10);
|
return int(r-'a' + 10);
|
||||||
}
|
}
|
||||||
return 16;
|
return 16;
|
||||||
@@ -245,7 +245,7 @@ scan_escape :: proc(t: ^Tokenizer) -> bool {
|
|||||||
advance_rune(t);
|
advance_rune(t);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case '0'..'7':
|
case '0'..='7':
|
||||||
for digit_val(t.ch) < 8 {
|
for digit_val(t.ch) < 8 {
|
||||||
advance_rune(t);
|
advance_rune(t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,11 +288,11 @@ load_from_stream :: proc(stream: io.Stream, buf: ^bytes.Buffer, allocator := con
|
|||||||
|
|
||||||
payload_crc_b: [4]u8;
|
payload_crc_b: [4]u8;
|
||||||
payload_len_b: [4]u8;
|
payload_len_b: [4]u8;
|
||||||
for i in 0..3 {
|
for _, i in payload_crc_b {
|
||||||
payload_crc_b[i] = u8(compress.read_bits_lsb(&ctx, 8));
|
payload_crc_b[i] = u8(compress.read_bits_lsb(&ctx, 8));
|
||||||
}
|
}
|
||||||
payload_crc := transmute(u32le)payload_crc_b;
|
payload_crc := transmute(u32le)payload_crc_b;
|
||||||
for i in 0..3 {
|
for _, i in payload_len_b {
|
||||||
payload_len_b[i] = u8(compress.read_bits_lsb(&ctx, 8));
|
payload_len_b[i] = u8(compress.read_bits_lsb(&ctx, 8));
|
||||||
}
|
}
|
||||||
payload_len := int(transmute(u32le)payload_len_b);
|
payload_len := int(transmute(u32le)payload_len_b);
|
||||||
|
|||||||
@@ -133,9 +133,7 @@ write_byte :: #force_inline proc(z: ^Context, c: u8) -> (err: io.Error) #no_boun
|
|||||||
}
|
}
|
||||||
|
|
||||||
allocate_huffman_table :: proc(allocator := context.allocator) -> (z: ^Huffman_Table, err: Error) {
|
allocate_huffman_table :: proc(allocator := context.allocator) -> (z: ^Huffman_Table, err: Error) {
|
||||||
|
return new(Huffman_Table, allocator), nil;
|
||||||
z = new(Huffman_Table, allocator);
|
|
||||||
return z, nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
||||||
@@ -152,14 +150,14 @@ build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
|||||||
}
|
}
|
||||||
sizes[0] = 0;
|
sizes[0] = 0;
|
||||||
|
|
||||||
for i in 1..16 {
|
for i in 1..<(HUFFMAN_MAX_BITS+1) {
|
||||||
if sizes[i] > (1 << uint(i)) {
|
if sizes[i] > (1 << uint(i)) {
|
||||||
return E_Deflate.Huffman_Bad_Sizes;
|
return E_Deflate.Huffman_Bad_Sizes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
code := int(0);
|
code := int(0);
|
||||||
|
|
||||||
for i in 1..<16 {
|
for i in 1..<HUFFMAN_MAX_BITS {
|
||||||
next_code[i] = code;
|
next_code[i] = code;
|
||||||
z.firstcode[i] = u16(code);
|
z.firstcode[i] = u16(code);
|
||||||
z.firstsymbol[i] = u16(k);
|
z.firstsymbol[i] = u16(k);
|
||||||
@@ -169,12 +167,12 @@ build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
|||||||
return E_Deflate.Huffman_Bad_Code_Lengths;
|
return E_Deflate.Huffman_Bad_Code_Lengths;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
z.maxcode[i] = code << (16 - uint(i));
|
z.maxcode[i] = code << (HUFFMAN_MAX_BITS - uint(i));
|
||||||
code <<= 1;
|
code <<= 1;
|
||||||
k += int(sizes[i]);
|
k += int(sizes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
z.maxcode[16] = 0x10000; // Sentinel
|
z.maxcode[HUFFMAN_MAX_BITS] = 0x10000; // Sentinel
|
||||||
c: int;
|
c: int;
|
||||||
|
|
||||||
for v, ci in code_lengths {
|
for v, ci in code_lengths {
|
||||||
@@ -197,7 +195,6 @@ build_huffman :: proc(z: ^Huffman_Table, code_lengths: []u8) -> (err: Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decode_huffman_slowpath :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
decode_huffman_slowpath :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
err = nil;
|
err = nil;
|
||||||
|
|
||||||
@@ -233,7 +230,6 @@ decode_huffman_slowpath :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
decode_huffman :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
decode_huffman :: proc(z: ^Context, t: ^Huffman_Table) -> (r: u16, err: Error) #no_bounds_check {
|
||||||
|
|
||||||
if z.num_bits < 16 {
|
if z.num_bits < 16 {
|
||||||
if z.num_bits == -100 {
|
if z.num_bits == -100 {
|
||||||
return 0, E_ZLIB.Code_Buffer_Malformed;
|
return 0, E_ZLIB.Code_Buffer_Malformed;
|
||||||
|
|||||||
@@ -201,9 +201,9 @@ next_token :: proc(p: ^Parser) -> Token {
|
|||||||
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
|
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
|
||||||
hex_to_int :: proc(c: byte) -> int {
|
hex_to_int :: proc(c: byte) -> int {
|
||||||
switch c {
|
switch c {
|
||||||
case '0'..'9': return int(c-'0');
|
case '0'..='9': return int(c-'0');
|
||||||
case 'a'..'f': return int(c-'a')+10;
|
case 'a'..='f': return int(c-'a')+10;
|
||||||
case 'A'..'F': return int(c-'A')+10;
|
case 'A'..='F': return int(c-'A')+10;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool
|
|||||||
case '"': r = '"';
|
case '"': r = '"';
|
||||||
case '\'': r = '\'';
|
case '\'': r = '\'';
|
||||||
|
|
||||||
case '0'..'7':
|
case '0'..='7':
|
||||||
v := int(c-'0');
|
v := int(c-'0');
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ get_pos :: proc(t: ^Tokenizer) -> Pos {
|
|||||||
|
|
||||||
is_letter :: proc(r: rune) -> bool {
|
is_letter :: proc(r: rune) -> bool {
|
||||||
switch r {
|
switch r {
|
||||||
case 'a'..'z', 'A'..'Z', '_':
|
case 'a'..='z', 'A'..='Z', '_':
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -240,7 +240,7 @@ is_letter :: proc(r: rune) -> bool {
|
|||||||
|
|
||||||
is_digit :: proc(r: rune) -> bool {
|
is_digit :: proc(r: rune) -> bool {
|
||||||
switch r {
|
switch r {
|
||||||
case '0'..'9':
|
case '0'..='9':
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -273,9 +273,9 @@ scan_identifier :: proc(t: ^Tokenizer) -> string {
|
|||||||
|
|
||||||
digit_value :: proc(r: rune) -> int {
|
digit_value :: proc(r: rune) -> int {
|
||||||
switch r {
|
switch r {
|
||||||
case '0'..'9': return int(r - '0');
|
case '0'..='9': return int(r - '0');
|
||||||
case 'a'..'f': return int(r - 'a' + 10);
|
case 'a'..='f': return int(r - 'a' + 10);
|
||||||
case 'A'..'F': return int(r - 'A' + 10);
|
case 'A'..='F': return int(r - 'A' + 10);
|
||||||
}
|
}
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -290,9 +290,9 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
|
|||||||
for c in s[2:4] {
|
for c in s[2:4] {
|
||||||
x: rune;
|
x: rune;
|
||||||
switch c {
|
switch c {
|
||||||
case '0'..'9': x = c - '0';
|
case '0'..='9': x = c - '0';
|
||||||
case 'a'..'f': x = c - 'a' + 10;
|
case 'a'..='f': x = c - 'a' + 10;
|
||||||
case 'A'..'F': x = c - 'A' + 10;
|
case 'A'..='F': x = c - 'A' + 10;
|
||||||
case: return -1;
|
case: return -1;
|
||||||
}
|
}
|
||||||
r = r*16 + x;
|
r = r*16 + x;
|
||||||
@@ -308,9 +308,9 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
|
|||||||
for c in s[2:6] {
|
for c in s[2:6] {
|
||||||
x: rune;
|
x: rune;
|
||||||
switch c {
|
switch c {
|
||||||
case '0'..'9': x = c - '0';
|
case '0'..='9': x = c - '0';
|
||||||
case 'a'..'f': x = c - 'a' + 10;
|
case 'a'..='f': x = c - 'a' + 10;
|
||||||
case 'A'..'F': x = c - 'A' + 10;
|
case 'A'..='F': x = c - 'A' + 10;
|
||||||
case: return -1;
|
case: return -1;
|
||||||
}
|
}
|
||||||
r = r*16 + x;
|
r = r*16 + x;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
|
|||||||
for t.offset < len(t.data) {
|
for t.offset < len(t.data) {
|
||||||
next_rune(t);
|
next_rune(t);
|
||||||
switch t.r {
|
switch t.r {
|
||||||
case '0'..'9', 'a'..'f', 'A'..'F':
|
case '0'..='9', 'a'..='f', 'A'..='F':
|
||||||
// Okay
|
// Okay
|
||||||
case:
|
case:
|
||||||
return;
|
return;
|
||||||
@@ -100,7 +100,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
|
|||||||
for i := 0; i < 4; i += 1 {
|
for i := 0; i < 4; i += 1 {
|
||||||
r := next_rune(t);
|
r := next_rune(t);
|
||||||
switch r {
|
switch r {
|
||||||
case '0'..'9', 'a'..'f', 'A'..'F':
|
case '0'..='9', 'a'..='f', 'A'..='F':
|
||||||
// Okay
|
// Okay
|
||||||
case:
|
case:
|
||||||
return false;
|
return false;
|
||||||
@@ -149,7 +149,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
|
|||||||
skip_alphanum :: proc(t: ^Tokenizer) {
|
skip_alphanum :: proc(t: ^Tokenizer) {
|
||||||
for t.offset < len(t.data) {
|
for t.offset < len(t.data) {
|
||||||
switch next_rune(t) {
|
switch next_rune(t) {
|
||||||
case 'A'..'Z', 'a'..'z', '0'..'9', '_':
|
case 'A'..='Z', 'a'..='z', '0'..='9', '_':
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
|
|||||||
token.kind = .EOF;
|
token.kind = .EOF;
|
||||||
err = .EOF;
|
err = .EOF;
|
||||||
|
|
||||||
case 'A'..'Z', 'a'..'z', '_':
|
case 'A'..='Z', 'a'..='z', '_':
|
||||||
token.kind = .Ident;
|
token.kind = .Ident;
|
||||||
|
|
||||||
skip_alphanum(t);
|
skip_alphanum(t);
|
||||||
@@ -200,7 +200,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
|
|||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
switch t.r {
|
switch t.r {
|
||||||
case '0'..'9':
|
case '0'..='9':
|
||||||
// Okay
|
// Okay
|
||||||
case:
|
case:
|
||||||
// Illegal use of +/-
|
// Illegal use of +/-
|
||||||
@@ -219,7 +219,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
|
|||||||
}
|
}
|
||||||
fallthrough;
|
fallthrough;
|
||||||
|
|
||||||
case '0'..'9':
|
case '0'..='9':
|
||||||
token.kind = t.parse_integers ? .Integer : .Float;
|
token.kind = t.parse_integers ? .Integer : .Float;
|
||||||
if t.spec == .JSON5 { // Hexadecimal Numbers
|
if t.spec == .JSON5 { // Hexadecimal Numbers
|
||||||
if curr_rune == '0' && (t.r == 'x' || t.r == 'X') {
|
if curr_rune == '0' && (t.r == 'x' || t.r == 'X') {
|
||||||
@@ -361,7 +361,7 @@ is_valid_number :: proc(str: string, spec: Specification) -> bool {
|
|||||||
switch s[0] {
|
switch s[0] {
|
||||||
case '0':
|
case '0':
|
||||||
s = s[1:];
|
s = s[1:];
|
||||||
case '1'..'9':
|
case '1'..='9':
|
||||||
s = s[1:];
|
s = s[1:];
|
||||||
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
|
for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
|
||||||
s = s[1:];
|
s = s[1:];
|
||||||
@@ -453,7 +453,7 @@ is_valid_string_literal :: proc(str: string, spec: Specification) -> bool {
|
|||||||
for j := 0; j < 4; j += 1 {
|
for j := 0; j < 4; j += 1 {
|
||||||
c2 := hex[j];
|
c2 := hex[j];
|
||||||
switch c2 {
|
switch c2 {
|
||||||
case '0'..'9', 'a'..'z', 'A'..'Z':
|
case '0'..='9', 'a'..='z', 'A'..='Z':
|
||||||
// Okay
|
// Okay
|
||||||
case:
|
case:
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+10
-10
@@ -1348,31 +1348,31 @@ defilter_less_than_8 :: proc(params: ^Filter_Params) -> (ok: bool) #no_bounds_ch
|
|||||||
case .None:
|
case .None:
|
||||||
copy(dest, src[:row_stride_in]);
|
copy(dest, src[:row_stride_in]);
|
||||||
case .Sub:
|
case .Sub:
|
||||||
for i in 0..channels {
|
for i in 0..=channels {
|
||||||
dest[i] = src[i];
|
dest[i] = src[i];
|
||||||
}
|
}
|
||||||
for k in 0..nk {
|
for k in 0..=nk {
|
||||||
dest[channels+k] = (src[channels+k] + dest[k]) & 255;
|
dest[channels+k] = (src[channels+k] + dest[k]) & 255;
|
||||||
}
|
}
|
||||||
case .Up:
|
case .Up:
|
||||||
for k in 0..row_stride_in {
|
for k in 0..=row_stride_in {
|
||||||
dest[k] = (src[k] + up[k]) & 255;
|
dest[k] = (src[k] + up[k]) & 255;
|
||||||
}
|
}
|
||||||
case .Average:
|
case .Average:
|
||||||
for i in 0..channels {
|
for i in 0..=channels {
|
||||||
avg := up[i] >> 1;
|
avg := up[i] >> 1;
|
||||||
dest[i] = (src[i] + avg) & 255;
|
dest[i] = (src[i] + avg) & 255;
|
||||||
}
|
}
|
||||||
for k in 0..nk {
|
for k in 0..=nk {
|
||||||
avg := u8((u16(up[channels+k]) + u16(dest[k])) >> 1);
|
avg := u8((u16(up[channels+k]) + u16(dest[k])) >> 1);
|
||||||
dest[channels+k] = (src[channels+k] + avg) & 255;
|
dest[channels+k] = (src[channels+k] + avg) & 255;
|
||||||
}
|
}
|
||||||
case .Paeth:
|
case .Paeth:
|
||||||
for i in 0..channels {
|
for i in 0..=channels {
|
||||||
paeth := filter_paeth(0, up[i], 0);
|
paeth := filter_paeth(0, up[i], 0);
|
||||||
dest[i] = (src[i] + paeth) & 255;
|
dest[i] = (src[i] + paeth) & 255;
|
||||||
}
|
}
|
||||||
for k in 0..nk {
|
for k in 0..=nk {
|
||||||
paeth := filter_paeth(dest[k], up[channels+k], up[k]);
|
paeth := filter_paeth(dest[k], up[channels+k], up[k]);
|
||||||
dest[channels+k] = (src[channels+k] + paeth) & 255;
|
dest[channels+k] = (src[channels+k] + paeth) & 255;
|
||||||
}
|
}
|
||||||
@@ -1380,9 +1380,9 @@ defilter_less_than_8 :: proc(params: ^Filter_Params) -> (ok: bool) #no_bounds_ch
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
src = src [row_stride_in:];
|
src = src[row_stride_in:];
|
||||||
up = dest;
|
up = dest;
|
||||||
dest = dest[row_stride_in:];
|
dest = dest[row_stride_in:];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's expand the bits
|
// Let's expand the bits
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ is_abs :: proc(path: string) -> bool {
|
|||||||
when ODIN_OS == "windows" {
|
when ODIN_OS == "windows" {
|
||||||
if len(path) > 2 {
|
if len(path) > 2 {
|
||||||
switch path[0] {
|
switch path[0] {
|
||||||
case 'A'..'Z', 'a'..'z':
|
case 'A'..='Z', 'a'..='z':
|
||||||
return path[1] == ':' && is_path_separator(path[2]);
|
return path[1] == ':' && is_path_separator(path[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ _is_abs :: proc(path: string) -> bool {
|
|||||||
}
|
}
|
||||||
if len(path) > 2 {
|
if len(path) > 2 {
|
||||||
switch path[0] {
|
switch path[0] {
|
||||||
case 'A'..'Z', 'a'..'z':
|
case 'A'..='Z', 'a'..='z':
|
||||||
return path[1] == ':' && is_path_separator(path[2]);
|
return path[1] == ':' && is_path_separator(path[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ volume_name_len :: proc(path: string) -> int {
|
|||||||
c := path[0];
|
c := path[0];
|
||||||
if path[1] == ':' {
|
if path[1] == ':' {
|
||||||
switch c {
|
switch c {
|
||||||
case 'a'..'z', 'A'..'Z':
|
case 'a'..='z', 'A'..='Z':
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ _digit_value :: proc(r: rune) -> int {
|
|||||||
ri := int(r);
|
ri := int(r);
|
||||||
v: int = 16;
|
v: int = 16;
|
||||||
switch r {
|
switch r {
|
||||||
case '0'..'9': v = ri-'0';
|
case '0'..='9': v = ri-'0';
|
||||||
case 'a'..'z': v = ri-'a'+10;
|
case 'a'..='z': v = ri-'a'+10;
|
||||||
case 'A'..'Z': v = ri-'A'+10;
|
case 'A'..='Z': v = ri-'A'+10;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -557,9 +557,9 @@ quote_rune :: proc(buf: []byte, r: rune) -> string {
|
|||||||
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
|
unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {
|
||||||
hex_to_int :: proc(c: byte) -> int {
|
hex_to_int :: proc(c: byte) -> int {
|
||||||
switch c {
|
switch c {
|
||||||
case '0'..'9': return int(c-'0');
|
case '0'..='9': return int(c-'0');
|
||||||
case 'a'..'f': return int(c-'a')+10;
|
case 'a'..='f': return int(c-'a')+10;
|
||||||
case 'A'..'F': return int(c-'A')+10;
|
case 'A'..='F': return int(c-'A')+10;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -597,7 +597,7 @@ unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool
|
|||||||
case '"': r = '"';
|
case '"': r = '"';
|
||||||
case '\'': r = '\'';
|
case '\'': r = '\'';
|
||||||
|
|
||||||
case '0'..'7':
|
case '0'..='7':
|
||||||
v := int(c-'0');
|
v := int(c-'0');
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -314,9 +314,9 @@ write_escaped_rune_writer :: proc(w: io.Writer, r: rune, quote: byte, html_safe
|
|||||||
is_printable :: proc(r: rune) -> bool {
|
is_printable :: proc(r: rune) -> bool {
|
||||||
if r <= 0xff {
|
if r <= 0xff {
|
||||||
switch r {
|
switch r {
|
||||||
case 0x20..0x7e:
|
case 0x20..=0x7e:
|
||||||
return true;
|
return true;
|
||||||
case 0xa1..0xff: // ¡ through ÿ except for the soft hyphen
|
case 0xa1..=0xff: // ¡ through ÿ except for the soft hyphen
|
||||||
return r != 0xad; //
|
return r != 0xad; //
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ is_delimiter :: proc(c: rune) -> bool {
|
|||||||
is_separator :: proc(r: rune) -> bool {
|
is_separator :: proc(r: rune) -> bool {
|
||||||
if r <= 0x7f {
|
if r <= 0x7f {
|
||||||
switch r {
|
switch r {
|
||||||
case '0'..'9': return false;
|
case '0'..='9': return false;
|
||||||
case 'a'..'z': return false;
|
case 'a'..='z': return false;
|
||||||
case 'A'..'Z': return false;
|
case 'A'..='Z': return false;
|
||||||
case '_': return false;
|
case '_': return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ equal_fold :: proc(u, v: string) -> bool {
|
|||||||
|
|
||||||
if tr < utf8.RUNE_SELF {
|
if tr < utf8.RUNE_SELF {
|
||||||
switch sr {
|
switch sr {
|
||||||
case 'A'..'Z':
|
case 'A'..='Z':
|
||||||
if tr == (sr+'a')-'A' {
|
if tr == (sr+'a')-'A' {
|
||||||
continue loop;
|
continue loop;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ semaphore_destroy :: proc(s: ^Semaphore) {
|
|||||||
|
|
||||||
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
||||||
// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
|
// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
|
||||||
for in 0..count-1 {
|
for in 0..<count {
|
||||||
res := darwin.semaphore_signal(s.handle);
|
res := darwin.semaphore_signal(s.handle);
|
||||||
assert(res == 0);
|
assert(res == 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ semaphore_destroy :: proc(s: ^Semaphore) {
|
|||||||
|
|
||||||
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
||||||
// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
|
// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
|
||||||
for in 0..count-1 {
|
for in 0..<count {
|
||||||
assert(unix.sem_post(&s.handle) == 0);
|
assert(unix.sem_post(&s.handle) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ semaphore_destroy :: proc(s: ^Semaphore) {
|
|||||||
|
|
||||||
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
||||||
// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
|
// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
|
||||||
for in 0..count-1 {
|
for in 0..<count {
|
||||||
assert(unix.sem_post(&s.handle) == 0);
|
assert(unix.sem_post(&s.handle) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -421,8 +421,8 @@ scan_number :: proc(s: ^Scanner, ch: rune, seen_dot: bool) -> (rune, rune) {
|
|||||||
scan_string :: proc(s: ^Scanner, quote: rune) -> (n: int) {
|
scan_string :: proc(s: ^Scanner, quote: rune) -> (n: int) {
|
||||||
digit_val :: proc(ch: rune) -> int {
|
digit_val :: proc(ch: rune) -> int {
|
||||||
switch v := lower(ch); v {
|
switch v := lower(ch); v {
|
||||||
case '0'..'9': return int(v - '0');
|
case '0'..='9': return int(v - '0');
|
||||||
case 'a'..'z': return int(v - 'a');
|
case 'a'..='z': return int(v - 'a');
|
||||||
}
|
}
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
@@ -450,10 +450,10 @@ scan_string :: proc(s: ^Scanner, quote: rune) -> (n: int) {
|
|||||||
switch ch {
|
switch ch {
|
||||||
case quote, 'a', 'b', 'e', 'f', 'n', 'r', 't', 'v', '\\':
|
case quote, 'a', 'b', 'e', 'f', 'n', 'r', 't', 'v', '\\':
|
||||||
ch = advance(s);
|
ch = advance(s);
|
||||||
case '0'..'7': ch = scan_digits(s, advance(s), 8, 3);
|
case '0'..='7': ch = scan_digits(s, advance(s), 8, 3);
|
||||||
case 'x': ch = scan_digits(s, advance(s), 16, 2);
|
case 'x': ch = scan_digits(s, advance(s), 16, 2);
|
||||||
case 'u': ch = scan_digits(s, advance(s), 16, 4);
|
case 'u': ch = scan_digits(s, advance(s), 16, 4);
|
||||||
case 'U': ch = scan_digits(s, advance(s), 16, 8);
|
case 'U': ch = scan_digits(s, advance(s), 16, 8);
|
||||||
case:
|
case:
|
||||||
error(s, "invalid char escape");
|
error(s, "invalid char escape");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ encode :: proc(d: []u16, s: []rune) -> int {
|
|||||||
d[n] = u16(r);
|
d[n] = u16(r);
|
||||||
n += 1;
|
n += 1;
|
||||||
|
|
||||||
case _surr_self .. MAX_RUNE:
|
case _surr_self ..= MAX_RUNE:
|
||||||
if m+2 < n { break loop; }
|
if m+2 < n { break loop; }
|
||||||
r1, r2 := encode_surrogate_pair(r);
|
r1, r2 := encode_surrogate_pair(r);
|
||||||
d[n] = u16(r1);
|
d[n] = u16(r1);
|
||||||
@@ -65,7 +65,7 @@ encode_string :: proc(d: []u16, s: string) -> int {
|
|||||||
d[n] = u16(r);
|
d[n] = u16(r);
|
||||||
n += 1;
|
n += 1;
|
||||||
|
|
||||||
case _surr_self .. MAX_RUNE:
|
case _surr_self ..= MAX_RUNE:
|
||||||
if m+2 < n { break loop; }
|
if m+2 < n { break loop; }
|
||||||
r1, r2 := encode_surrogate_pair(r);
|
r1, r2 := encode_surrogate_pair(r);
|
||||||
d[n] = u16(r1);
|
d[n] = u16(r1);
|
||||||
|
|||||||
Reference in New Issue
Block a user