Changeset 792

Show
Ignore:
Timestamp:
07/07/08 23:23:25 (5 months ago)
Author:
andrei
Message:

$(LI In $(B std.getopt), added $(B optChar), $(B assignChar), and $(B endOfOptions), per popular demand :o|)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/getopt.d

    r714 r792  
    386386        // no more options to look for, potentially some arguments left 
    387387        foreach (a ; args[1 .. $]) { 
    388             if (!a.length || a[0] != '-'
     388            if (!a.length || a[0] != optChar
    389389            { 
    390390                // not an option 
     
    392392                continue;  
    393393            } 
    394             if (a == endOfOptions) break; // end of options 
     394            if (endOfOptions.length && a == endOfOptions) break; 
    395395            if (!cfg.passThrough) 
    396396            { 
     
    407407    for (size_t i = 1; i < args.length; ) { 
    408408        auto a = args[i]; 
    409         if (a == endOfOptions) break; // end of options, i.e. "--" 
     409        if (endOfOptions.length && a == endOfOptions) break; 
    410410        if (cfg.stopOnFirstNonOption && (!a.length || a[0] != optChar)) 
    411411        { 
     
    469469                alias typeof(receiver.keys[0]) K; 
    470470                alias typeof(receiver.values[0]) V; 
    471                 auto j = std.string.find(val, '='); 
     471                auto j = std.string.find(val, assignChar); 
    472472                auto key = val[0 .. j], value = val[j + 1 .. $]; 
    473473                (*receiver)[to!(K)(key)] = to!(V)(value); 
     
    482482} 
    483483 
    484 enum 
    485     optChar = '-', 
    486     assignChar = '=', 
    487     autoIncrementChar = '+', 
    488     endOfOptions = "--"; 
     484/** 
     485   The option character. Defaults to '-' but it can be assigned to 
     486   prior to calling $(D getopt). 
     487 */ 
     488dchar optChar = '-'; 
     489 
     490/** 
     491   The string that conventionally marks the end of all 
     492   options. Defaults to "--" but can be assigned to prior to calling 
     493   $(D getopt). Assigning an empty string to $(D endOfOptions) 
     494   effectively disables it. 
     495 */ 
     496string endOfOptions = "--"; 
     497 
     498/** 
     499   The assignment character used in options with parameters. Defaults 
     500   to '=' but can be assigned to prior to calling $(D getopt). 
     501 */ 
     502dchar assignChar = '='; 
     503 
     504enum autoIncrementChar = '+'; 
    489505 
    490506private struct configuration