summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-12-28 23:30:53 +0100
committerAraq <rumpf_a@web.de>2013-12-28 23:30:53 +0100
commit1101a40f91880b6cd1f0807d2b272eda7b5c9491 (patch)
tree650531f24cec9b67ffee2a36f4fa0eb2de3144d8 /lib/pure
parentf2b9905b4e4365e0dd51a67ad90ac690f584feca (diff)
downloadNim-1101a40f91880b6cd1f0807d2b272eda7b5c9491.tar.gz
improvements for 'pretty'
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/os.nim56
-rw-r--r--lib/pure/strutils.nim20
-rw-r--r--lib/pure/times.nim2
3 files changed, 39 insertions, 39 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index fbca89f52..202052bc6 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -96,8 +96,8 @@ elif defined(macos):
     CurDir* = ':'
     ParDir* = "::"
     Dirsep* = ':'
-    Altsep* = dirsep
-    Pathsep* = ','
+    Altsep* = Dirsep
+    PathSep* = ','
     FileSystemCaseSensitive* = false
     ExeExt* = ""
     ScriptExt* = ""
@@ -135,7 +135,7 @@ elif doslike:
 elif defined(PalmOS) or defined(MorphOS):
   const
     Dirsep* = '/'
-    Altsep* = dirsep
+    Altsep* = Dirsep
     PathSep* = ';'
     Pardir* = ".."
     FileSystemCaseSensitive* = false
@@ -157,7 +157,7 @@ else: # UNIX-like operating system
     Curdir* = '.'
     Pardir* = ".."
     Dirsep* = '/'
-    Altsep* = dirsep
+    Altsep* = Dirsep
     PathSep* = ':'
     FileSystemCaseSensitive* = true
     ExeExt* = ""
