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 {
222222 return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0;
223223}
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 {
226241 return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
227242 @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
228243}
229244
230pub fn isAlpha(c: u8) bool {
245pub fn isAlphabetic(c: u8) bool {
231246 return inTable(c, tIndex.Alpha);
232247}
233248
234pub fn isCntrl(c: u8) bool {
249pub fn isControl(c: u8) bool {
235250 return c <= control_code.us or c == control_code.del;
236251}
237252
......@@ -256,21 +271,21 @@ pub fn isPunct(c: u8) bool {
256271 return inTable(c, tIndex.Punct);
257272}
258273
259pub fn isSpace(c: u8) bool {
274pub fn isWhitespace(c: u8) bool {
260275 return inTable(c, tIndex.Space);
261276}
262277
263/// All the values for which isSpace() returns true. This may be used with
264/// e.g. std.mem.trim() to trim whiteSpace.
265pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.FF };
278/// Whitespace for general use.
279/// This may be used with e.g. `std.mem.trim` to trim whitespace.
280/// See also: `isSpace`.
281pub const whitespace = [_]u8{ ' ', '\t', '\n', '\r', control_code.vt, control_code.ff };
266282
267test "spaces" {
268 const testing = std.testing;
269 for (spaces) |space| try testing.expect(isSpace(space));
283test "whitespace" {
284 for (whitespace) |char| try std.testing.expect(isWhitespace(char));
270285
271286 var i: u8 = 0;
272287 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);
274289 }
275290}
276291
......@@ -278,7 +293,7 @@ pub fn isUpper(c: u8) bool {
278293 return inTable(c, tIndex.Upper);
279294}
280295
281pub fn isXDigit(c: u8) bool {
296pub fn isHex(c: u8) bool {
282297 return inTable(c, tIndex.Hex);
283298}
284299
......@@ -286,7 +301,7 @@ pub fn isASCII(c: u8) bool {
286301 return c < 128;
287302}
288303
289/// DEPRECATED: use `c == ' ' or c == '\x09'` or try `isWhitespace`
304/// DEPRECATED: use `c == ' ' or c == '\t'` or try `isWhitespace`
290305pub fn isBlank(c: u8) bool {
291306 return (c == ' ') or (c == '\x09');
292307}