This module supports helper routines for working with cstring without having to convert cstring to string, in order to save allocations.
string
func cmpIgnoreCase(a, b: cstring): int {....gcsafe, extern: "csuCmpIgnoreCase",
raises: [], tags: [], forbids: [].}a == b
a < b
a > b
Example:
assert cmpIgnoreCase(cstring"hello", cstring"HeLLo") == 0 assert cmpIgnoreCase(cstring"echo", cstring"hello") < 0 assert cmpIgnoreCase(cstring"yellow", cstring"hello") > 0Source Edit
func cmpIgnoreStyle(a, b: cstring): int {....gcsafe, extern: "csuCmpIgnoreStyle",
raises: [], tags: [], forbids: [].}cmp(normalize($a), normalize($b)). It is just optimized to not allocate temporary strings. This should NOT be used to compare Nim identifier names, use macros.eqIdent for that. Returns:a == b
a < b
a > b
Example:
assert cmpIgnoreStyle(cstring"hello", cstring"H_e_L_Lo") == 0Source Edit
func endsWith(s, suffix: cstring): bool {....gcsafe, extern: "csuEndsWith",
raises: [], tags: [], forbids: [].}Returns true if s ends with suffix.
The JS backend uses the native String.prototype.endsWith function.
Example:
assert endsWith(cstring"Hello, Nimion", cstring"Nimion") assert not endsWith(cstring"Hello, Nimion", cstring"Hello") assert endsWith(cstring"Hello", cstring"")Source Edit
func startsWith(s, prefix: cstring): bool {....gcsafe, extern: "csuStartsWith",
raises: [], tags: [], forbids: [].}Returns true if s starts with prefix.
The JS backend uses the native String.prototype.startsWith function.
Example:
assert startsWith(cstring"Hello, Nimion", cstring"Hello") assert not startsWith(cstring"Hello, Nimion", cstring"Nimion") assert startsWith(cstring"Hello", cstring"")Source Edit
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/cstrutils.html