exported strutils.abbrev
This commit is contained in:
parent
96e7ee91cc
commit
f0172b0a5f
4 changed files with 17 additions and 18 deletions
|
|
@ -174,9 +174,9 @@ The `incompleteStruct`:idx: pragma tells the compiler to not use the
|
||||||
underlying C ``struct`` in a ``sizeof`` expression:
|
underlying C ``struct`` in a ``sizeof`` expression:
|
||||||
|
|
||||||
.. code-block:: Nimrod
|
.. code-block:: Nimrod
|
||||||
type
|
type
|
||||||
TDIR* {.importc: "DIR", header: "<dirent.h>",
|
TDIR* {.importc: "DIR", header: "<dirent.h>",
|
||||||
final, pure, incompleteStruct.} = object
|
final, pure, incompleteStruct.} = object
|
||||||
|
|
||||||
|
|
||||||
Compile pragma
|
Compile pragma
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nimrod's Runtime Library
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2010 Andreas Rumpf
|
# (c) Copyright 2012 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nimrod's Runtime Library
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2010 Andreas Rumpf
|
# (c) Copyright 2012 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
|
||||||
|
|
@ -542,19 +542,18 @@ proc allCharsInSet*(s: string, theSet: TCharSet): bool =
|
||||||
if c notin theSet: return false
|
if c notin theSet: return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# 012345
|
proc abbrev*(s: string, possibilities: openarray[string]): int =
|
||||||
# 345
|
## returns the index of the first item in `possibilities` if not
|
||||||
|
## ambiguous; -1 if no item has been found; -2 if multiple items
|
||||||
when false:
|
## match.
|
||||||
proc abbrev(s: string, possibilities: openarray[string]): int =
|
result = -1 # none found
|
||||||
## returns the index of the first item in `possibilities` if not
|
for i in 0..possibilities.len-1:
|
||||||
## ambiguous; -1 if no item has been found; -2 if multiple items
|
if possibilities[i].startsWith(s):
|
||||||
## match.
|
if possibilities[i] == s:
|
||||||
result = -1 # none found
|
# special case: exact match shouldn't be ambiguous
|
||||||
for i in 0..possibilities.len-1:
|
return i
|
||||||
if possibilities[i].startsWith(s):
|
if result >= 0: return -2 # ambiguous
|
||||||
if result >= 0: return -2 # ambiguous
|
result = i
|
||||||
result = i
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue