authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-16 21:37:02+02:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-16 21:37:02+02:00
log298062897da5de0766f180ebb7a66a6f1e91af88
treeba22d6bce42c108fa6972d3ec7868801b6dee8d4
parentee97fbc199a6b5cf04637d044650d407ce44f883

docs: fixes and improvements


1 files changed, 15 insertions(+), 10 deletions(-)

lib/std/ascii.zig+15-10
......@@ -12,7 +12,7 @@ const std = @import("std");
1212
1313/// The C0 control codes of the ASCII encoding.
1414///
15/// See also: https://en.wikipedia.org/wiki/C0_and_C1_control_codes and `is_control`.
15/// See also: https://en.wikipedia.org/wiki/C0_and_C1_control_codes and `isControl`.
1616pub const control_code = struct {
1717 /// Null.
1818 pub const nul = 0x00;
......@@ -240,24 +240,26 @@ pub const spaces = whitespace;
240240/// DEPRECATED: use `isHex`.
241241pub const isXDigit = isHex;
242242
243/// Returns whether the character is alphanumeric. This is case-insensitive.
243/// Returns whether the character is alphanumeric.
244244pub fn isAlphanumeric(c: u8) bool {
245245 return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) |
246246 @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0;
247247}
248248
249/// Returns whether the character is alphabetic. This is case-insensitive.
249/// Returns whether the character is alphabetic.
250250pub fn isAlphabetic(c: u8) bool {
251251 return inTable(c, tIndex.Alpha);
252252}
253253
254254/// Returns whether the character is a control character.
255/// This is the same as `!isPrint(c)`.
255256///
256257/// See also: `control_code`.
257258pub fn isControl(c: u8) bool {
258259 return c <= control_code.us or c == control_code.del;
259260}
260261
262/// Returns whether the character is a digit.
261263pub fn isDigit(c: u8) bool {
262264 return inTable(c, tIndex.Digit);
263265}
......@@ -267,13 +269,14 @@ pub fn isGraph(c: u8) bool {
267269 return inTable(c, tIndex.Graph);
268270}
269271
270/// Returns whether the character is lowercased.
272/// Returns whether the character is a lowercased letter.
271273pub fn isLower(c: u8) bool {
272274 return inTable(c, tIndex.Lower);
273275}
274276
275277/// Returns whether the character has some graphical representation and can be printed.
276278/// This also returns `true` for the space character.
279/// This is the same as `!isControl(c)`.
277280pub fn isPrint(c: u8) bool {
278281 return inTable(c, tIndex.Graph) or c == ' ';
279282}
......@@ -290,7 +293,8 @@ pub fn isWhitespace(c: u8) bool {
290293
291294/// Whitespace for general use.
292295/// This may be used with e.g. `std.mem.trim` to trim whitespace.
293/// See also: `isSpace`.
296///
297/// See also: `isWhitespace`.
294298pub const whitespace = [_]u8{ ' ', '\t', '\n', '\r', control_code.vt, control_code.ff };
295299
296300test "whitespace" {
......@@ -302,7 +306,7 @@ test "whitespace" {
302306 }
303307}
304308
305/// Returns whether the character is uppercased.
309/// Returns whether the character is an uppercased letter.
306310pub fn isUpper(c: u8) bool {
307311 return inTable(c, tIndex.Upper);
308312}
......@@ -312,6 +316,7 @@ pub fn isHex(c: u8) bool {
312316 return inTable(c, tIndex.Hex);
313317}
314318
319/// Returns whether the character is a 7-bit ASCII character.
315320pub fn isASCII(c: u8) bool {
316321 return c < 128;
317322}
......@@ -321,7 +326,7 @@ pub fn isBlank(c: u8) bool {
321326 return (c == ' ') or (c == '\x09');
322327}
323328
324/// Uppercases the character and returns it as-is if it's already uppercased.
329/// Uppercases the character and returns it as-is if it's already uppercased or not a letter.
325330pub fn toUpper(c: u8) u8 {
326331 if (isLower(c)) {
327332 return c & 0b11011111;
......@@ -330,7 +335,7 @@ pub fn toUpper(c: u8) u8 {
330335 }
331336}
332337
333/// Lowercases the character and returns it as-is if it's already lowercased.
338/// Lowercases the character and returns it as-is if it's already lowercased or not a letter.
334339pub fn toLower(c: u8) u8 {
335340 if (isUpper(c)) {
336341 return c | 0b00100000;
......@@ -505,7 +510,7 @@ test "indexOfIgnoreCase" {
505510 try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
506511}
507512
508/// Compares two slices of numbers lexicographically. O(n).
513/// Returns the lexicographical order of two slices. O(n).
509514pub fn orderIgnoreCase(lhs: []const u8, rhs: []const u8) std.math.Order {
510515 const n = std.math.min(lhs.len, rhs.len);
511516 var i: usize = 0;
......@@ -519,7 +524,7 @@ pub fn orderIgnoreCase(lhs: []const u8, rhs: []const u8) std.math.Order {
519524 return std.math.order(lhs.len, rhs.len);
520525}
521526
522/// Returns whether `lhs` < `rhs`.
527/// Returns whether the lexicographical order of `lhs` is lower than `rhs`.
523528pub fn lessThanIgnoreCase(lhs: []const u8, rhs: []const u8) bool {
524529 return orderIgnoreCase(lhs, rhs) == .lt;
525530}