Merge branch 'master' of github.com:Araq/Nimrod

This commit is contained in:
Araq
2011-12-22 15:04:13 +01:00
6 changed files with 22 additions and 3 deletions

View File

@@ -467,6 +467,16 @@ proc ParseHexInt*(s: string): int {.noSideEffect, procvar,
inc(i)
of '\0': break
else: raise newException(EInvalidValue, "invalid integer: " & s)
proc parseBool*(s: string): bool =
## Parses a value into a `bool`. If ``s`` is one of the following values:
## ``y, yes, true, 1, on``, then returns `true`. If ``s`` is one of the
## following values: ``n, no, false, 0, off``, then returns `false`.
## If ``s`` is something else a ``EInvalidValue`` exception is raised.
case normalize(s)
of "y", "yes", "true", "1", "on": result = true
of "n", "no", "false", "0", "off": result = false
else: raise newException(EInvalidValue, "cannot interpret as a bool: " & s)
proc repeatChar*(count: int, c: Char = ' '): string {.noSideEffect,
rtl, extern: "nsuRepeatChar".} =