Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
e17a778d56
5 changed files with 40 additions and 8 deletions
|
|
@ -411,7 +411,7 @@ proc JoinPath*(head, tail: string): string {.
|
|||
else:
|
||||
result = head & DirSep & tail
|
||||
|
||||
proc JoinPath*(parts: openarray[string]): string {.noSideEffect,
|
||||
proc JoinPath*(parts: varargs[string]): string {.noSideEffect,
|
||||
rtl, extern: "nos$1OpenArray".} =
|
||||
## The same as `JoinPath(head, tail)`, but works with any number
|
||||
## of directory parts.
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ proc ssAtEnd(s: PStream): bool =
|
|||
|
||||
proc ssSetPosition(s: PStream, pos: int) =
|
||||
var s = PStringStream(s)
|
||||
s.pos = min(pos, s.data.len-1)
|
||||
s.pos = clamp(pos, 0, s.data.high)
|
||||
|
||||
proc ssGetPosition(s: PStream): int =
|
||||
var s = PStringStream(s)
|
||||
|
|
|
|||
|
|
@ -654,6 +654,20 @@ proc find*(s: string, chars: set[char], start: int = 0): int {.noSideEffect,
|
|||
for i in start..s.len-1:
|
||||
if s[i] in chars: return i
|
||||
return -1
|
||||
|
||||
proc rfind*(s, sub: string, start: int = -1): int {.noSideEffect.} =
|
||||
## Searches for `sub` in `s` in reverse, starting at `start` and going
|
||||
## backwards to 0. Searching is case-sensitive. If `sub` is not in `s`, -1 is
|
||||
## returned.
|
||||
let realStart = if start == -1: s.len else: start
|
||||
for i in countdown(realStart-sub.len, 0):
|
||||
for j in 0..sub.len-1:
|
||||
result = i
|
||||
if sub[j] != s[i+j]:
|
||||
result = -1
|
||||
break
|
||||
if result != -1: return
|
||||
return -1
|
||||
|
||||
proc quoteIfContainsWhite*(s: string): string =
|
||||
## returns ``'"' & s & '"'`` if `s` contains a space and does not
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue