src/sys/strings

Source   Edit  

Special kinds of strings used for interacting with certain operating system APIs.

While mutating APIs are provided, they are limited to simple operations only. For performance it is recommended to convert them to strings, perform the necessary mutations, then use the checked converters.

Types

Nulless = Without[{'\x00'}]
A string without the character NUL, mainly used for file paths or command arguments. Source   Edit  
Without[C] = distinct string
A distinct string type without the characters in set C. Source   Edit  

Procs

func `[]=`[C](w: var Without[C]; i: Natural; c: char) {.inline,
    ...raises: [ValueError].}

Set the byte at position i of the string w to c.

Raises ValueError if c is in C.

Source   Edit  
func add[C](w: var Without[C]; c: char) {.inline, ...raises: [ValueError].}

Append the character c to w.

Raises ValueError if c is in C.

Source   Edit  
func add[C](w: var Without[C]; s: string)

Append the string s to w.

Raises ValueError if any character in C if found in the string s.

Source   Edit  
func filter(s: string; C: static set[char]): Without[C] {....raises: [].}
Remove characters in set C from s and create a Without[C]. Source   Edit  
func filter[A](w: Without[A]; C: static set[char]): Without[C] {....raises: [].}

Remove characters in set C from w and create a Without[C].

When A is equal to C, w will be returned. This makes it useful for use in generics.

Source   Edit  
func toNulless(s: sink Nulless): Nulless {.inline, ...raises: [], tags: [],
    forbids: [].}
Returns s. This function is provided for use in generics. Source   Edit  
func toNulless(s: sink string): Nulless {.inline, ...raises: [ValueError],
    tags: [], forbids: [].}

Checked conversion to NullessString.

Raises ValueError if any NUL character was found in the string.

Source   Edit  
func toWithout(s: sink string; C: static set[char]): Without[C] {.inline,
    ...raises: [ValueError].}

Checked conversion to Without[C].

Raises ValueError if any character in C was found in the string.

Source   Edit  
func toWithout[A](w: sink Without[A]; C: static set[char]): Without[C] {.inline,
    ...raises: [ValueError].}

Convert between Without types.

Raises ValueError if any character in C was found in the string.

When A is equal to C, w will be returned and no check occurs. This makes it useful for use in generics.

Source   Edit  

Converters

converter toString(w: Without): lent string
Read-only converter from any Without type to a string. This enables drop-in compatibility with non-mutating operations on a string. Source   Edit  

Templates

template `[]`[C](w: Without[C]; slice: HSlice[int, BackwardsIndex]): Without[C]
Returns a copy of w's slice. Source   Edit  
template `[]`[C](w: Without[C]; slice: Slice[int]): Without[C]
Returns a copy of w's slice. Source   Edit  
template add[C](w: var Without[C]; s: Without[C])
Append the string s to w. Source   Edit