Skip to content

Commit e9ba753

Browse files
jdmbrson
authored andcommitted
---
yaml --- r: 24558 b: refs/heads/try2 c: 10fd195 h: refs/heads/master v: v3
1 parent e69a116 commit e9ba753

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 195dd54d61c32ca983b1f81237570e9b0e70abbd
8+
refs/heads/try2: 10fd19580ed1f2caed28e90893f2f4889760265d
99
refs/heads/incoming: 05543fd04dfb3f63b453a331e239ceb1a9a219f9
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libstd/getopts.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,36 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
220220
}
221221
} else {
222222
let mut j = 1u;
223+
let mut last_valid_opt_id = option::none;
223224
names = ~[];
224225
while j < curlen {
225226
let range = str::char_range_at(cur, j);
226-
vec::push(names, short(range.ch));
227+
let opt = short(range.ch);
228+
229+
/* In a series of potential options (eg. -aheJ), if we see
230+
one which takes an argument, we assume all subsequent
231+
characters make up the argument. This allows options
232+
such as -L/usr/local/lib/foo to be interpreted correctly
233+
*/
234+
alt find_opt(opts, opt) {
235+
some(id) {
236+
last_valid_opt_id = option::some(id);
237+
}
238+
none {
239+
let arg_follows = option::is_some(last_valid_opt_id) &&
240+
alt opts[option::get(last_valid_opt_id)].hasarg {
241+
yes | maybe { true }
242+
no { false }
243+
};
244+
if arg_follows && j + 1 < curlen {
245+
i_arg = option::some(str::slice(cur, j, curlen));
246+
break;
247+
} else {
248+
last_valid_opt_id = option::none;
249+
}
250+
}
251+
}
252+
vec::push(names, opt);
227253
j = range.next;
228254
}
229255
}
@@ -857,6 +883,18 @@ mod tests {
857883
assert opts_str(match, ~["e", "encrypt"]) == "foo";
858884
assert opts_str(match, ~["encrypt", "e"]) == "foo";
859885
}
886+
887+
#[test]
888+
fn test_nospace() {
889+
let args = ~["-Lfoo"];
890+
let opts = ~[optmulti("L")];
891+
let match = alt getopts(args, opts) {
892+
result::ok(m) { m }
893+
result::err(f) { fail; }
894+
};
895+
assert opts_present(match, ~["L"]);
896+
assert opts_str(match, ~["L"]) == "foo";
897+
}
860898
}
861899

862900
// Local Variables:

0 commit comments

Comments
 (0)