diff options
author | dom96 <dominikpicheta@googlemail.com> | 2011-12-19 21:09:17 +0000 |
---|---|---|
committer | dom96 <dominikpicheta@googlemail.com> | 2011-12-19 21:09:17 +0000 |
commit | 4f08946f64f04ef85a53c686fb89b8d84fbc6d65 (patch) | |
tree | b354e99bdffec4463c7c7b38166dc7381cd2ebf8 | |
parent | fff9276cf66827b7ddde8636d1cf6b50a0dd4417 (diff) | |
download | Nim-4f08946f64f04ef85a53c686fb89b8d84fbc6d65.tar.gz |
fixes #77
-rwxr-xr-x | lib/pure/strutils.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 33bb5b5f0..46dcb3849 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -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".} = |