summary refs log tree commit diff stats
path: root/lib/pure/strutils.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-06-26 17:21:52 +0200
committerAraq <rumpf_a@web.de>2011-06-26 17:21:52 +0200
commit990dc2d7152f09c413d8fd96d66484d79aec97c7 (patch)
treea267c16996c61292c78019ab56d1116d811fd0dc /lib/pure/strutils.nim
parentdb0a4a9f86d167faccbd50f3f12f9de470e516b8 (diff)
downloadNim-990dc2d7152f09c413d8fd96d66484d79aec97c7.tar.gz
code gen bugfixes; marshal.nim implemented
Diffstat (limited to 'lib/pure/strutils.nim')
-rwxr-xr-xlib/pure/strutils.nim80
1 files changed, 40 insertions, 40 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 8659c7d29..58e1e5fed 100755
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -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