Skip to content

Commit fe324d3

Browse files
Modernize Comments
1 parent abb5da2 commit fe324d3

File tree

1 file changed

+83
-115
lines changed

1 file changed

+83
-115
lines changed

src/lib.rs

Lines changed: 83 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/*!
12-
* Support for matching file paths against Unix shell style patterns.
13-
*
14-
* The `glob` and `glob_with` functions, in concert with the `Paths`
15-
* type, allow querying the filesystem for all files that match a particular
16-
* pattern - just like the libc `glob` function (for an example see the `glob`
17-
* documentation). The methods on the `Pattern` type provide functionality
18-
* for checking if individual paths match a particular pattern - in a similar
19-
* manner to the libc `fnmatch` function
20-
*
21-
* For consistency across platforms, and for Windows support, this module
22-
* is implemented entirely in Rust rather than deferring to the libc
23-
* `glob`/`fnmatch` functions.
24-
*/
11+
//! Support for matching file paths against Unix shell style patterns.
12+
//!
13+
//! The `glob` and `glob_with` functions, in concert with the `Paths`
14+
//! type, allow querying the filesystem for all files that match a particular
15+
//! pattern - just like the libc `glob` function (for an example see the `glob`
16+
//! documentation). The methods on the `Pattern` type provide functionality
17+
//! for checking if individual paths match a particular pattern - in a similar
18+
//! manner to the libc `fnmatch` function
19+
//! For consistency across platforms, and for Windows support, this module
20+
//! is implemented entirely in Rust rather than deferring to the libc
21+
//! `glob`/`fnmatch` functions.
2522
2623
#![crate_name = "glob"]
2724
#![experimental]
@@ -37,18 +34,15 @@ use std::io::fs;
3734
use std::path::is_sep;
3835
use std::string::String;
3936

40-
/**
41-
* An iterator that yields Paths from the filesystem that match a particular
42-
* pattern - see the `glob` function for more details.
43-
*/
37+
/// An iterator that yields Paths from the filesystem that match a particular
38+
/// pattern - see the `glob` function for more details.
4439
pub struct Paths {
4540
dir_patterns: Vec<Pattern>,
4641
require_dir: bool,
4742
options: MatchOptions,
4843
todo: Vec<(Path,uint)>,
4944
}
5045

51-
///
5246
/// Return an iterator that produces all the Paths that match the given pattern,
5347
/// which may be absolute or relative to the current working directory.
5448
///
@@ -80,17 +74,15 @@ pub fn glob(pattern: &str) -> Paths {
8074
glob_with(pattern, MatchOptions::new())
8175
}
8276

83-
/**
84-
* Return an iterator that produces all the Paths that match the given pattern,
85-
* which may be absolute or relative to the current working directory.
86-
*
87-
* This function accepts Unix shell style patterns as described by `Pattern::new(..)`.
88-
* The options given are passed through unchanged to `Pattern::matches_with(..)` with
89-
* the exception that `require_literal_separator` is always set to `true` regardless of the
90-
* value passed to this function.
91-
*
92-
* Paths are yielded in alphabetical order, as absolute paths.
93-
*/
77+
/// Return an iterator that produces all the Paths that match the given pattern,
78+
/// which may be absolute or relative to the current working directory.
79+
///
80+
/// This function accepts Unix shell style patterns as described by `Pattern::new(..)`.
81+
/// The options given are passed through unchanged to `Pattern::matches_with(..)` with
82+
/// the exception that `require_literal_separator` is always set to `true` regardless of the
83+
/// value passed to this function.
84+
///
85+
/// Paths are yielded in alphabetical order, as absolute paths.
9486
pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
9587
#[cfg(windows)]
9688
fn check_windows_verbatim(p: &Path) -> bool { path::windows::is_verbatim(p) }
@@ -190,9 +182,7 @@ fn list_dir_sorted(path: &Path) -> Option<Vec<Path>> {
190182
}
191183
}
192184

