40 Commits

Author SHA1 Message Date
CrazyboyQCD
8ddce90e62
std.ascii: make toLower toUpper branchless (#21369)
Co-authored-by: WX\shixi <shixi1@cnwxsoft.com>
2024-09-13 17:22:19 -07:00
Michael Bradshaw
02b3d5b58a Rename isASCII to isAscii 2024-07-02 16:31:15 +02:00
Andrew Kelley
12191c8a22 std: promote tests to doctests
Now these show up as "example usage" in generated documentation.
2024-03-21 14:11:46 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
r00ster91
45650f7003 std.ascii: more tests 2022-12-09 21:57:17 +01:00
r00ster91
0162a0868c isHex, isAlphanumeric: prong reorder
On x86 interestingly I can see a reduction in codesize by 1 instruction with this.
While not necessarily faster, it might still reduce codesize a bit and this ordering is also more logical
because it follows ASCII table order. Rust's std uses this ordering too.
See https://zig.godbolt.org/z/PqodY8YqY for the difference.
2022-12-09 21:57:17 +01:00
r00ster91
19dbc5805c fix(perf): remove LUT
This makes it so that we no longer use a LUT (Look-Up Table):
* The code is much simpler and easier to understand now.
* Using a LUT means we rely on a warm cache.
  Relying on the cache like this results in inconsistent performance and in many cases codegen will be worse.
  Also as @topolarity once pointed out, in some cases while it seems like the code may branch, it actually doesn't:
  https://github.com/ziglang/zig/pull/11629#issuecomment-1213641429
* Other languages' standard libraries don't do this either.
  JFF I wanted to see what other languages codegen compared to us now:
  https://rust.godbolt.org/z/Te4ax9Edf, https://zig.godbolt.org/z/nTbYedWKv
  So we are pretty much on par or better than other languages now.
2022-12-09 21:57:17 +01:00
r00ster91
626e02a429 docs: minor improvements 2022-12-09 21:57:17 +01:00
r00ster91
6b7d9b34e8 api(std.ascii): remove deprecated decls 2022-12-09 21:57:17 +01:00
fn ⌃ ⌥
a70c86e661 Fix deprecation docs for isAlpha and isCntrl 2022-10-29 15:22:05 -04:00
Zhora Trush
c66d3f6bf6 Enhance indexOfIgnoreCase with Boyer-Moore-Horspool algorithm 2022-10-28 20:29:41 -04:00
r00ster91
4ea3a9ba9f fix: comments 2022-08-17 20:08:13 +02:00
r00ster91
37880f2385 api: deprecate lowercase control_code consts 2022-08-17 20:07:58 +02:00
r00ster91
298062897d docs: fixes and improvements 2022-08-16 21:37:02 +02:00
r00ster91
ee97fbc199 api: deprecate isPunct too
See https://github.com/ziglang/zig/issues/8419#issuecomment-843719898
2022-08-14 22:04:13 +02:00
r00ster91
846dbf2745 docs: remove some hyphens 2022-08-14 21:49:21 +02:00
r00ster91
8890190857 fix: add missing 'o' 2022-08-14 21:46:26 +02:00
r00ster91
028134055c fix: remove outdated TODO
It was supposed to be removed: 490654c332 (r47643278)
2022-08-14 21:43:40 +02:00
r00ster91
9b79c6ae52 test: update and add more tests 2022-08-14 21:42:24 +02:00
r00ster91
d130d09e2b docs: add more docs
And improve some existing docs.
2022-08-14 21:39:53 +02:00
r00ster91
02893d80cf 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.
2022-08-14 21:34:59 +02:00
r00ster91
d178df773a api: deprecate isBlank and isGraph.
I think `isBlank` and `isWhitespace` are quite confusable.
What `isBlank` does is so simple that you can just do the `c == ' ' or c == '\t'`
check yourself but in a lot of cases you don't even want that.
`std.ascii` can't really know what you think "blank" means.
That's why I think it's better to remove it.
And again, it seems ambiguous considering that we have `isWhitespace`.

Next, it also deprecates `isGraph`.
It's the same as `isPrint(c) and c != ' '`, which I find confusing.
When something is printable, you can say it also has a *graph*ical representation.
Removing `isGraph` solves this possible confusion.
2022-08-14 21:13:46 +02:00
r00ster91
93ca0c4a5e fix: off-by-one in isCntrl
0x1F (`control_code.us`) itself is also a control code.
2022-08-14 21:05:37 +02:00
r00ster91
aa0b93e875 feat: new control_code
It lowercases all constants and documents them.
2022-08-14 21:03:57 +02:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
xackus
143688e266 add allocation free versions of lower/upper string
Co-authored-by: LemonBoy <thatlemon@gmail.com>
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-06-08 14:27:44 -04:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Andrew Kelley
490654c332 std.ascii: add lessThanIgnoreCase and orderIgnoreCase
For sorting ascii strings, case insensitively.
2021-02-27 01:21:01 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
LemonBoy
fd8fa55129
std: Add a few helpers for matching ascii strings (#7300)
* startsWithIgnoreCase
* endsWithIgnoreCase
2020-12-04 15:27:28 -05:00
Isaac Freund
50ba018223 std/ascii: add spaces array
This may be combined with std.mem.trim to form a proper replacement for
the now deprecated std.fmt.trimWhitespace().
2020-11-02 13:20:58 -05:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Felix (xq) Queißner
7dc29fdee1 Creates std.ascii.control_code that contains the C0 control codes as named constants. 2020-05-16 12:46:44 -04:00
Greg Anders
c6420820b0 Remove redundant ASCII functions
The `matchCase` variants are simply duplicates of the `eql` and
`indexOf` functions found in std.mem.
2020-05-12 08:38:15 -06:00
Greg Anders
9f496c0777 Add helper functions and docstrings to ascii.zig
* Add an upper case variant of `allocLowerString`
  * Add case-sensitive variants of `eqlIgnoreCase`, `indexOfIgnoreCase`,
    and `indexOfIgnoreCasePos`
  * Add and update docstrings on functions
2020-05-11 19:36:41 -06:00
Benjamin Feng
699c50a375 Switch a bunch of FBA to use testing.allocator 2020-02-12 17:17:56 -06:00
Andrew Kelley
e0db54e89d
update the codebase to use @as 2019-11-08 15:57:24 -05:00
Andrew Kelley
ed36dbbd9c
mv std/ lib/
that's all this commit does. further commits will fix cli flags and
such.

see #2221
2019-09-25 23:35:41 -04:00