summary refs log tree commit diff stats
path: root/lib/pure/strutils.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/strutils.nim')
-rwxr-xr-xlib/pure/strutils.nim25
1 files changed, 12 insertions, 13 deletions
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

 

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