| ... | ... | @@ -222,16 +222,31 @@ fn inTable(c: u8, t: tIndex) bool { |
| 222 | 222 | return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | | pub fn isAlNum(c: u8) bool { |
| 225 | // remove all decls marked as DEPRECATED after 0.10.0 |
| 226 | |
| 227 | /// DEPRECATED: use `isAlphanumeric` |
| 228 | pub const isAlNum = isAlphanumeric; |
| 229 | /// DEPRECATED: use `isAlpha` |
| 230 | pub const isAlpha = isAlphabetic; |
| 231 | /// DEPRECATED: use `isAlpha` |
| 232 | pub const isCntrl = isControl; |
| 233 | /// DEPRECATED: use `isWhitespace`. |
| 234 | pub const isSpace = isWhitespace; |
| 235 | /// DEPRECATED: use `whitespace`. |
| 236 | pub const spaces = whitespace; |
| 237 | /// DEPRECATED: use `isHex`. |
| 238 | pub const isXDigit = isHex; |
| 239 | |
| 240 | pub fn isAlphanumeric(c: u8) bool { |
| 226 | 241 | return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) | |
| 227 | 242 | @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0; |
| 228 | 243 | } |
| 229 | 244 | |
| 230 | | pub fn isAlpha(c: u8) bool { |
| 245 | pub fn isAlphabetic(c: u8) bool { |
| 231 | 246 | return inTable(c, tIndex.Alpha); |
| 232 | 247 | } |
| 233 | 248 | |
| 234 | | pub fn isCntrl(c: u8) bool { |
| 249 | pub fn isControl(c: u8) bool { |
| 235 | 250 | return c <= control_code.us or c == control_code.del; |
| 236 | 251 | } |
| 237 | 252 | |
| ... | ... | @@ -256,21 +271,21 @@ pub fn isPunct(c: u8) bool { |
| 256 | 271 | return inTable(c, tIndex.Punct); |
| 257 | 272 | } |
| 258 | 273 | |
| 259 | | pub fn isSpace(c: u8) bool { |
| 274 | pub fn isWhitespace(c: u8) bool { |
| 260 | 275 | return inTable(c, tIndex.Space); |
| 261 | 276 | } |
| 262 | 277 | |
| 263 | | /// All the values for which isSpace() returns true. This may be used with |
| 264 | | /// e.g. std.mem.trim() to trim whiteSpace. |
| 265 | | pub 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`. |
| 281 | pub const whitespace = [_]u8{ ' ', '\t', '\n', '\r', control_code.vt, control_code.ff }; |
| 266 | 282 | |
| 267 | | test "spaces" { |
| 268 | | const testing = std.testing; |
| 269 | | for (spaces) |space| try testing.expect(isSpace(space)); |
| 283 | test "whitespace" { |
| 284 | for (whitespace) |char| try std.testing.expect(isWhitespace(char)); |
| 270 | 285 | |
| 271 | 286 | var i: u8 = 0; |
| 272 | 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 | } |
| 276 | 291 | |
| ... | ... | @@ -278,7 +293,7 @@ pub fn isUpper(c: u8) bool { |
| 278 | 293 | return inTable(c, tIndex.Upper); |
| 279 | 294 | } |
| 280 | 295 | |
| 281 | | pub fn isXDigit(c: u8) bool { |
| 296 | pub fn isHex(c: u8) bool { |
| 282 | 297 | return inTable(c, tIndex.Hex); |
| 283 | 298 | } |
| 284 | 299 | |
| ... | ... | @@ -286,7 +301,7 @@ pub fn isASCII(c: u8) bool { |
| 286 | 301 | return c < 128; |
| 287 | 302 | } |
| 288 | 303 | |
| 289 | | /// DEPRECATED: use `c == ' ' or c == '\x09'` or try `isWhitespace` |
| 304 | /// DEPRECATED: use `c == ' ' or c == '\t'` or try `isWhitespace` |
| 290 | 305 | pub fn isBlank(c: u8) bool { |
| 291 | 306 | return (c == ' ') or (c == '\x09'); |
| 292 | 307 | } |