From f0172b0a5fdb618265eb20fb03dd720e970f95a7 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 24 Feb 2012 19:19:13 +0100 Subject: exported strutils.abbrev --- doc/nimrodc.txt | 6 +++--- lib/pure/cgi.nim | 2 +- lib/pure/gentabs.nim | 2 +- lib/pure/strutils.nim | 25 ++++++++++++------------- 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: "", - final, pure, incompleteStruct.} = object + type + TDIR* {.importc: "DIR", header: "", + 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 # --------------------------------------------------------------------------- -- cgit 1.4.1-2-gfad0 lame/lib/pure/gentabs.nim?h=devel&id=f0172b0a5fdb618265eb20fb03dd720e970f95a7'>blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191