summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-02-24 19:19:13 +0100
committerAraq <rumpf_a@web.de>2012-02-24 19:19:13 +0100
commitf0172b0a5fdb618265eb20fb03dd720e970f95a7 (patch)
tree3ddd91ae4cc35fd3e6a6da8718da902a5493c7ab
parent96e7ee91cced216e287b9dadb6eec97147347989 (diff)
downloadNim-f0172b0a5fdb618265eb20fb03dd720e970f95a7.tar.gz
exported strutils.abbrev
-rwxr-xr-xdoc/nimrodc.txt6
-rwxr-xr-xlib/pure/cgi.nim2
-rwxr-xr-xlib/pure/gentabs.nim2
-rwxr-xr-xlib/pure/strutils.nim25
4 files changed, 17 insertions, 18 deletions
diff --git a/doc/nimrodc.txt b/doc/nimrodc.txt
index 77a96ee74..7e1df29fa 100755
--- a/doc/nimrodc.txt
+++ b/doc/nimrodc.txt
@@ -174,9 +174,9 @@ The `incompleteStruct`:idx: pragma tells the compiler to not use the
 underlying C ``struct`` in a ``sizeof`` expression:

 

 .. code-block:: Nimrod

-type

-  TDIR* {.importc: "DIR", header: "<dirent.h>", 

-          final, pure, incompleteStruct.} = object

+  type

+    TDIR* {.importc: "DIR", header: "<dirent.h>", 

+            final, pure, incompleteStruct.} = object

 

 

 Compile pragma

diff --git a/lib/pure/cgi.nim b/lib/pure/cgi.nim
index c6e294374..0f0948118 100755
--- a/lib/pure/cgi.nim
+++ b/lib/pure/cgi.nim
@@ -1,7 +1,7 @@
 #
 #
 #            Nimrod's Runtime Library
-#        (c) Copyright 2010 Andreas Rumpf
+#        (c) Copyright 2012 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
diff --git a/lib/pure/gentabs.nim b/lib/pure/gentabs.nim
index 1d000ba8c..617473c14 100755
--- a/lib/pure/gentabs.nim
+++ b/lib/pure/gentabs.nim
@@ -1,7 +1,7 @@
 #
 #
 #            Nimrod's Runtime Library
-#        (c) Copyright 2010 Andreas Rumpf
+#        (c) Copyright 2012 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 0bfec8894..97748c103 100755
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -542,19 +542,18 @@ proc allCharsInSet*(s: string, theSet: TCharSet): bool =
     if c notin theSet: return false

   return true

 

-# 012345

-#    345

-

-when false:

-  proc abbrev(s: string, possibilities: openarray[string]): int =

-    ## returns the index of the first item in `possibilities` if not

-    ## ambiguous; -1 if no item has been found; -2 if multiple items

-    ## match.

-    result = -1 # none found

-    for i in 0..possibilities.len-1:

-      if possibilities[i].startsWith(s):

-        if result >= 0: return -2 # ambiguous

-        result = i

+proc abbrev*(s: string, possibilities: openarray[string]): int =

+  ## returns the index of the first item in `possibilities` if not

+  ## ambiguous; -1 if no item has been found; -2 if multiple items

+  ## match.

+  result = -1 # none found

+  for i in 0..possibilities.len-1:

+    if possibilities[i].startsWith(s):

+      if possibilities[i] == s:

+        # special case: exact match shouldn't be ambiguous

+        return i

+      if result >= 0: return -2 # ambiguous

+      result = i

 

 # ---------------------------------------------------------------------------