std/cstrutils
Source EditЭтот модуль предоставляет вспомогательные функции для работы со строками C без необходимости конвертации в строки Nim, для экономии выделения памяти.
См. также
- модуль strutils для работы со строками Nim
Импорты
- strimpl
Процедуры
func cmpIgnoreCase(a, b: cstring): int {....gcsafe, extern: "csuCmpIgnoreCase", raises: [], tags: [], forbids: [].}- Сравнивает две строки без учёта регистра. Возвращает:
- 0, если строки равны
- < 0, если первая строка меньше второй
- > 0, если первая строка больше второй
Пример:
assert cmpIgnoreCase(cstring"hello", cstring"HeLLo") == 0 assert cmpIgnoreCase(cstring"echo", cstring"hello") < 0 assert cmpIgnoreCase(cstring"yellow", cstring"hello") > 0
Source Edit func cmpIgnoreStyle(a, b: cstring): int {....gcsafe, extern: "csuCmpIgnoreStyle", raises: [], tags: [], forbids: [].}- Семантически идентична процедуре
cmp(normalize($a), normalize($b)). Она оптимизирована для избегания выделения временных строк. Не следует использовать для сравнения имён идентификаторов Nim, используйтеmacros.eqIdentдля этой цели. Возвращает:- 0, если строки равны
- < 0, если первая строка меньше второй
- > 0, если первая строка больше второй
Пример:
assert cmpIgnoreStyle(cstring"hello", cstring"H_e_L_Lo") == 0
Source Edit func endsWith(s, suffix: cstring): bool {....gcsafe, extern: "csuEndsWith", raises: [], tags: [], forbids: [].}-
Возвращает true, если строка
sоканчивается наsuffix.JS-бекенд использует встроенную функцию
String.prototype.endsWith.Пример:
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: [].}-
Возвращает true, если строка
sначинается сprefix.JS-бекенд использует встроенную функцию
String.prototype.startsWith.Пример:
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