193-
/**
194-
* A compiled Unix shell style pattern.
195-
*/
185+
/// A compiled Unix shell style pattern.
196186
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
197187
pub struct Pattern {
198188
tokens: Vec<PatternToken>,
@@ -222,25 +212,23 @@ enum MatchResult {
222212

223213
impl Pattern {
224214

225-
/**
226-
* This function compiles Unix shell style patterns: `?` matches any single
227-
* character, `*` matches any (possibly empty) sequence of characters and
228-
* `[...]` matches any character inside the brackets, unless the first
229-
* character is `!` in which case it matches any character except those
230-
* between the `!` and the `]`. Character sequences can also specify ranges
231-
* of characters, as ordered by Unicode, so e.g. `[0-9]` specifies any
232-
* character between 0 and 9 inclusive.
233-
*
234-
* The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets
235-
* (e.g. `[?]`). When a `]` occurs immediately following `[` or `[!` then
236-
* it is interpreted as being part of, rather then ending, the character
237-
* set, so `]` and NOT `]` can be matched by `[]]` and `[!]]` respectively.
238-
* The `-` character can be specified inside a character sequence pattern by
239-
* placing it at the start or the end, e.g. `[abc-]`.
240-
*
241-
* When a `[` does not have a closing `]` before the end of the string then
242-
* the `[` will be treated literally.
243-
*/
215+
/// This function compiles Unix shell style patterns: `?` matches any single
216+
/// character, `*` matches any (possibly empty) sequence of characters and
217+
/// `[...]` matches any character inside the brackets, unless the first
218+
/// character is `!` in which case it matches any character except those
219+
/// between the `!` and the `]`. Character sequences can also specify ranges
220+
/// of characters, as ordered by Unicode, so e.g. `[0-9]` specifies any
221+
/// character between 0 and 9 inclusive.
222+
///
223+
/// The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets
224+
/// (e.g. `[?]`). When a `]` occurs immediately following `[` or `[!` then
225+
/// it is interpreted as being part of, rather then ending, the character
226+
/// set, so `]` and NOT `]` can be matched by `[]]` and `[!]]` respectively.
227+
/// The `-` character can be specified inside a character sequence pattern by
228+
/// placing it at the start or the end, e.g. `[abc-]`.
229+
///
230+
/// When a `[` does not have a closing `]` before the end of the string then
231+
/// the `[` will be treated literally.
244232
pub fn new(pattern: &str) -> Pattern {
245233

246234
let chars = pattern.chars().collect::<Vec<_>>();
@@ -300,11 +288,9 @@ impl Pattern {
300288
Pattern { tokens: tokens }
301289
}
302290

303-
/**
304-
* Escape metacharacters within the given string by surrounding them in
305-
* brackets. The resulting string will, when compiled into a `Pattern`,
306-
* match the input string and nothing else.
307-
*/
291+
/// Escape metacharacters within the given string by surrounding them in
292+
/// brackets. The resulting string will, when compiled into a `Pattern`,
293+
/// match the input string and nothing else.
308294
pub fn escape(s: &str) -> String {
309295
let mut escaped = String::new();
310296
for c in s.chars() {
@@ -323,46 +309,38 @@ impl Pattern {
323309
escaped
324310
}
325311

326-
/**
327-
* Return if the given `str` matches this `Pattern` using the default
328-
* match options (i.e. `MatchOptions::new()`).
329-
*
330-
* # Example
331-
*
332-
* ```rust
333-
* use glob::Pattern;
334-
*
335-
* assert!(Pattern::new("c?t").matches("cat"));
336-
* assert!(Pattern::new("k[!e]tteh").matches("kitteh"));
337-
* assert!(Pattern::new("d*g").matches("doog"));
338-
* ```
339-
*/
312+
/// Return if the given `str` matches this `Pattern` using the default
313+
/// match options (i.e. `MatchOptions::new()`).
314+
///
315+
/// # Example
316+
///
317+
/// ```rust
318+
/// use glob::Pattern;
319+
///
320+
/// assert!(Pattern::new("c?t").matches("cat"));
321+
/// assert!(Pattern::new("k[!e]tteh").matches("kitteh"));
322+
/// assert!(Pattern::new("d*g").matches("doog"));
323+
/// ```
340324
pub fn matches(&self, str: &str) -> bool {
341325
self.matches_with(str, MatchOptions::new())
342326
}
343327

344-
/**
345-
* Return if the given `Path`, when converted to a `str`, matches this `Pattern`
346-
* using the default match options (i.e. `MatchOptions::new()`).
347-
*/
328+
/// Return if the given `Path`, when converted to a `str`, matches this `Pattern`
329+
/// using the default match options (i.e. `MatchOptions::new()`).
348330
pub fn matches_path(&self, path: &Path) -> bool {
349331
// FIXME (#9639): This needs to handle non-utf8 paths
350332
path.as_str().map_or(false, |s| {
351333
self.matches(s)
352334
})
353335
}
354336

355-
/**
356-
* Return if the given `str` matches this `Pattern` using the specified match options.
357-
*/
337+
/// Return if the given `str` matches this `Pattern` using the specified match options.
358338
pub fn matches_with(&self, str: &str, options: MatchOptions) -> bool {
359339
self.matches_from(None, str, 0, options) == Match
360340
}
361341

362-
/**
363-
* Return if the given `Path`, when converted to a `str`, matches this `Pattern`
364-
* using the specified match options.
365-
*/
342+
/// Return if the given `Path`, when converted to a `str`, matches this `Pattern`
343+
/// using the specified match options.
366344
pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool {
367345
// FIXME (#9639): This needs to handle non-utf8 paths
368346
path.as_str().map_or(false, |s| {
@@ -588,50 +566,40 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
588566
}
589567
}
590568

591-
/**
592-
* Configuration options to modify the behaviour of `Pattern::matches_with(..)`
593-
*/
569+
570+
/// Configuration options to modify the behaviour of `Pattern::matches_with(..)`
594571
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
595572
pub struct MatchOptions {
596-
597-
/**
598-
* Whether or not patterns should be matched in a case-sensitive manner. This
599-
* currently only considers upper/lower case relationships between ASCII characters,
600-
* but in future this might be extended to work with Unicode.
601-
*/
573+
/// Whether or not patterns should be matched in a case-sensitive manner. This
574+
/// currently only considers upper/lower case relationships between ASCII characters,
575+
/// but in future this might be extended to work with Unicode.
602576
pub case_sensitive: bool,
603577

604-
/**
605-
* If this is true then path-component separator characters (e.g. `/` on Posix)
606-
* must be matched by a literal `/`, rather than by `*` or `?` or `[...]`
607-
*/
578+
/// If this is true then path-component separator characters (e.g. `/` on Posix)
579+
/// must be matched by a literal `/`, rather than by `*` or `?` or `[...]`
608580
pub require_literal_separator: bool,
609581

610-
/**
611-
* If this is true then paths that contain components that start with a `.` will
612-
* not match unless the `.` appears literally in the pattern: `*`, `?` or `[...]`
613-
* will not match. This is useful because such files are conventionally considered
614-
* hidden on Unix systems and it might be desirable to skip them when listing files.
615-
*/
582+
/// If this is true then paths that contain components that start with a `.` will
583+
/// not match unless the `.` appears literally in the pattern: `*`, `?` or `[...]`
584+
/// will not match. This is useful because such files are conventionally considered
585+
/// hidden on Unix systems and it might be desirable to skip them when listing files.
616586
pub require_literal_leading_dot: bool
617587
}
618588

619589
impl MatchOptions {
620590

621-
/**
622-
* Constructs a new `MatchOptions` with default field values. This is used
623-
* when calling functions that do not take an explicit `MatchOptions` parameter.
624-
*
625-
* This function always returns this value:
626-
*
627-
* ```rust,ignore
628-
* MatchOptions {
629-
* case_sensitive: true,
630-
* require_literal_separator: false.
631-
* require_literal_leading_dot: false
632-
* }
633-
* ```
634-
*/
591+
/// Constructs a new `MatchOptions` with default field values. This is used
592+
/// when calling functions that do not take an explicit `MatchOptions` parameter.
593+
///
594+
/// This function always returns this value:
595+
///
596+
/// ```rust,ignore
597+
/// MatchOptions {
598+
/// case_sensitive: true,
599+
/// require_literal_separator: false.
600+
/// require_literal_leading_dot: false
601+
/// }
602+
/// ```
635603
pub fn new() -> MatchOptions {
636604
MatchOptions {
637605
case_sensitive: true,

0 commit comments

Comments
 (0)