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