Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strutils new sets #18193

Closed
wants to merge 18 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions lib/pure/strutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,39 @@ from std/private/strimpl import cmpIgnoreStyleImpl, cmpIgnoreCaseImpl, startsWit


const
Whitespace* = {' ', '\t', '\v', '\r', '\l', '\f'}
Whitespace* = {' ', '\t', '\v', '\r', '\n', '\f'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, a separate PR would be welcome to change all instances of \l to \n in nim repo (and it'd only do that plus maybe related changes)

## All the characters that count as whitespace (space, tab, vertical tab,
## carriage return, new line, form feed).

Letters* = {'A'..'Z', 'a'..'z'}
## The set of letters.

Vowels* = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}
kintrix007 marked this conversation as resolved.
Show resolved Hide resolved
## The set of vowels.

kintrix007 marked this conversation as resolved.
Show resolved Hide resolved
Consonants* = Letters - Vowels
kintrix007 marked this conversation as resolved.
Show resolved Hide resolved
## The set of consonants.

Digits* = {'0'..'9'}
## The set of digits.

HexDigits* = {'0'..'9', 'A'..'F', 'a'..'f'}
HexDigits* = Digits + {'A'..'F', 'a'..'f'}
## The set of hexadecimal digits.

IdentChars* = {'a'..'z', 'A'..'Z', '0'..'9', '_'}
IdentChars* = Letters + Digits + {'_'}
## The set of characters an identifier can consist of.

IdentStartChars* = {'a'..'z', 'A'..'Z', '_'}
IdentStartChars* = Letters + {'_'}
## The set of characters an identifier can start with.

Newlines* = {'\13', '\10'}
## The set of characters a newline terminator can start with (carriage
## return, line feed).
Newlines* = {'\r', '\n'}
## The set of characters a newline terminator can consist of

Punctuation* = {'!'..'/'} - {'+', '$'} + {':', ';', '?', '@', '['..']', '_', '{', '}', '\161','\167','\171','\182','\183','\187','\191'}
kintrix007 marked this conversation as resolved.
Show resolved Hide resolved
## The set of all ASCII punctuation characters.

AllChars* = {'\x00'..'\xFF'}
## A set with all the possible characters.
## The set with all the possible characters.
kintrix007 marked this conversation as resolved.
Show resolved Hide resolved
##
## Not very useful by its own, you can use it to create *inverted* sets to
## make the `find func<#find,string,set[char],Natural,int>`_
Expand Down Expand Up @@ -185,6 +193,10 @@ func isUpperAscii*(c: char): bool {.rtl, extern: "nsuIsUpperAsciiChar".} =
doAssert isUpperAscii('7') == false
return c in {'A'..'Z'}

template toImpl(call) =
timotheecour marked this conversation as resolved.
Show resolved Hide resolved
result = newString(len(s))
for i in 0..len(s) - 1:
result[i] = call(s[i])

func toLowerAscii*(c: char): char {.rtl, extern: "nsuToLowerAsciiChar".} =
## Returns the lower case version of character `c`.
Expand All @@ -204,11 +216,6 @@ func toLowerAscii*(c: char): char {.rtl, extern: "nsuToLowerAsciiChar".} =
else:
result = c

template toImpl(call) =
result = newString(len(s))
for i in 0..len(s) - 1:
result[i] = call(s[i])

func toLowerAscii*(s: string): string {.rtl, extern: "nsuToLowerAsciiStr".} =
## Converts string `s` into lower case.
##
Expand Down