src/hmisc/algo/hstring_algo

    Dark Mode
Search:
Group by:
  Source   Edit

Types

CharBackIndex = distinct char
  Source   Edit
IdentStyle = enum
  idsNone, idsSnake, idsCamel
  Source   Edit
InterpolatedExprKind = enum
  iekStr,                   ## ``str`` part of the interpolated string
  iekDollar,                ## escaped ``$`` part of the interpolated string
  iekVar,                   ## ``var`` part of the interpolated string
  iekExpr,                  ## ``expr`` part of the interpolated string
  iekIndex
Describes for interpolatedFragments which part of the interpolated string is yielded; for example in "str$$$var${expr}"   Source   Edit
StrBackIndex = distinct string
  Source   Edit
StringAlignDirection = enum
  sadLeft, sadRight, sadCenter
  Source   Edit
StrPart = object
  case kind: StrPartKind
  of spkSet:
      chars*: set[char]

  of spkSubstr:
      strs*: seq[string]

  
  Source   Edit
StrPartConv = char | set[char] | string | seq[string] | openArray[string]
  Source   Edit
StrPartKind = enum
  spkSet, spkSubstr
  Source   Edit
StrPartTuple = tuple[lhs, rhs: StrPart]
  Source   Edit

Procs

func `[]`(ins: string; back: CharBackIndex): bool {.inline, ...raises: [], tags: [].}
  Source   Edit
func `[]`(ins: string; back: StrBackIndex): bool {.inline, ...raises: [], tags: [].}
  Source   Edit
func `[]`(ins: string; beg: StrPart; final: openArray[string]): bool {.inline,
    ...raises: [], tags: [].}
  Source   Edit
func `[]`(ins: string; beg: StrPart; final: StrPartConv): bool {.inline.}
  Source   Edit
func `[]`(ins: string; forward: string | char): bool {.inline.}
  Source   Edit
func `[]`(ins: string; strs: openArray[string]): bool {.inline, ...raises: [],
    tags: [].}
  Source   Edit
func `^`(s: char): CharBackIndex {.inline, ...raises: [], tags: [].}
  Source   Edit
func `^`(s: string): StrBackIndex {.inline, ...raises: [], tags: [].}
  Source   Edit
proc `|<<`(str: string; align: (int, char)): string {.inline, ...raises: [],
    tags: [].}
  Source   Edit
proc `|<<`(str: string; align: int): string {.inline, ...raises: [], tags: [].}
  Source   Edit
proc `|<>`(str: string; align: (int, char, char)): string {.inline, ...raises: [],
    tags: [].}
  Source   Edit
proc `|>>`(str: string; align: (int, char)): string {.inline, ...raises: [],
    tags: [].}
  Source   Edit
proc `|>>`(str: string; align: int): string {.inline, ...raises: [], tags: [].}
  Source   Edit
proc abbrevCamel(abbrev: string; words: seq[string]; getExact: bool = false): seq[
    string] {.inline, ...raises: [Exception, KeyError], tags: [RootEffect].}
Split abbreviation and all worlds as camelCase identifiers. Find all worlds that contains abbrev as subsequence. getExact
  • if any of the alternatives fully matches input word return it

as only result

To avoid ambiguous returns on tests like "Else", @["Else", "ElseBlock"])

  Source   Edit
proc abbrevCamel(abbrSplit: seq[string]; splitWords: seq[seq[string]];
                 getExact: bool = false): seq[string] {.inline,
    ...raises: [Exception, KeyError], tags: [RootEffect].}
