src/pylib/pystring/strimpl

Search:
Group by:
Source   Edit  

Types

PyStr = distinct string
Python str, use func str to get an instance Source   Edit  
StringLike = string | char | PyStr
Source   Edit  

Procs

func `$`(self: PyStr): string {.borrow, ...raises: [], tags: [], forbids: [].}
to Nim string Source   Edit  
func `+`(self: PyStr; s: PyStr): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  
func `+`(self: PyStr; s: StringLike): PyStr
Source   Edit  
func `+=`(mself; s: char) {....raises: [], tags: [], forbids: [].}
Source   Edit  
func `+=`(mself; s: PyStr) {....raises: [], tags: [], forbids: [].}
Source   Edit  
func `+=`(mself; s: string) {....raises: [], tags: [], forbids: [].}
Source   Edit  
func `==`(o: string; self: PyStr): bool {.borrow, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
func `==`(self: PyStr; o: PyStr): bool {.borrow, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
func `==`(self: PyStr; o: string): bool {.borrow, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
func `[]`(self: PyStr; i: HSlice[int, BackwardsIndex]): PyStr {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func `[]`(self: PyStr; i: int): PyStr {....raises: [], tags: [], forbids: [].}

Example:

assert str("你好")[1] == str("好")

str.__getitem__(int)

i may be negative to index from backward.

Source   Edit  
func `[]`(self: PyStr; i: Slice[int]): PyStr {....raises: [], tags: [], forbids: [].}
EXT. s[1..2] means s[1:3], and the latter is not valid Nim code Source   Edit  
func byteLen(self: PyStr): int {....raises: [], tags: [], forbids: [].}
EXT. len of bytes Source   Edit  
func contains(s: PyStr; c: char): bool {.borrow.}
Source   Edit  
func contains(s: PyStr; c: PyStr): bool {.borrow, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
func contains(s: PyStr; c: string): bool {.borrow, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
func fspath(self: PyStr): PyStr {....raises: [], tags: [], forbids: [].}
make a PathLike Source   Edit  
func getChar(self: PyStr; i: Natural): char {....raises: [], tags: [], forbids: [].}
EXT. get char by byte index. Source   Edit  
func len(c: char): int {....raises: [], tags: [], forbids: [].}
len('c'), always returns 1 Source   Edit  
func len(self: PyStr): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
func runeAtPos(self: PyStr; pos: int): Rune {.borrow, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc runeLenAt(self: PyStr; i: Natural): int {.borrow, ...raises: [], tags: [],
    forbids: [].}
EXT. i is byte index Source   Edit  
func str(a: Rune): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  
func str(c: char): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  
func str(object = ""): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  
func str(self: PyStr): PyStr {....raises: [], tags: [], forbids: [].}
copy Source   Edit  
proc substr(self: PyStr; start, last: int): PyStr {.borrow, ...raises: [],
    tags: [], forbids: [].}
EXT. byte index Source   Edit  
func toNimStr(self: PyStr): string {....deprecated: "use toNimString instead. will be removed since 0.10",
                                     raises: [], tags: [], forbids: [].}
Deprecated: use toNimString instead. will be removed since 0.10
Source   Edit  

Iterators

iterator chars(self: PyStr): char {....raises: [], tags: [], forbids: [].}
EXT. Source   Edit  
iterator items(self: PyStr): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  
iterator runes(self: PyStr): Rune {....raises: [], tags: [], forbids: [].}
EXT. Source   Edit  

Converters

converter toNimString(self: PyStr): string {....raises: [], tags: [], forbids: [].}
Source   Edit  
converter toPyStr(s: char): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  
converter toPyStr(s: Rune): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  
converter toPyStr(s: string): PyStr {....raises: [], tags: [], forbids: [].}
Source   Edit  

Templates

template `and`(a, b: PyStr): PyStr
Mimics Python str and str -> str. Returns a if a is not empty, otherwise b (even if it's empty) Source   Edit  
template `not`(s: PyStr): bool

Mimics Python not str -> bool.

"not" for strings, return true if the string is not nil or empty.

Source   Edit  
template `or`(a, b: PyStr): PyStr
Mimics Python str or str -> str. Returns a if a is not empty, otherwise b (even if it's empty) Source   Edit  
template str[O: object](o: O): PyStr
Source   Edit  
template str[T](a: T): PyStr

convert any object based on repr

This is alreadly a fallback, used for types without str defined.

In Python, if a object's type has no __str__, then it falls to use __repr__

Source   Edit