@@ -304,11 +304,11 @@ proc unixToNativePath*(path: string): string {.
       elif defined(macos):
         result = "" # must not start with ':'
       else:
-        result = $dirSep
+        result = $DirSep
       start = 1
     elif path[0] == '.' and path[1] == '/':
       # current directory
-      result = $curdir
+      result = $Curdir
       start = 2
     else:
       result = ""
@@ -322,12 +322,12 @@ proc unixToNativePath*(path: string): string {.
           if result[high(result)] == ':':
             add result, ':'
           else:
-            add result, pardir
+            add result, ParDir
         else:
-          add result, pardir & dirSep
+          add result, ParDir & DirSep
         inc(i, 3)
       elif path[i] == '/':
-        add result, dirSep
+        add result, DirSep
         inc(i)
       else:
         add result, path[i]
@@ -538,7 +538,7 @@ proc splitPath*(path: string): tuple[head, tail: string] {.
   ##   splitPath("") -> ("", "")
   var sepPos = -1
   for i in countdown(len(path)-1, 0):
-    if path[i] in {dirsep, altsep}:
+    if path[i] in {Dirsep, Altsep}:
       sepPos = i
       break
   if sepPos >= 0:
@@ -550,9 +550,9 @@ proc splitPath*(path: string): tuple[head, tail: string] {.
 
 proc parentDirPos(path: string): int =
   var q = 1
-  if path[len(path)-1] in {dirsep, altsep}: q = 2
+  if path[len(path)-1] in {Dirsep, Altsep}: q = 2
   for i in countdown(len(path)-q, 0):
-    if path[i] in {dirsep, altsep}: return i
+    if path[i] in {Dirsep, Altsep}: return i
   result = -1
 
 proc parentDir*(path: string): string {.
@@ -593,8 +593,8 @@ iterator parentDirs*(path: string, fromRoot=false, inclusive=true): string =
   else:
     for i in countup(0, path.len - 2): # ignore the last /
       # deal with non-normalized paths such as /foo//bar//baz
-      if path[i] in {dirsep, altsep} and
-          (i == 0 or path[i-1] notin {dirsep, altsep}):
+      if path[i] in {Dirsep, Altsep} and
+          (i == 0 or path[i-1] notin {Dirsep, Altsep}):
         yield path.substr(0, i)
 
     if inclusive: yield path
@@ -609,17 +609,17 @@ proc `/../` * (head, tail: string): string {.noSideEffect.} =
     result = head / tail
 
 proc normExt(ext: string): string =
-  if ext == "" or ext[0] == extSep: result = ext # no copy needed here
-  else: result = extSep & ext
+  if ext == "" or ext[0] == ExtSep: result = ext # no copy needed here
+  else: result = ExtSep & ext
 
 proc searchExtPos(s: string): int =
   # BUGFIX: do not search until 0! .DS_Store is no file extension!
   result = -1
   for i in countdown(len(s)-1, 1):
-    if s[i] == extsep:
+    if s[i] == ExtSep:
       result = i
       break
-    elif s[i] in {dirsep, altsep}:
+    elif s[i] in {Dirsep, Altsep}:
       break # do not skip over path
 
 proc splitFile*(path: string): tuple[dir, name, ext: string] {.
@@ -639,7 +639,7 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
   ## If `path` has no extension, `ext` is the empty string.
   ## If `path` has no directory component, `dir` is the empty string.
   ## If `path` has no filename component, `name` and `ext` are empty strings.
-  if path.len == 0 or path[path.len-1] in {dirSep, altSep}:
+  if path.len == 0 or path[path.len-1] in {DirSep, Altsep}:
     result = (path, "", "")
   else:
     var sepPos = -1
@@ -647,8 +647,8 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
     for i in countdown(len(path)-1, 0):
       if path[i] == ExtSep:
         if dotPos == path.len and i > 0 and
-            path[i-1] notin {dirsep, altsep}: dotPos = i
-      elif path[i] in {dirsep, altsep}:
+            path[i-1] notin {Dirsep, Altsep}: dotPos = i
+      elif path[i] in {Dirsep, Altsep}:
         sepPos = i
         break
     result.dir = substr(path, 0, sepPos-1)
@@ -659,7 +659,7 @@ proc extractFilename*(path: string): string {.
   noSideEffect, rtl, extern: "nos$1".} =
   ## Extracts the filename of a given `path`. This is the same as
   ## ``name & ext`` from ``splitFile(path)``.
-  if path.len == 0 or path[path.len-1] in {dirSep, altSep}:
+  if path.len == 0 or path[path.len-1] in {DirSep, Altsep}:
     result = ""
   else:
     result = splitPath(path).tail
@@ -816,7 +816,7 @@ proc sameFileContent*(path1, path2: string): bool {.rtl, extern: "nos$1",
     return false
   var bufA = alloc(bufsize)
   var bufB = alloc(bufsize)
-  while True:
+  while true:
     var readA = readBuffer(a, bufA, bufsize)
     var readB = readBuffer(b, bufB, bufsize)
     if readA != readB:
@@ -1032,7 +1032,7 @@ when defined(windows):
           env = getEnvironmentStringsW()
           e = env
         if e == nil: return # an error occured
-        while True:
+        while true:
           var eend = strEnd(e)
           add(environment, $e)
           e = cast[WideCString](cast[TAddress](eend)+2)
@@ -1043,7 +1043,7 @@ when defined(windows):
           env = getEnvironmentStringsA()
           e = env
         if e == nil: return # an error occured
-        while True:
+        while true:
           var eend = strEnd(e)
           add(environment, $e)
           e = cast[CString](cast[TAddress](eend)+1)
@@ -1308,7 +1308,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
   when defined(doslike):
     omitNext = isAbsolute(dir)
   for i in 1.. dir.len-1:
-    if dir[i] in {dirsep, altsep}:
+    if dir[i] in {Dirsep, Altsep}:
       if omitNext:
         omitNext = false
       else:
@@ -1635,10 +1635,10 @@ proc findExe*(exe: string): string {.tags: [FReadDir, FReadEnv].} =
   ## in directories listed in the ``PATH`` environment variable.
   ## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe`
   ## is added an ``.exe`` file extension if it has no extension.
-  result = addFileExt(exe, os.exeExt)
+  result = addFileExt(exe, os.ExeExt)
   if existsFile(result): return
   var path = string(os.getEnv("PATH"))
-  for candidate in split(path, pathSep):
+  for candidate in split(path, PathSep):
     var x = candidate / result
     if existsFile(x): return x
   result = ""
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index b7e3de6cf..2a6d499a7 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -67,7 +67,7 @@ proc toUpper*(c: char): char {.noSideEffect, procvar,
   ## Converts `c` into upper case. This works only for the letters a-z.
   ## See `unicode.toUpper` for a version that works for any Unicode character.
   if c in {'a'..'z'}:
-    result = chr(ord(c) - (Ord('a') - Ord('A')))
+    result = chr(ord(c) - (ord('a') - ord('A')))
   else:
     result = c
 
@@ -497,31 +497,31 @@ iterator tokenize*(s: string, seps: set[char] = Whitespace): tuple[
 
 proc wordWrap*(s: string, maxLineWidth = 80,
                splitLongWords = true,
-               seps: set[char] = whitespace,
+               seps: set[char] = Whitespace,
                newLine = "\n"): string {.
                noSideEffect, rtl, extern: "nsuWordWrap".} =
   ## word wraps `s`.
   result = newStringOfCap(s.len + s.len shr 6)
-  var SpaceLeft = maxLineWidth
+  var spaceLeft = maxLineWidth
   for word, isSep in tokenize(s, seps):
-    if len(word) > SpaceLeft:
+    if len(word) > spaceLeft:
       if splitLongWords and len(word) > maxLineWidth:
-        result.add(substr(word, 0, SpaceLeft-1))
-        var w = SpaceLeft+1
-        var wordLeft = len(word) - SpaceLeft
+        result.add(substr(word, 0, spaceLeft-1))
+        var w = spaceLeft+1
+        var wordLeft = len(word) - spaceLeft
         while wordLeft > 0:
           result.add(newLine)
           var L = min(maxLineWidth, wordLeft)
-          SpaceLeft = maxLineWidth - L
+          spaceLeft = maxLineWidth - L
           result.add(substr(word, w, w+L-1))
           inc(w, L)
           dec(wordLeft, L)
       else:
-        SpaceLeft = maxLineWidth - len(word)
+        spaceLeft = maxLineWidth - len(word)
         result.add(newLine)
         result.add(word)
     else:
-      SpaceLeft = SpaceLeft - len(word)
+      spaceLeft = spaceLeft - len(word)
       result.add(word)
 
 proc unindent*(s: string, eatAllIndent = false): string {.
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index 6dfe80ca1..246126828 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -593,7 +593,7 @@ proc format*(info: TTimeInfo, f: string): string =
   result = ""
   var i = 0
   var currentF = ""
-  while True:
+  while true:
     case f[i]
     of ' ', '-', '/', ':', '\'', '\0', '(', ')', '[', ']', ',':
       case currentF