Split abbreviation and all worlds as camelCase identifiers. Find all worlds that contains abbrev as subsequence.   Source   Edit
func abbrevSnake(str: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func addIndent(res: var string; level: int; sep: int = 2; prefix: char = ' ') {.
    inline, ...raises: [], tags: [].}
  Source   Edit
func addPrefix(str, pref: string): string {.inline, ...raises: [], tags: [].}
Add prefix to string if it not starts with pref   Source   Edit
func addPrefix(str: seq[string]; pref: string): seq[string] {.inline,
    ...raises: [], tags: [].}
  Source   Edit
func addPrefix(str: var string; pref: string): void {.inline, ...raises: [],
    tags: [].}
Add prefix to string if it not starts with pref   Source   Edit
func addSuffix(str, suff: string): string {.inline, ...raises: [], tags: [].}
Add suffix suff if not already present   Source   Edit
func commonPrefix(strs: seq[string]): string {.inline, ...raises: [], tags: [].}
Find common prefix for list of strings   Source   Edit
func contains(str: string; parts: varargs[StrPart, toStrPart]): bool {.inline,
    ...raises: [], tags: [].}
  Source   Edit
func dashedWords(str: string;
                 toDash: set[char] = {'-', '_', ' ', '.', ',', ';', ':'};
                 toLower: set[char] = {'a' .. 'z', 'A' .. 'Z', '0' .. '9'}): string {.
    inline, ...raises: [], tags: [].}
  Source   Edit
func delete(str: string; chars: set[char]): string {.inline, ...raises: [],
    tags: [].}
  Source   Edit
func delete(str: var string; chars: set[char]) {.inline, ...raises: [], tags: [].}
  Source   Edit
func dropCommonPrefix(strs: seq[string]; dropSingle: bool = true): seq[string] {.
    inline, ...raises: [], tags: [].}
Drop common prefix from sequence of strings. If dropSingle is false sequences with len == 1 are returned as-is.   Source   Edit
func dropNormPrefix(str: string; prefix: string): string {.inline, ...raises: [],
    tags: [].}
  Source   Edit
func dropPrefix(ss: seq[string]; patt: StrPart): seq[string] {.inline,
    ...raises: [ArgumentError], tags: [].}
  Source   Edit
func dropPrefix(str: string; alt: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func dropPrefix(str: string; part: StrPart): string {.inline,
    ...raises: [ArgumentError], tags: [].}
  Source   Edit
func dropSuffix(str: string; part: StrPart): string {.inline,
    ...raises: [ArgumentError], tags: [].}
  Source   Edit
func enclosedIn(s: string; delim: string): bool {.inline, ...raises: [], tags: [].}
  Source   Edit
func enclosedIn(str: string; delim: StrPart): bool {.inline, ...raises: [],
    tags: [].}
Check if string starts and ends with strings.   Source   Edit
func enclosedIn(str: string; delim: StrPartTuple): bool {.inline, ...raises: [],
    tags: [].}
Check if string starts and ends with strings.   Source   Edit
func endsWith(s: string; part: StrPart): bool {....raises: [], tags: [].}
  Source   Edit
func endsWith(str: string; suffixes: varargs[string]): bool {.inline,
    ...raises: [], tags: [].}
True if string ends with any of the suffixes   Source   Edit
func escapeHTML(input: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func escapeStrLit(input: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func filterPrefix(str: seq[string]; pref: StrPart): seq[string] {.inline,
    ...raises: [], tags: [].}
Return only strings that have prefix in pref   Source   Edit
func findEnd(str: string; sub: string; start: Natural = 0; last = 0): int {.
    inline, ...raises: [], tags: [].}
  Source   Edit
func fixCapitalizeAscii(str: string): string {.inline, ...raises: [], tags: [].}
Capitalize ascii string first character, and lowercase all other.   Source   Edit
func getIndent(level: int; sep: int = 2; prefix: char = ' '): string {.inline,
    ...raises: [], tags: [].}
  Source   Edit
proc getKeys[K, V](t: Table[K, V] | TableRef[K, V]): seq[K] {.inline.}
  Source   Edit
proc getRandomBase64(length: int): string {.inline, ...raises: [], tags: [].}
Return random base 64 string with length characters   Source   Edit
proc indentBody(str: string; count: int; indent: string = " ";
                prefix: string = ""): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func join(text: openArray[(string, string)]; sep: string = " "): string {.
    inline, ...raises: [], tags: [].}
  Source   Edit
func join(text: openArray[string]; sep: char = ' '): string {.inline,
    ...raises: [], tags: [].}
  Source   Edit
func join[T](obj: T; sep: string; wrap: (string, string)): string {.inline.}
  Source   Edit
func joinCamel(ins: openArray[string]): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func joinkv[K, V](t: openArray[(K, V)]; eqTok: string = "="): seq[string] {.
    inline.}
Join table values as key-value pairs   Source   Edit
func joinl(inseq: openArray[string]): string {.inline, ...raises: [], tags: [].}
Join items using newlines   Source   Edit
func joinq(inseq: openArray[string]; sep: string = " "; wrap: string = "\""): string {.
    inline, ...raises: [], tags: [].}
Join items using spaces and quote each item   Source   Edit
func joinql(inseq: openArray[string]; ident: int = 1; wrap: string = "\"";
            identStr: string = "  "): string {.inline, ...raises: [], tags: [].}
  Source   Edit
proc joinw(inseq: openArray[string]; sep = " "): string {.inline, ...raises: [],
    tags: [].}
Join items using spaces   Source   Edit
func keepNimIdentChars(str: string): string {.inline, ...raises: [], tags: [].}
Remove all non-identifier characters and collapse multiple underscrores into single one. Remove all leading underscores.   Source   Edit
func len(part: StrPart): int {.inline, inline, ...raises: [ArgumentError], tags: [].}
  Source   Edit
func makeCommentSection(str: string; level: range[0 .. 2]): string {.inline,
    ...raises: [ValueError], tags: [].}
Generate separation comment   Source   Edit
func mismatchStart(str1, str2: string): int {.inline, ...raises: [], tags: [].}
Find position where two strings mismatch first   Source   Edit
func msgjoin(args: varargs[string, `$`]): string {.inline, ...raises: [], tags: [].}
Concatenate arguments by adding whitespaces when necessary. When string ends with _, ', " or other similar characters (used when wrapping things like in msgjoin("_", text, "_")). Whitespace is omitted when strings ends with any of [('#@ + wrapper characters or next one starts with , . + wrapper characters. Wrapper characters are: _' "   Source   Edit
func msgjoinImpl(args: seq[string]): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func posString(node: NimNode): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func replaceN(str: string; n: int; subst: char = ' '): string {.inline,
    ...raises: [], tags: [].}
Replace first n characters in string with subst   Source   Edit
func skip1(s: string; part: StrPart): int {....raises: [], tags: [].}
  Source   Edit
func snakeToCamelCase(str: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func splitCamel(str: string; dropUnderscore: bool = true;
                splitUnderscores: bool = true; mergeCapitalized: bool = true;
                adaptiveMerge: bool = true): seq[string] {.inline, ...raises: [],
    tags: [].}
Split abbreviation as camelCase identifier
  • @arg{dropUnderscore} :: Drop all _ characters if found
  • @arg{splitUnderscores} :: Split on _ characters
  • @arg{mergeCapitalized} :: Do not split consecutive capitalized
  • @arg{adaptiveMerge} :: Employ additional heuristics to make capitalized chunk splits more 'logical'. DBManager -> DB + Manager, but FILE -> FILE
  Source   Edit
func splitSnake(str: string): seq[string] {.inline, ...raises: [], tags: [].}
  Source   Edit
func splitTokenize(str: string; seps: seq[string]): seq[string] {.inline,
    ...raises: [], tags: [].}
  Source   Edit
func splitTokenize(str: string; seps: set[char]; sweep: bool = false): seq[
    string] {.inline, ...raises: [], tags: [].}
  Source   Edit
func startsWith(s: string; part: StrPart): bool {....raises: [], tags: [].}
  Source   Edit
func startsWith(str: string; pref: varargs[string]): bool {.inline, ...raises: [],
    tags: [].}
True if string starts with any of the prefixes   Source   Edit
func startsWith(str: string; skip: set[char]; pref: set[char]): bool {.inline,
    ...raises: [], tags: [].}
Return true if string has prefix <skip*><pref> - one or more occurencies of chars in skip set, followed by prefix.   Source   Edit
func startsWith(str: string; skip: set[char]; pref: string): bool {.inline,
    ...raises: [], tags: [].}
Return true if string has prefix <skip*><pref> - one or more occurencies of chars in skip set, followed by prefix.   Source   Edit
func toDashedCase(str: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func toSnakeCamelCase(str: string): string {.
    ...deprecated: "Use `snakeToCamelCase` instead", inline, ...raises: [], tags: [].}
Deprecated: Use `snakeToCamelCase` instead
  Source   Edit
func toSnakeCase(str: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func toUpperAscii(strs: seq[string]): seq[string] {.inline, inline, ...raises: [],
    tags: [].}
  Source   Edit
func wrap(str, left, right: string): string {.inline, ...raises: [], tags: [].}
  Source   Edit
func wrap(str: string; delim: string): string {.inline, ...raises: [], tags: [].}
Split delim in two, use wrap str in left and right halves.   Source   Edit
func wrap(str: string; delim: tuple[left, right: string]): string {.inline,
    ...raises: [], tags: [].}
Check if string starts and ends with strings.   Source   Edit
func wrap(str: string; left, right: char): string {.inline, inline, ...raises: [],
    tags: [].}
  Source   Edit

Iterators

iterator interpolatedExprs(s: string): tuple[kind: InterpolatedExprKind,
    value: string] {.inline, ...raises: [ValueError], tags: [].}
  Source   Edit
iterator items(part: StrPart): StrPart {.inline, ...raises: [], tags: [].}
  Source   Edit

Converters

converter toStrPart(c: char): StrPart {....raises: [], tags: [].}
  Source   Edit
converter toStrPart(cs: set[char]): StrPart {....raises: [], tags: [].}
  Source   Edit
converter toStrPart(s: openArray[string]): StrPart {....raises: [], tags: [].}
  Source   Edit
converter toStrPart(s: string): StrPart {....raises: [], tags: [].}
  Source   Edit
converter toStrPartTuple[A: StrPartConv; B: StrPartConv](indata: (A, B)): StrPartTuple
  Source   Edit

Macros

macro fmt3(arg: string{lit}): untyped {.inline.}
  Source   Edit
macro joinLiteral(body: untyped): untyped {.inline.}
  Source   Edit
macro lit3(arg: string{lit}): untyped {.inline.}
  Source   Edit

Templates

template fmtJoin(body: untyped): untyped
  Source   Edit