mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
api(std.ascii): remove deprecated decls
This commit is contained in:
parent
f7fea080b2
commit
6b7d9b34e8
7 changed files with 14 additions and 115 deletions
|
|
@ -114,7 +114,7 @@ pub fn parse(text: []const u8) !Version {
|
|||
if (id.len == 0) return error.InvalidVersion;
|
||||
|
||||
// Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-].
|
||||
for (id) |c| if (!std.ascii.isAlNum(c) and c != '-') return error.InvalidVersion;
|
||||
for (id) |c| if (!std.ascii.isAlphanumeric(c) and c != '-') return error.InvalidVersion;
|
||||
|
||||
// Numeric identifiers MUST NOT include leading zeroes.
|
||||
const is_num = for (id) |c| {
|
||||
|
|
@ -133,7 +133,7 @@ pub fn parse(text: []const u8) !Version {
|
|||
if (id.len == 0) return error.InvalidVersion;
|
||||
|
||||
// Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-].
|
||||
for (id) |c| if (!std.ascii.isAlNum(c) and c != '-') return error.InvalidVersion;
|
||||
for (id) |c| if (!std.ascii.isAlphanumeric(c) and c != '-') return error.InvalidVersion;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,83 +10,10 @@
|
|||
|
||||
const std = @import("std");
|
||||
|
||||
// TODO: remove all decls marked as DEPRECATED after 0.10.0's release
|
||||
|
||||
/// The C0 control codes of the ASCII encoding.
|
||||
///
|
||||
/// See also: https://en.wikipedia.org/wiki/C0_and_C1_control_codes and `isControl`.
|
||||
pub const control_code = struct {
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const NUL = 0x00;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const SOH = 0x01;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const STX = 0x02;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const ETX = 0x03;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const EOT = 0x04;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const ENQ = 0x05;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const ACK = 0x06;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const BEL = 0x07;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const BS = 0x08;
|
||||
// DEPRECATED: use `ht`
|
||||
pub const TAB = 0x09;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const LF = 0x0A;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const VT = 0x0B;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const FF = 0x0C;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const CR = 0x0D;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const SO = 0x0E;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const SI = 0x0F;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const DLE = 0x10;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const DC1 = 0x11;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const DC2 = 0x12;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const DC3 = 0x13;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const DC4 = 0x14;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const NAK = 0x15;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const SYN = 0x16;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const ETB = 0x17;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const CAN = 0x18;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const EM = 0x19;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const SUB = 0x1A;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const ESC = 0x1B;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const FS = 0x1C;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const GS = 0x1D;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const RS = 0x1E;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const US = 0x1F;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const DEL = 0x7F;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const XON = 0x11;
|
||||
// DEPRECATED: use the lowercase variant
|
||||
pub const XOFF = 0x13;
|
||||
|
||||
/// Null.
|
||||
pub const nul = 0x00;
|
||||
/// Start of Heading.
|
||||
|
|
@ -298,19 +225,6 @@ fn inTable(c: u8, t: tIndex) bool {
|
|||
return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;
|
||||
}
|
||||
|
||||
/// DEPRECATED: use `isAlphanumeric`
|
||||
pub const isAlNum = isAlphanumeric;
|
||||
/// DEPRECATED: use `isAlphabetic`
|
||||
pub const isAlpha = isAlphabetic;
|
||||
/// DEPRECATED: use `isControl`
|
||||
pub const isCntrl = isControl;
|
||||
/// DEPRECATED: use `isWhitespace`.
|
||||
pub const isSpace = isWhitespace;
|
||||
/// DEPRECATED: use `whitespace`.
|
||||
pub const spaces = whitespace;
|
||||
/// DEPRECATED: use `isHex`.
|
||||
pub const isXDigit = isHex;
|
||||
|
||||
/// Returns whether the character is alphanumeric.
|
||||
pub fn isAlphanumeric(c: u8) bool {
|
||||
return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
|
||||
|
|
@ -335,11 +249,6 @@ pub fn isDigit(c: u8) bool {
|
|||
return inTable(c, tIndex.Digit);
|
||||
}
|
||||
|
||||
/// DEPRECATED: use `isPrint(c) and c != ' '` instead
|
||||
pub fn isGraph(c: u8) bool {
|
||||
return inTable(c, tIndex.Graph);
|
||||
}
|
||||
|
||||
/// Returns whether the character is a lowercased letter.
|
||||
pub fn isLower(c: u8) bool {
|
||||
return inTable(c, tIndex.Lower);
|
||||
|
|
@ -352,11 +261,6 @@ pub fn isPrint(c: u8) bool {
|
|||
return inTable(c, tIndex.Graph) or c == ' ';
|
||||
}
|
||||
|
||||
/// DEPRECATED: create your own function based on your needs and what you want to do.
|
||||
pub fn isPunct(c: u8) bool {
|
||||
return inTable(c, tIndex.Punct);
|
||||
}
|
||||
|
||||
/// Returns whether this character is included in `whitespace`.
|
||||
pub fn isWhitespace(c: u8) bool {
|
||||
return inTable(c, tIndex.Space);
|
||||
|
|
@ -392,11 +296,6 @@ pub fn isASCII(c: u8) bool {
|
|||
return c < 128;
|
||||
}
|
||||
|
||||
/// DEPRECATED: use `c == ' ' or c == '\t'` or try `isWhitespace`
|
||||
pub fn isBlank(c: u8) bool {
|
||||
return (c == ' ') or (c == '\x09');
|
||||
}
|
||||
|
||||
/// Uppercases the character and returns it as-is if it's already uppercased or not a letter.
|
||||
pub fn toUpper(c: u8) u8 {
|
||||
if (isLower(c)) {
|
||||
|
|
@ -440,9 +339,9 @@ test "ascii character classes" {
|
|||
try testing.expect(isAlphanumeric('5'));
|
||||
try testing.expect(!isAlphanumeric('!'));
|
||||
|
||||
try testing.expect(!isAlpha('5'));
|
||||
try testing.expect(isAlpha('c'));
|
||||
try testing.expect(!isAlpha('5'));
|
||||
try testing.expect(!isAlphabetic('5'));
|
||||
try testing.expect(isAlphabetic('c'));
|
||||
try testing.expect(!isAlphabetic('5'));
|
||||
|
||||
try testing.expect(isWhitespace(' '));
|
||||
try testing.expect(isWhitespace('\t'));
|
||||
|
|
|
|||
|
|
@ -1192,7 +1192,7 @@ pub fn isValidHostName(hostname: []const u8) bool {
|
|||
if (hostname.len >= 254) return false;
|
||||
if (!std.unicode.utf8ValidateSlice(hostname)) return false;
|
||||
for (hostname) |byte| {
|
||||
if (byte >= 0x80 or byte == '.' or byte == '-' or std.ascii.isAlNum(byte)) {
|
||||
if (!std.ascii.isASCII(byte) or byte == '.' or byte == '-' or std.ascii.isAlphanumeric(byte)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1531,7 +1531,7 @@ const Parser = struct {
|
|||
// without types we don't know if '&&' was intended as 'bitwise_and address_of', or a c-style logical_and
|
||||
// The best the parser can do is recommend changing it to 'and' or ' & &'
|
||||
try p.warnMsg(.{ .tag = .invalid_ampersand_ampersand, .token = oper_token });
|
||||
} else if (std.ascii.isSpace(char_before) != std.ascii.isSpace(char_after)) {
|
||||
} else if (std.ascii.isWhitespace(char_before) != std.ascii.isWhitespace(char_after)) {
|
||||
try p.warnMsg(.{ .tag = .mismatched_binary_op_whitespace, .token = oper_token });
|
||||
}
|
||||
}
|
||||
|
|
@ -1728,7 +1728,7 @@ const Parser = struct {
|
|||
var sentinel: Node.Index = 0;
|
||||
if (p.eatToken(.identifier)) |ident| {
|
||||
const ident_slice = p.source[p.token_starts[ident]..p.token_starts[ident + 1]];
|
||||
if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.spaces), "c")) {
|
||||
if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.whitespace), "c")) {
|
||||
p.tok_i -= 1;
|
||||
}
|
||||
} else if (p.eatToken(.colon)) |_| {
|
||||
|
|
|
|||
|
|
@ -2648,7 +2648,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool {
|
|||
const newline = if (newline_index) |i| comment_start + i else null;
|
||||
|
||||
const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len];
|
||||
const trimmed_comment = mem.trimRight(u8, untrimmed_comment, &std.ascii.spaces);
|
||||
const trimmed_comment = mem.trimRight(u8, untrimmed_comment, &std.ascii.whitespace);
|
||||
|
||||
// Don't leave any whitespace at the start of the file
|
||||
if (index != 0) {
|
||||
|
|
@ -2669,7 +2669,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool {
|
|||
|
||||
index = 1 + (newline orelse end - 1);
|
||||
|
||||
const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.spaces);
|
||||
const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.whitespace);
|
||||
if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) {
|
||||
// Write the source for which formatting was disabled directly
|
||||
// to the underlying writer, fixing up invaild whitespace.
|
||||
|
|
@ -2716,7 +2716,7 @@ fn renderExtraNewlineToken(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex) Er
|
|||
// non-whitespace character is encountered or two newlines have been found.
|
||||
var i = token_start - 1;
|
||||
var newlines: u2 = 0;
|
||||
while (std.ascii.isSpace(tree.source[i])) : (i -= 1) {
|
||||
while (std.ascii.isWhitespace(tree.source[i])) : (i -= 1) {
|
||||
if (tree.source[i] == '\n') newlines += 1;
|
||||
if (newlines == 2) return ais.insertNewline();
|
||||
if (i == prev_token_end) break;
|
||||
|
|
@ -2778,7 +2778,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
|
|||
ret.len -= 1;
|
||||
},
|
||||
.container_doc_comment, .doc_comment => {
|
||||
ret = mem.trimRight(u8, ret, &std.ascii.spaces);
|
||||
ret = mem.trimRight(u8, ret, &std.ascii.whitespace);
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1232,7 +1232,7 @@ pub const Tokenizer = struct {
|
|||
fn getInvalidCharacterLength(self: *Tokenizer) u3 {
|
||||
const c0 = self.buffer[self.index];
|
||||
if (std.ascii.isASCII(c0)) {
|
||||
if (std.ascii.isCntrl(c0)) {
|
||||
if (std.ascii.isControl(c0)) {
|
||||
// ascii control codes are never allowed
|
||||
// (note that \n was checked before we got here)
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -5738,7 +5738,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
|
|||
if (mem.indexOfScalar(u8, lit_bytes, '.')) |dot_index| {
|
||||
if (dot_index == 2) {
|
||||
lit_bytes = try std.fmt.allocPrint(c.arena, "0x0{s}", .{lit_bytes[2..]});
|
||||
} else if (dot_index + 1 == lit_bytes.len or !std.ascii.isXDigit(lit_bytes[dot_index + 1])) {
|
||||
} else if (dot_index + 1 == lit_bytes.len or !std.ascii.isHex(lit_bytes[dot_index + 1])) {
|
||||
// If the literal lacks a digit after the `.`, we need to
|
||||
// add one since `0x1.p10` would be invalid syntax in Zig.
|
||||
lit_bytes = try std.fmt.allocPrint(c.arena, "0x{s}0{s}", .{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue