code gen bugfixes; marshal.nim implemented
This commit is contained in:
parent
db0a4a9f86
commit
990dc2d715
21 changed files with 725 additions and 422 deletions
|
|
@ -89,15 +89,15 @@ proc normalize*(s: string): string {.noSideEffect, procvar,
|
|||
rtl, extern: "nsuNormalize".} =
|
||||
## Normalizes the string `s`. That means to convert it to lower case and
|
||||
## remove any '_'. This is needed for Nimrod identifiers for example.
|
||||
result = newString(s.len)
|
||||
result = newString(s.len)
|
||||
var j = 0
|
||||
for i in 0..len(s) - 1:
|
||||
if s[i] in {'A'..'Z'}:
|
||||
result[j] = Chr(Ord(s[i]) + (Ord('a') - Ord('A')))
|
||||
result[j] = Chr(Ord(s[i]) + (Ord('a') - Ord('A')))
|
||||
inc j
|
||||
elif s[i] != '_':
|
||||
result[j] = s[i]
|
||||
inc j
|
||||
result[j] = s[i]
|
||||
inc j
|
||||
if j != s.len: setLen(result, j)
|
||||
|
||||
proc cmpIgnoreCase*(a, b: string): int {.noSideEffect,
|
||||
|
|
@ -461,7 +461,7 @@ proc repeatChar*(count: int, c: Char = ' '): string {.noSideEffect,
|
|||
## the character `c`.
|
||||
result = newString(count)
|
||||
for i in 0..count-1: result[i] = c
|
||||
|
||||
|
||||
proc repeatStr*(count: int, s: string): string {.noSideEffect,
|
||||
rtl, extern: "nsuRepeatStr".} =
|
||||
## Returns `s` concatenated `count` times.
|
||||
|
|
@ -480,40 +480,40 @@ proc align*(s: string, count: int): string {.
|
|||
for i in spaces..count-1: result[i] = s[i-spaces]
|
||||
else:
|
||||
result = s
|
||||
|
||||
iterator tokenize*(s: string, seps: set[char] = Whitespace): tuple[
|
||||
token: string, isSep: bool] =
|
||||
## Tokenizes the string `s` into substrings.
|
||||
##
|
||||
## Substrings are separated by a substring containing only `seps`.
|
||||
## Examples:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## for word in tokenize(" this is an example "):
|
||||
## writeln(stdout, word)
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## (" ", true)
|
||||
## ("this", false)
|
||||
## (" ", true)
|
||||
## ("is", false)
|
||||
## (" ", true)
|
||||
## ("an", false)
|
||||
## (" ", true)
|
||||
## ("example", false)
|
||||
## (" ", true)
|
||||
var i = 0
|
||||
while true:
|
||||
var j = i
|
||||
var isSep = s[j] in seps
|
||||
while j < s.len and (s[j] in seps) == isSep: inc(j)
|
||||
if j > i:
|
||||
yield (substr(s, i, j-1), isSep)
|
||||
else:
|
||||
break
|
||||
i = j
|
||||
|
||||
iterator tokenize*(s: string, seps: set[char] = Whitespace): tuple[
|
||||
token: string, isSep: bool] =
|
||||
## Tokenizes the string `s` into substrings.
|
||||
##
|
||||
## Substrings are separated by a substring containing only `seps`.
|
||||
## Examples:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## for word in tokenize(" this is an example "):
|
||||
## writeln(stdout, word)
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## (" ", true)
|
||||
## ("this", false)
|
||||
## (" ", true)
|
||||
## ("is", false)
|
||||
## (" ", true)
|
||||
## ("an", false)
|
||||
## (" ", true)
|
||||
## ("example", false)
|
||||
## (" ", true)
|
||||
var i = 0
|
||||
while true:
|
||||
var j = i
|
||||
var isSep = s[j] in seps
|
||||
while j < s.len and (s[j] in seps) == isSep: inc(j)
|
||||
if j > i:
|
||||
yield (substr(s, i, j-1), isSep)
|
||||
else:
|
||||
break
|
||||
i = j
|
||||
|
||||
proc wordWrap*(s: string, maxLineWidth = 80,
|
||||
splitLongWords = true,
|
||||
|
|
@ -815,7 +815,7 @@ proc escape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
|
|||
## The procedure has been designed so that its output is usable for many
|
||||
## different common syntaxes. The resulting string is prefixed with
|
||||
## `prefix` and suffixed with `suffix`. Both may be empty strings.
|
||||
result = newStringOfCap(s.len + s.len shr 2)
|
||||
result = newStringOfCap(s.len + s.len shr 2)
|
||||
result.add(prefix)
|
||||
for c in items(s):
|
||||
case c
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue