| author | |
| committer | |
| log | 6b7d9b34e8fcefa731800cef883c2400f9f39de5 |
| tree | 695fc1d564a2bc590d9c87bca57f825d4027716e |
| parent | f7fea080b25f932b352d38f126e0a179c5163f68 |
7 files changed, 14 insertions(+), 115 deletions(-)
lib/std/SemanticVersion.zig+2-2| ... | ... | @@ -114,7 +114,7 @@ pub fn parse(text: []const u8) !Version { |
| 114 | 114 | if (id.len == 0) return error.InvalidVersion; |
| 115 | 115 | |
| 116 | 116 | // Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]. |
| 117 | for (id) |c| if (!std.ascii.isAlNum(c) and c != '-') return error.InvalidVersion; | |
| 117 | for (id) |c| if (!std.ascii.isAlphanumeric(c) and c != '-') return error.InvalidVersion; | |
| 118 | 118 | |
| 119 | 119 | // Numeric identifiers MUST NOT include leading zeroes. |
| 120 | 120 | const is_num = for (id) |c| { |
| ... | ... | @@ -133,7 +133,7 @@ pub fn parse(text: []const u8) !Version { |
| 133 | 133 | if (id.len == 0) return error.InvalidVersion; |
| 134 | 134 | |
| 135 | 135 | // Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]. |
| 136 | for (id) |c| if (!std.ascii.isAlNum(c) and c != '-') return error.InvalidVersion; | |
| 136 | for (id) |c| if (!std.ascii.isAlphanumeric(c) and c != '-') return error.InvalidVersion; | |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 |
lib/std/ascii.zig+3-104| ... | ... | @@ -10,83 +10,10 @@ |
| 10 | 10 | |
| 11 | 11 | const std = @import("std"); |
| 12 | 12 | |
| 13 | // TODO: remove all decls marked as DEPRECATED after 0.10.0's release | |
| 14 | ||
| 15 | 13 | /// The C0 control codes of the ASCII encoding. |
| 16 | 14 | /// |
| 17 | 15 | /// See also: https://en.wikipedia.org/wiki/C0_and_C1_control_codes and `isControl`. |
| 18 | 16 | pub const control_code = struct { |
| 19 | // DEPRECATED: use the lowercase variant | |
| 20 | pub const NUL = 0x00; | |
| 21 | // DEPRECATED: use the lowercase variant | |
| 22 | pub const SOH = 0x01; | |
| 23 | // DEPRECATED: use the lowercase variant | |
| 24 | pub const STX = 0x02; | |
| 25 | // DEPRECATED: use the lowercase variant | |
| 26 | pub const ETX = 0x03; | |
| 27 | // DEPRECATED: use the lowercase variant | |
| 28 | pub const EOT = 0x04; | |
| 29 | // DEPRECATED: use the lowercase variant | |
| 30 | pub const ENQ = 0x05; | |
| 31 | // DEPRECATED: use the lowercase variant | |
| 32 | pub const ACK = 0x06; | |
| 33 | // DEPRECATED: use the lowercase variant | |
| 34 | pub const BEL = 0x07; | |
| 35 | // DEPRECATED: use the lowercase variant | |
| 36 | pub const BS = 0x08; | |
| 37 | // DEPRECATED: use `ht` | |
| 38 | pub const TAB = 0x09; | |
| 39 | // DEPRECATED: use the lowercase variant | |
| 40 | pub const LF = 0x0A; | |
| 41 | // DEPRECATED: use the lowercase variant | |
| 42 | pub const VT = 0x0B; | |
| 43 | // DEPRECATED: use the lowercase variant | |
| 44 | pub const FF = 0x0C; | |
| 45 | // DEPRECATED: use the lowercase variant | |
| 46 | pub const CR = 0x0D; | |
| 47 | // DEPRECATED: use the lowercase variant | |
| 48 | pub const SO = 0x0E; | |
| 49 | // DEPRECATED: use the lowercase variant | |
| 50 | pub const SI = 0x0F; | |
| 51 | // DEPRECATED: use the lowercase variant | |
| 52 | pub const DLE = 0x10; | |
| 53 | // DEPRECATED: use the lowercase variant | |
| 54 | pub const DC1 = 0x11; | |
| 55 | // DEPRECATED: use the lowercase variant | |
| 56 | pub const DC2 = 0x12; | |
| 57 | // DEPRECATED: use the lowercase variant | |
| 58 | pub const DC3 = 0x13; | |
| 59 | // DEPRECATED: use the lowercase variant | |
| 60 | pub const DC4 = 0x14; | |
| 61 | // DEPRECATED: use the lowercase variant | |
| 62 | pub const NAK = 0x15; | |
| 63 | // DEPRECATED: use the lowercase variant | |
| 64 | pub const SYN = 0x16; | |
| 65 | // DEPRECATED: use the lowercase variant | |
| 66 | pub const ETB = 0x17; | |
| 67 | // DEPRECATED: use the lowercase variant | |
| 68 | pub const CAN = 0x18; | |
| 69 | // DEPRECATED: use the lowercase variant | |
| 70 | pub const EM = 0x19; | |
| 71 | // DEPRECATED: use the lowercase variant | |
| 72 | pub const SUB = 0x1A; | |
| 73 | // DEPRECATED: use the lowercase variant | |
| 74 | pub const ESC = 0x1B; | |
| 75 | // DEPRECATED: use the lowercase variant | |
| 76 | pub const FS = 0x1C; | |
| 77 | // DEPRECATED: use the lowercase variant | |
| 78 | pub const GS = 0x1D; | |
| 79 | // DEPRECATED: use the lowercase variant | |
| 80 | pub const RS = 0x1E; | |
| 81 | // DEPRECATED: use the lowercase variant | |
| 82 | pub const US = 0x1F; | |
| 83 | // DEPRECATED: use the lowercase variant | |
| 84 | pub const DEL = 0x7F; | |
| 85 | // DEPRECATED: use the lowercase variant | |
| 86 | pub const XON = 0x11; | |
| 87 | // DEPRECATED: use the lowercase variant | |
| 88 | pub const XOFF = 0x13; | |
| 89 | ||
| 90 | 17 | /// Null. |
| 91 | 18 | pub const nul = 0x00; |
| 92 | 19 | /// Start of Heading. |
| ... | ... | @@ -298,19 +225,6 @@ fn inTable(c: u8, t: tIndex) bool { |
| 298 | 225 | return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0; |
| 299 | 226 | } |
| 300 | 227 | |
| 301 | /// DEPRECATED: use `isAlphanumeric` | |
| 302 | pub const isAlNum = isAlphanumeric; | |
| 303 | /// DEPRECATED: use `isAlphabetic` | |
| 304 | pub const isAlpha = isAlphabetic; | |
| 305 | /// DEPRECATED: use `isControl` | |
| 306 | pub const isCntrl = isControl; | |
| 307 | /// DEPRECATED: use `isWhitespace`. | |
| 308 | pub const isSpace = isWhitespace; | |
| 309 | /// DEPRECATED: use `whitespace`. | |
| 310 | pub const spaces = whitespace; | |
| 311 | /// DEPRECATED: use `isHex`. | |
| 312 | pub const isXDigit = isHex; | |
| 313 | ||
| 314 | 228 | /// Returns whether the character is alphanumeric. |
| 315 | 229 | pub fn isAlphanumeric(c: u8) bool { |
| 316 | 230 | return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) | |
| ... | ... | @@ -335,11 +249,6 @@ pub fn isDigit(c: u8) bool { |
| 335 | 249 | return inTable(c, tIndex.Digit); |
| 336 | 250 | } |
| 337 | 251 | |
| 338 | /// DEPRECATED: use `isPrint(c) and c != ' '` instead | |
| 339 | pub fn isGraph(c: u8) bool { | |
| 340 | return inTable(c, tIndex.Graph); | |
| 341 | } | |
| 342 | ||
| 343 | 252 | /// Returns whether the character is a lowercased letter. |
| 344 | 253 | pub fn isLower(c: u8) bool { |
| 345 | 254 | return inTable(c, tIndex.Lower); |
| ... | ... | @@ -352,11 +261,6 @@ pub fn isPrint(c: u8) bool { |
| 352 | 261 | return inTable(c, tIndex.Graph) or c == ' '; |
| 353 | 262 | } |
| 354 | 263 | |
| 355 | /// DEPRECATED: create your own function based on your needs and what you want to do. | |
| 356 | pub fn isPunct(c: u8) bool { | |
| 357 | return inTable(c, tIndex.Punct); | |
| 358 | } | |
| 359 | ||
| 360 | 264 | /// Returns whether this character is included in `whitespace`. |
| 361 | 265 | pub fn isWhitespace(c: u8) bool { |
| 362 | 266 | return inTable(c, tIndex.Space); |
| ... | ... | @@ -392,11 +296,6 @@ pub fn isASCII(c: u8) bool { |
| 392 | 296 | return c < 128; |
| 393 | 297 | } |
| 394 | 298 | |
| 395 | /// DEPRECATED: use `c == ' ' or c == '\t'` or try `isWhitespace` | |
| 396 | pub fn isBlank(c: u8) bool { | |
| 397 | return (c == ' ') or (c == '\x09'); | |
| 398 | } | |
| 399 | ||
| 400 | 299 | /// Uppercases the character and returns it as-is if it's already uppercased or not a letter. |
| 401 | 300 | pub fn toUpper(c: u8) u8 { |
| 402 | 301 | if (isLower(c)) { |
| ... | ... | @@ -440,9 +339,9 @@ test "ascii character classes" { |
| 440 | 339 | try testing.expect(isAlphanumeric('5')); |
| 441 | 340 | try testing.expect(!isAlphanumeric('!')); |
| 442 | 341 | |
| 443 | try testing.expect(!isAlpha('5')); | |
| 444 | try testing.expect(isAlpha('c')); | |
| 445 | try testing.expect(!isAlpha('5')); | |
| 342 | try testing.expect(!isAlphabetic('5')); | |
| 343 | try testing.expect(isAlphabetic('c')); | |
| 344 | try testing.expect(!isAlphabetic('5')); | |
| 446 | 345 | |
| 447 | 346 | try testing.expect(isWhitespace(' ')); |
| 448 | 347 | try testing.expect(isWhitespace('\t')); |
lib/std/net.zig+1-1| ... | ... | @@ -1192,7 +1192,7 @@ pub fn isValidHostName(hostname: []const u8) bool { |
| 1192 | 1192 | if (hostname.len >= 254) return false; |
| 1193 | 1193 | if (!std.unicode.utf8ValidateSlice(hostname)) return false; |
| 1194 | 1194 | for (hostname) |byte| { |
| 1195 | if (byte >= 0x80 or byte == '.' or byte == '-' or std.ascii.isAlNum(byte)) { | |
| 1195 | if (!std.ascii.isASCII(byte) or byte == '.' or byte == '-' or std.ascii.isAlphanumeric(byte)) { | |
| 1196 | 1196 | continue; |
| 1197 | 1197 | } |
| 1198 | 1198 | return false; |
lib/std/zig/parse.zig+2-2| ... | ... | @@ -1531,7 +1531,7 @@ const Parser = struct { |
| 1531 | 1531 | // without types we don't know if '&&' was intended as 'bitwise_and address_of', or a c-style logical_and |
| 1532 | 1532 | // The best the parser can do is recommend changing it to 'and' or ' & &' |
| 1533 | 1533 | try p.warnMsg(.{ .tag = .invalid_ampersand_ampersand, .token = oper_token }); |
| 1534 | } else if (std.ascii.isSpace(char_before) != std.ascii.isSpace(char_after)) { | |
| 1534 | } else if (std.ascii.isWhitespace(char_before) != std.ascii.isWhitespace(char_after)) { | |
| 1535 | 1535 | try p.warnMsg(.{ .tag = .mismatched_binary_op_whitespace, .token = oper_token }); |
| 1536 | 1536 | } |
| 1537 | 1537 | } |
| ... | ... | @@ -1728,7 +1728,7 @@ const Parser = struct { |
| 1728 | 1728 | var sentinel: Node.Index = 0; |
| 1729 | 1729 | if (p.eatToken(.identifier)) |ident| { |
| 1730 | 1730 | const ident_slice = p.source[p.token_starts[ident]..p.token_starts[ident + 1]]; |
| 1731 | if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.spaces), "c")) { | |
| 1731 | if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.whitespace), "c")) { | |
| 1732 | 1732 | p.tok_i -= 1; |
| 1733 | 1733 | } |
| 1734 | 1734 | } else if (p.eatToken(.colon)) |_| { |
lib/std/zig/render.zig+4-4| ... | ... | @@ -2648,7 +2648,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool { |
| 2648 | 2648 | const newline = if (newline_index) |i| comment_start + i else null; |
| 2649 | 2649 | |
| 2650 | 2650 | const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len]; |
| 2651 | const trimmed_comment = mem.trimRight(u8, untrimmed_comment, &std.ascii.spaces); | |
| 2651 | const trimmed_comment = mem.trimRight(u8, untrimmed_comment, &std.ascii.whitespace); | |
| 2652 | 2652 | |
| 2653 | 2653 | // Don't leave any whitespace at the start of the file |
| 2654 | 2654 | if (index != 0) { |
| ... | ... | @@ -2669,7 +2669,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool { |
| 2669 | 2669 | |
| 2670 | 2670 | index = 1 + (newline orelse end - 1); |
| 2671 | 2671 | |
| 2672 | const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.spaces); | |
| 2672 | const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.whitespace); | |
| 2673 | 2673 | if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) { |
| 2674 | 2674 | // Write the source for which formatting was disabled directly |
| 2675 | 2675 | // to the underlying writer, fixing up invaild whitespace. |
| ... | ... | @@ -2716,7 +2716,7 @@ fn renderExtraNewlineToken(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex) Er |
| 2716 | 2716 | // non-whitespace character is encountered or two newlines have been found. |
| 2717 | 2717 | var i = token_start - 1; |
| 2718 | 2718 | var newlines: u2 = 0; |
| 2719 | while (std.ascii.isSpace(tree.source[i])) : (i -= 1) { | |
| 2719 | while (std.ascii.isWhitespace(tree.source[i])) : (i -= 1) { | |
| 2720 | 2720 | if (tree.source[i] == '\n') newlines += 1; |
| 2721 | 2721 | if (newlines == 2) return ais.insertNewline(); |
| 2722 | 2722 | if (i == prev_token_end) break; |
| ... | ... | @@ -2778,7 +2778,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 { |
| 2778 | 2778 | ret.len -= 1; |
| 2779 | 2779 | }, |
| 2780 | 2780 | .container_doc_comment, .doc_comment => { |
| 2781 | ret = mem.trimRight(u8, ret, &std.ascii.spaces); | |
| 2781 | ret = mem.trimRight(u8, ret, &std.ascii.whitespace); | |
| 2782 | 2782 | }, |
| 2783 | 2783 | else => {}, |
| 2784 | 2784 | } |
lib/std/zig/tokenizer.zig+1-1| ... | ... | @@ -1232,7 +1232,7 @@ pub const Tokenizer = struct { |
| 1232 | 1232 | fn getInvalidCharacterLength(self: *Tokenizer) u3 { |
| 1233 | 1233 | const c0 = self.buffer[self.index]; |
| 1234 | 1234 | if (std.ascii.isASCII(c0)) { |
| 1235 | if (std.ascii.isCntrl(c0)) { | |
| 1235 | if (std.ascii.isControl(c0)) { | |
| 1236 | 1236 | // ascii control codes are never allowed |
| 1237 | 1237 | // (note that \n was checked before we got here) |
| 1238 | 1238 | return 1; |
src/translate_c.zig+1-1| ... | ... | @@ -5738,7 +5738,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { |
| 5738 | 5738 | if (mem.indexOfScalar(u8, lit_bytes, '.')) |dot_index| { |
| 5739 | 5739 | if (dot_index == 2) { |
| 5740 | 5740 | lit_bytes = try std.fmt.allocPrint(c.arena, "0x0{s}", .{lit_bytes[2..]}); |
| 5741 | } else if (dot_index + 1 == lit_bytes.len or !std.ascii.isXDigit(lit_bytes[dot_index + 1])) { | |
| 5741 | } else if (dot_index + 1 == lit_bytes.len or !std.ascii.isHex(lit_bytes[dot_index + 1])) { | |
| 5742 | 5742 | // If the literal lacks a digit after the `.`, we need to |
| 5743 | 5743 | // add one since `0x1.p10` would be invalid syntax in Zig. |
| 5744 | 5744 | lit_bytes = try std.fmt.allocPrint(c.arena, "0x{s}0{s}", .{ |