Source Edit

This module supports helper routines for working with cstring without having to convert cstring to string, in order to save allocations.

See also

Imports

strimpl

Procs

  1. func cmpIgnoreCase(a, b: cstring): int {....gcsafe, extern: "csuCmpIgnoreCase",
  2. 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:

  1. assert cmpIgnoreCase(cstring"hello", cstring"HeLLo") == 0
  2. assert cmpIgnoreCase(cstring"echo", cstring"hello") < 0
  3. assert cmpIgnoreCase(cstring"yellow", cstring"hello") > 0

Source Edit

  1. func cmpIgnoreStyle(a, b: cstring): int {....gcsafe, extern: "csuCmpIgnoreStyle",
  2. 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, use macros.eqIdent for that. Returns:

  • 0 if a == b
  • < 0 if a < b
  • > 0 if a > b

Example:

  1. assert cmpIgnoreStyle(cstring"hello", cstring"H_e_L_Lo") == 0

Source Edit

  1. func endsWith(s, suffix: cstring): bool {....gcsafe, extern: "csuEndsWith",
  2. raises: [], tags: [], forbids: [].}

Returns true if s ends with suffix.

The JS backend uses the native String.prototype.endsWith function.

Example:

  1. assert endsWith(cstring"Hello, Nimion", cstring"Nimion")
  2. assert not endsWith(cstring"Hello, Nimion", cstring"Hello")
  3. assert endsWith(cstring"Hello", cstring"")

Source Edit

  1. func startsWith(s, prefix: cstring): bool {....gcsafe, extern: "csuStartsWith",
  2. raises: [], tags: [], forbids: [].}

Returns true if s starts with prefix.

The JS backend uses the native String.prototype.startsWith function.

Example:

  1. assert startsWith(cstring"Hello, Nimion", cstring"Hello")
  2. assert not startsWith(cstring"Hello, Nimion", cstring"Nimion")
  3. assert startsWith(cstring"Hello", cstring"")

Source Edit