Seperate types & utils to files
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import std/strutils
|
||||
import std/math
|
||||
import fusion/matching
|
||||
|
||||
{.experimental: "caseStmtMacros".}
|
||||
|
||||
proc safeDelete*(str: string, slice: Slice[int]): string =
|
||||
## Deletes the items `str[slice]`, ignoring elements out of range.
|
||||
@@ -25,3 +28,28 @@ func findAndDelete*(str: string, chars: set[char], start = 0, last = str.len - 1
|
||||
func deleteAfterNewline*(str: string, start = 0): string =
|
||||
## Delete string after next Newline from `start`.
|
||||
findAndDelete(str, Newlines, start)
|
||||
|
||||
proc indentAfterNewline*(str: string, count: int): string =
|
||||
## Indent lines following the first line of `str` by `count`.
|
||||
## Useful for indenting nested keys of stringify functions.
|
||||
var strDup = str.indent(count)
|
||||
strDup.delete(0..count - 1)
|
||||
strDup
|
||||
|
||||
proc prettyExpectedSet*(x: set[char]): string =
|
||||
## Pretty print value for a set `x` of characters
|
||||
case x:
|
||||
of AllChars:
|
||||
"AllChars {'\x00'..'\xFF'}"
|
||||
of Digits:
|
||||
"Digits {'0'..'9'}"
|
||||
of HexDigits:
|
||||
"HexDigits {'0'..'9', 'A'..'F', 'a'..'f'}"
|
||||
of Letters:
|
||||
"Letters {'A'..'Z', 'a'..'z'}"
|
||||
of Newlines:
|
||||
"Newlines {'\r', '\n'}"
|
||||
of Whitespace:
|
||||
"Whitespace {' ', '\t', '\v', '\r', '\n', '\f'}"
|
||||
else:
|
||||
$x
|
||||
|
||||
Reference in New Issue
Block a user