authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-14 21:31:12+02:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-14 21:34:59+02:00
log02893d80cf013b14708d2262e9ecf0037cf6b3f2
tree3743f76a8e77500c8220e67dae3e3b654056c885
parentd178df773a6a11eff0b7f06f41fe26930c228b91

api: rename and deprecate a bunch of functions

`isAlNum` and `isAlpha`: 1. I think these names are a bit cryptic. 2. `isAlpha` is a bit ambiguous: is it alpha*numeric* or alpha*betic*? This is why I renamed `isAlpha` to `isAlphabetic`. 3. For consistency and because `isAlNum` looks weird, I renamed it to `isAlphanumeric`. `isCntrl`: 1. It's cryptic and hard to find when you look for it. 2. We don't save a lot of space writing it this way. 3. It's closer to the name of the `control_code` struct. `isSpace`: 1. The name is ambiguous and misleading. `spaces`: 1. Ditto `isXDigit`: 1. The name is extremely cryptic. 2. The function is very hard to find by its name.

1 files changed, 28 insertions(+), 13 deletions(-)

lib/std/ascii.zig+28-13
...@@ -222,16 +222,31 @@ fn inTable(c: u8, t: tIndex) bool {...@@ -222,16 +222,31 @@ fn inTable(c: u8, t: tIndex) bool {
222 return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;222 return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;
223}223}
224224
225pub fn isAlNum(c: u8) bool {225// remove all decls marked as DEPRECATED after 0.10.0
226
227/// DEPRECATED: use `isAlphanumeric`
228pub const isAlNum = isAlphanumeric;
229/// DEPRECATED: use `isAlpha`
230pub const isAlpha = isAlphabetic;
231/// DEPRECATED: use `isAlpha`
232pub const isCntrl = isControl;
233/// DEPRECATED: use `isWhitespace`.
234pub const isSpace = isWhitespace;
235/// DEPRECATED: use `whitespace`.
236pub const spaces = whitespace;
237/// DEPRECATED: use `isHex`.
238pub const isXDigit = isHex;
239
240pub fn isAlphanumeric(c: u8) bool {
226 return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |241 return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
227 @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;242 @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
228}243}
229244
230pub fn isAlpha(c: u8) bool {245pub fn isAlphabetic(c: u8) bool {
231 return inTable(c, tIndex.Alpha);246 return inTable(c, tIndex.Alpha);
232}247}
233248
234pub fn isCntrl(c: u8) bool {249pub fn isControl(c: u8) bool {
235 return c <= control_code.us or c == control_code.del;250 return c <= control_code.us or c == control_code.del;
236}251}
237252
...@@ -256,21 +271,21 @@ pub fn isPunct(c: u8) bool {...@@ -256,21 +271,21 @@ pub fn isPunct(c: u8) bool {
256 return inTable(c, tIndex.Punct);271 return inTable(c, tIndex.Punct);
257}272}
258273
259pub fn isSpace(c: u8) bool {274pub fn isWhitespace(c: u8) bool {
260 return inTable(c, tIndex.Space);275 return inTable(c, tIndex.Space);
261}276}
262277
263/// All the values for which isSpace() returns true. This may be used with278/// Whitespace for general use.
264/// e.g. std.mem.trim() to trim whiteSpace.279/// This may be used with e.g. `std.mem.trim` to trim whitespace.
265pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.FF };280/// See also: `isSpace`.
281pub const whitespace = [_]u8{ ' ', '\t', '\n', '\r', control_code.vt, control_code.ff };
266282
267test "spaces" {283test "whitespace" {
268 const testing = std.testing;284 for (whitespace) |char| try std.testing.expect(isWhitespace(char));
269 for (spaces) |space| try testing.expect(isSpace(space));
270285
271 var i: u8 = 0;286 var i: u8 = 0;
272 while (isASCII(i)) : (i += 1) {287 while (isASCII(i)) : (i += 1) {
273 if (isSpace(i)) try testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);288 if (isWhitespace(i)) try std.testing.expect(std.mem.indexOfScalar(u8, &whitespace, i) != null);
274 }289 }
275}290}
276291
...@@ -278,7 +293,7 @@ pub fn isUpper(c: u8) bool {...@@ -278,7 +293,7 @@ pub fn isUpper(c: u8) bool {
278 return inTable(c, tIndex.Upper);293 return inTable(c, tIndex.Upper);
279}294}
280295
281pub fn isXDigit(c: u8) bool {296pub fn isHex(c: u8) bool {
282 return inTable(c, tIndex.Hex);297 return inTable(c, tIndex.Hex);
283}298}
284299
...@@ -286,7 +301,7 @@ pub fn isASCII(c: u8) bool {...@@ -286,7 +301,7 @@ pub fn isASCII(c: u8) bool {
286 return c < 128;301 return c < 128;
287}302}
288303
289/// DEPRECATED: use `c == ' ' or c == '\x09'` or try `isWhitespace`304/// DEPRECATED: use `c == ' ' or c == '\t'` or try `isWhitespace`
290pub fn isBlank(c: u8) bool {305pub fn isBlank(c: u8) bool {
291 return (c == ' ') or (c == '\x09');306 return (c == ' ') or (c == '\x09');
292}307}