src/pylib/Lib/string

Source   Edit  

Types

Template = distinct string
Hint: Currently inheriting Template is not supported. (In Python, you can custom formatting via defining subclass of Template and overwrite some attributes).
Warning:

Currently substitute is implemented via % in std/strutils, in which there are two different behaviors from Python's Template:

1. the variables are compared with cmpIgnoreStyle, whereas in Python they are compared in 'ignorecase' flag by default.

2. digit or # following the dollar (e.g. $1) is allowed, and will be substituted by variable at such position, whereas in Python such will cause ValueError.

3. for unknown key, substitute raises ValueError instead of KeyError currently.

Source   Edit  

Consts

ascii_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Source   Edit  
ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"
Source   Edit  
ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Source   Edit  
digits = "0123456789"
Source   Edit  
hexdigits = "0123456789abcdefABCDEF"
Source   Edit  
octdigits = "01234567"
Source   Edit  
printable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\\\'()*+,-./:;<=>?@[\\\\]^_`{|}~ \t\n\r\v\f"
Source   Edit  
punctuation = """!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"""
Source   Edit  
whitespace = " \t\n\r\v\f"
Source   Edit  

Procs

func capwords(a: StringLike): PyStr

Mimics Python string.capwords(s) -> str:

Runs of whitespace characters are replaced by a single space and leading and trailing whitespace are removed.

Source   Edit  
func capwords(a: StringLike; sep: StringLike): PyStr

Mimics Python string.capwords(s, sep) -> str:

Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. sep is used to split and join the words.

Source   Edit  
func substitute(templ: Template): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  

Macros

macro substitute(templ: Template; kws: varargs[untyped]): PyStr
Template.substitute(**kws) Source   Edit  
macro substitute(templ: Template; mapping: Mapping; kws: varargs[untyped]): PyStr

Template.substitute(mapping, **kws)

where kws is preferred if the same key occurs in mapping

Source   Edit