Changeset 10

Show
Ignore:
Timestamp:
06/29/07 16:41:33 (2 years ago)
Author:
aarti_pl
Message:

removed own string alias to get library up to date with dmd 1.017

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doost/any.d

    r8 r10  
    110110 
    111111    class Test { 
    112         string toString() { 
     112        char[] toString() { 
    113113            return "Test class"; 
    114114        } 
     
    132132 
    133133    v="string test"[]; 
    134     assert(v.as!(string) == "string test"); 
     134    assert(v.as!(char[]) == "string test"); 
    135135 
    136136    v=&t.doTest; 
  • trunk/doost/common.d

    r8 r10  
    1010 
    1111public import std.stdio; 
    12  
    13 alias char[] string; 
  • trunk/doost/environment.d

    r5 r10  
    2424 
    2525class EnvException : Exception { 
    26     this(string e) { 
     26    this(char[] e) { 
    2727        super(e); 
    2828    } 
    2929} 
    3030 
    31 string[string] getEnv() { 
    32     string[string] result; 
     31char[][char[]] getEnv() { 
     32    char[][char[]] result; 
    3333    char** m_environment=environ; 
    34     string s, key, value; 
     34    char[] s, key, value; 
    3535    uint n; 
    3636 
     
    4949} 
    5050 
    51 string getEnvVariable(string name) { 
     51char[] getEnvVariable(char[] name) { 
    5252    return ""; 
    5353} 
    5454 
    55 void setEnvVariable(string name, string value) { 
     55void setEnvVariable(char[] name, char[] value) { 
    5656} 
    5757 
    58 void removeEnvVariable(string name) { 
     58void removeEnvVariable(char[] name) { 
    5959} 
  • trunk/doost/program_options/command_line_parser.d

    r9 r10  
    106106/** Return type of aditional parser. */ 
    107107struct OptionPair { 
    108     string name; 
    109     string value; 
     108    char[] name; 
     109    char[] value; 
    110110} 
    111111 
    112 alias OptionPair delegate(string) additional_parser; 
    113 alias Option[] delegate(inout string[]) style_parser; 
     112alias OptionPair delegate(char[]) additional_parser; 
     113alias Option[] delegate(inout char[][]) style_parser; 
    114114 
    115115//------------------------------------------------------------------------------ 
     
    152152        assumed to have optional parameter. 
    153153    */ 
    154     this(string[] args) { 
     154    this(char[][] args) { 
    155155        m_args = args; 
    156156        m_style = style_t.default_style; 
     
    214214 
    215215 
    216         string self; 
     216        char[] self; 
    217217        if (m_style & style_t.first_is_self) { 
    218218            self=m_args[0]; 
     
    234234//                writefln("Before check ..."); 
    235235                if (next.length!=0) { 
    236                     string[] e; 
     236                    char[][] e; 
    237237                    for (uint k = 0; k < next.length-1; ++k) { 
    238238                        finishOption(next[k], e); 
     
    306306    } 
    307307 
    308     Option[] parseLongOption(inout string[] args) { 
     308    Option[] parseLongOption(inout char[][] args) { 
    309309//        writefln("parse_long_option: args.length=", args.length); 
    310310        Option[] result; 
    311         string tok = args[0]; 
     311        char[] tok = args[0]; 
    312312        //writefln("parse_long_option::tok=", tok); 
    313313        if (tok.length >= 3 && tok[0] == '-' && tok[1] == '-') { 
    314             string name, adjacent; 
     314            char[] name, adjacent; 
    315315 
    316316            int p = find(tok, '='); 
     
    336336 
    337337 
    338     Option[] parseShortOption(inout string[] args) { 
     338    Option[] parseShortOption(inout char[][] args) { 
    339339//        writefln("parse_short_option: args.length=", args.length); 
    340340        Option[] result; 
    341         string tok = args[0]; 
     341        char[] tok = args[0]; 
    342342        //writefln("parse_short_option::tok=", tok); 
    343343 
    344344        if (tok.length >= 2 && tok[0] == '-' && tok[1] != '-') { 
    345345 
    346             string name = tok[0..2]; 
    347             string adjacent = tok[2..$]; 
     346            char[] name = tok[0..2]; 
     347            char[] adjacent = tok[2..$]; 
    348348 
    349349            //writefln("parse_short_option::name=", name); 
     
    393393    } 
    394394 
    395     Option[] parseDosOption(inout string[] args) { 
     395    Option[] parseDosOption(inout char[][] args) { 
    396396//        writefln("parse_dos_option: args.length=", args.length); 
    397397        Option[] result; 
    398         string tok = args[0]; 
     398        char[] tok = args[0]; 
    399399        if (tok.length >= 2 && tok[0] == '/') { 
    400             string name = "-" ~ tok[1]; 
    401             string adjacent = tok[2..$]; 
     400            char[] name = "-" ~ tok[1]; 
     401            char[] adjacent = tok[2..$]; 
    402402 
    403403            auto opt = new Option; 
     
    411411    } 
    412412 
    413     Option[] parseDisguisedLongOption(inout string[] args) { 
     413    Option[] parseDisguisedLongOption(inout char[][] args) { 
    414414//        writefln("parse_disguised_long_option: args.length=", args.length); 
    415415        Option[] result; 
    416         string tok = args[0]; 
     416        char[] tok = args[0]; 
    417417        if (tok.length >= 2 && ((tok[0] == '-' && tok[1] != '-') || ((m_style & style_t.allow_slash_for_short) && tok[0] == '/'))) { 
    418418            bool aprox=(m_style & style_t.allow_guessing)==0 ? false : true; 
     
    426426    } 
    427427 
    428     Option[] parseTerminator(inout string[] args) { 
     428    Option[] parseTerminator(inout char[][] args) { 
    429429//        writefln("parse_terminator: args.length=", args.length); 
    430430        Option[] result; 
    431         string tok = args[0]; 
     431        char[] tok = args[0]; 
    432432        if (tok == "--") { 
    433433            for (uint i = 1; i < args.length; ++i) { 
     
    441441    } 
    442442 
    443     Option[] handleAdditionalParser(inout string[] args) { 
     443    Option[] handleAdditionalParser(inout char[][] args) { 
    444444//        writefln("handle_additional_parser: args.length=", args.length); 
    445445        Option[] result; 
     
    477477        bool allow_some_long = (style & style_t.allow_long) || (style & style_t.allow_long_disguise); 
    478478 
    479         string error; 
     479        char[] error; 
    480480        if (allow_some_long && !(style & style_t.long_allow_adjacent) && !(style & style_t.long_allow_next)) 
    481481            error = "style disallows parameters for long options"; 
     
    493493    } 
    494494 
    495     void finishOption(Option opt, inout string[] other_tokens) { 
     495    void finishOption(Option opt, inout char[][] other_tokens) { 
    496496        if (opt.string_key.length==0) return; 
    497497 
     
    544544 
    545545    // Copies of input. 
    546     string[] m_args; 
     546    char[][] m_args; 
    547547    style_t m_style; 
    548548    bool m_allow_unregistered; 
    549     string m_self; 
     549    char[] m_self; 
    550550 
    551551    OptionsDescription m_desc; 
     
    600600    //TODO: Program name should be always added to variable map as default, when 
    601601    //parsing command line 
    602     this(string[] args) { 
     602    this(char[][] args) { 
    603603        super(args); 
    604604    } 
     
    647647 */ 
    648648 
    649 ParsedOptions parseCommandLine(string[] args, OptionsDescription desc, int style = 0, additional_parser ext = null) { 
     649ParsedOptions parseCommandLine(char[][] args, OptionsDescription desc, int style = 0, additional_parser ext = null) { 
    650650    return (new CommandLineParser(args)).options(desc).style(style).extraParser(ext).run(); 
    651651} 
  • trunk/doost/program_options/config_file_parser.d

    r9 r10  
    2525/** Parse a config file. 
    2626*/ 
    27 ParsedOptions parseConfigFile(string str, OptionsDescription desc) { 
     27ParsedOptions parseConfigFile(char[] str, OptionsDescription desc) { 
    2828    auto parser=new CommonConfigFileParser(desc); 
    2929    return parser.parseFile(str); 
    3030} 
    3131 
    32 ParsedOptions parseConfigFile(string str, OptionsDescription desc, CommonConfigFileParser parser) { 
     32ParsedOptions parseConfigFile(char[] str, OptionsDescription desc, CommonConfigFileParser parser) { 
    3333    return parser.parseFile(str); 
    3434} 
     
    9494    } 
    9595 
    96     Option get(string s) { 
     96    Option get(char[] s) { 
    9797        uint n; 
    9898        Option result; 
     
    110110                    m_prefix ~= '.'; 
    111111            } else if ((n = find(s, '=')) != -1) { 
    112                 string name = m_prefix ~ strip(s[0..n]); 
    113                 string value = strip(s[n+1..$]); 
     112                char[] name = m_prefix ~ strip(s[0..n]); 
     113                char[] value = strip(s[n+1..$]); 
    114114 
    115115                if (!allowedOption(name)) 
     
    130130    } 
    131131 
    132     ParsedOptions parseFile(string str) { 
     132    ParsedOptions parseFile(char[] str) { 
    133133        auto result = new ParsedOptions(m_desc); 
    134         string[] lines=splitlines(str); 
     134        char[][] lines=splitlines(str); 
    135135        Option r; 
    136136 
     
    149149        'foo_bar' are allowed. */ 
    150150 
    151     void addOption(string name) { 
    152         string s=name; 
     151    void addOption(char[] name) { 
     152        char[] s=name; 
    153153        assert(s.length!=0); 
    154154        if (s[$-1] == '*') { 
     
    181181 
    182182    // Returns true if 's' is a registered option name. 
    183     bool allowedOption(string s) { 
     183    bool allowedOption(char[] s) { 
    184184        if (s in allowed_options) 
    185185            return true; 
     
    204204    } 
    205205 
    206     bool[string] allowed_options; 
     206    bool[char[]] allowed_options; 
    207207 
    208208    // Invariant: no element is prefix of other element. 
    209     bool[string] allowed_prefixes; 
    210     string m_prefix; 
     209    bool[char[]] allowed_prefixes; 
     210    char[] m_prefix; 
    211211    OptionsDescription m_desc; 
    212212} 
  • trunk/doost/program_options/environment_parser.d

    r9 r10  
    4848class PrefixNameMapper { 
    4949public: 
    50     this(string prefix) { 
     50    this(char[] prefix) { 
    5151        this.prefix=prefix; 
    5252    } 
    5353 
    54     string opCall(string s) { 
    55         string result; 
     54    char[] opCall(char[] s) { 
     55        char[] result; 
    5656        if (find(s, prefix) == 0) { 
    5757                result=tolower(s[prefix.length..$]); 
     
    6060    } 
    6161private: 
    62     string prefix; 
     62    char[] prefix; 
    6363} 
    6464 
     
    7474    different from the naming of command line options. 
    7575*/ 
    76 ParsedOptions parseEnvironment(OptionsDescription desc, string delegate (string) name_mapper) { 
     76ParsedOptions parseEnvironment(OptionsDescription desc, char[] delegate (char[]) name_mapper) { 
    7777    auto result = new ParsedOptions(desc); 
    7878 
    79     string[string] env=getEnv(); 
     79    char[][char[]] env=getEnv(); 
    8080 
    8181    foreach(key; env.keys) { 
    82         string option_name = name_mapper(key); 
     82        char[] option_name = name_mapper(key); 
    8383 
    8484        if (option_name.length!=0) { 
     
    101101    converting the remaining string into lower case. 
    102102*/ 
    103 ParsedOptions parseEnvironment(OptionsDescription desc, string prefix) { 
     103ParsedOptions parseEnvironment(OptionsDescription desc, char[] prefix) { 
    104104    auto p=new PrefixNameMapper(prefix); 
    105105    return parseEnvironment(desc, &p.opCall); 
  • trunk/doost/program_options/errors.d

    r9 r10  
    1919class ProgramOptionsException : Exception { 
    2020public: 
    21     this(string what) { 
     21    this(char[] what) { 
    2222        super(what); 
    2323    } 
     
    2929class InvalidSyntax : ProgramOptionsException { 
    3030public: 
    31     this(string tokens, string msg) { 
     31    this(char[] tokens, char[] msg) { 
    3232        super(msg ~ " in '" ~ tokens ~ "'"); 
    3333        this.tokens=tokens; 
    3434        this.msg=msg; 
    3535    } 
    36     string tokens, msg; 
     36    char[] tokens, msg; 
    3737} 
    3838 
     
    4242class UnknownOption : ProgramOptionsException { 
    4343public: 
    44     this(string name) { 
     44    this(char[] name) { 
    4545        super("unknown option " ~ name); 
    4646    } 
     
    5252class AmbiguousOption : ProgramOptionsException { 
    5353public: 
    54     this(string name, string[] alternatives) { 
     54    this(char[] name, char[][] alternatives) { 
    5555        super("ambiguous options: " ~ name); 
    5656        this.alternatives=alternatives; 
    5757    } 
    58     string[] alternatives; 
     58    char[][] alternatives; 
    5959} 
    6060 
     
    6565class MultipleValues : ProgramOptionsException { 
    6666public: 
    67     this(string what) { 
     67    this(char[] what) { 
    6868        super(what); 
    6969    } 
     
    7777class MultipleOccurrences : ProgramOptionsException { 
    7878public: 
    79     this(string what) { 
     79    this(char[] what) { 
    8080        super(what); 
    8181    } 
     
    8787class ValidationError : ProgramOptionsException { 
    8888public: 
    89     this(string what) { 
    90         super(what); 
    91     } 
    92     void setOptionName(string option_name) { 
     89    this(char[] what) { 
     90        super(what); 
     91    } 
     92    void setOptionName(char[] option_name) { 
    9393        m_option_name = option_name; 
    9494    } 
    9595 
    9696private: 
    97     string m_message;       // For on-demand formatting in 'what' 
    98     string m_option_name;   // The name of the option which 
     97    char[] m_message;       // For on-demand formatting in 'what' 
     98    char[] m_option_name;   // The name of the option which 
    9999                            // caused the exception. 
    100100    // Zamiana na toString? 
    101     string what() { 
     101    char[] what() { 
    102102        if (m_option_name!="") { 
    103103            m_message = "in option '" ~ m_option_name ~ "': " ~ "logic error"; 
     
    112112class InvalidOptionValue : ValidationError { 
    113113public: 
    114     this(string value) { 
     114    this(char[] value) { 
    115115        super("invalid option value '" ~ value ~ "'"); 
    116116    } 
     
    122122class TooManyPositionalOptionsError : ProgramOptionsException { 
    123123public: 
    124     this(string what) { 
     124    this(char[] what) { 
    125125        super(what); 
    126126    } 
     
    132132class TooFewPositionalOptionsError : ProgramOptionsException { 
    133133public: 
    134     this(string what) { 
     134    this(char[] what) { 
    135135        super(what); 
    136136    } 
     
    150150    } 
    151151 
    152     this(string tokens, kind_t kind) { 
     152    this(char[] tokens, kind_t kind) { 
    153153        super(tokens, errorMessage(kind)); 
    154154        m_kind=kind; 
     
    159159 
    160160protected: 
    161     static string errorMessage(kind_t kind) { 
     161    static char[] errorMessage(kind_t kind) { 
    162162        // Initially, store the message in 'const char*' variable, 
    163163        // to avoid conversion to std::string in all cases. 
    164         string msg; 
     164        char[] msg; 
    165165        switch(kind) { 
    166166            case kind_t.long_not_allowed: 
     
    197197class InvalidConfigFileSyntax : InvalidSyntax { 
    198198public: 
    199     this(string tokens, string msg) { 
     199    this(char[] tokens, char[] msg) { 
    200200        super(tokens, msg); 
    201201    } 
     
    206206class InvalidCommandLineStyle : ProgramOptionsException { 
    207207public: 
    208     this(string msg) { 
     208    this(char[] msg) { 
    209209        super(msg); 
    210210    } 
     
    216216class DuplicateOptionError : ProgramOptionsException { 
    217217public: 
    218     this(string what) { 
    219         super(what); 
    220     } 
    221 } 
     218    this(char[] what) { 
     219        super(what); 
     220    } 
     221} 
  • trunk/doost/program_options/libversion.d

    r5 r10  
    1515import doost.common; 
    1616 
    17 const string program_options_version="2"; 
    18 const string program_options_date="2006-12-02"; 
     17const char[] program_options_version="2"; 
     18const char[] program_options_date="2006-12-02"; 
  • trunk/doost/program_options/option.d

    r5 r10  
    3131    } 
    3232 
    33     this(string string_key, string[] value) { 
     33    this(char[] string_key, char[][] value) { 
    3434        this.string_key=string_key; 
    3535        this.value=value; 
     
    3939    /** String key of this option. Intentionally independent of the template 
    4040        parameter. */ 
    41     string string_key; 
     41    char[] string_key; 
    4242 
    4343    /** Position key of this option. All options without an explicit name are 
     
    5050 
    5151    /** Option's value */ 
    52     string[] value; 
     52    char[][] value; 
    5353 
    5454    /** True if option was not recognized. In that case, 
  • trunk/doost/program_options/options_description.d

    r9 r10  
    7272    */ 
    7373 
    74     this(string name, ValueSemantic s) { 
     74    this(char[] name, ValueSemantic s) { 
    7575        m_value_semantic=s; 
    7676        setName(name); 
     
    8181     */ 
    8282 
    83     this(string name, ValueSemantic s, string description) { 
     83    this(char[] name, ValueSemantic s, char[] description) { 
    8484        m_description=description; 
    8585        m_value_semantic=s; 
     
    8989    /** Given 'option', specified in the input source, 
    9090        return 'true' is 'option' specifies *this. */ 
    91     MatchResult match(string option, bool approx) { 
     91    MatchResult match(char[] option, bool approx) { 
    9292        MatchResult result = MatchResult.no_match; 
    9393        //writefln("m_long_name=", m_long_name, " approx=", approx, " option=", option); 
     
    126126        it's a short name with prepended '-'. 
    127127    */ 
    128     string key(string option) { 
     128    char[] key(char[] option) { 
    129129        if (m_long_name!="") 
    130130            if (find(m_long_name, "*") != -1) 
     
    141141    } 
    142142 
    143     string longName() { 
     143    char[] longName() { 
    144144        return m_long_name; 
    145145    } 
    146146 
    147147    /// Explanation of this option 
    148     string description() { 
     148    char[] description() { 
    149149        return m_description; 
    150150    } 
     
    156156 
    157157    /// Returns the option name, formatted suitably for usage message. 
    158     string formatName() { 
     158    char[] formatName() { 
    159159        if (m_short_name!="") return m_short_name~" [--"~m_long_name~"]"; 
    160160        else return "--"~m_long_name; 
     
    163163    /** Return the parameter name and properties, formatted suitably for 
    164164        usage message. */ 
    165     string formatParameter() { 
     165    char[] formatParameter() { 
    166166        if (m_value_semantic.maxTokens != 0) return m_value_semantic.name; 
    167167        else return ""; 
     
    181181 
    182182private: 
    183     OptionDescription setName(string _name) { 
    184         string name=_name; 
     183    OptionDescription setName(char[] _name) { 
     184        char[] name=_name; 
    185185        uint n = find(name, ','); 
    186186        if (n != -1) { 
     
    195195    } 
    196196 
    197     string m_short_name, m_long_name, m_description; 
     197    char[] m_short_name, m_long_name, m_description; 
    198198    ValueSemantic m_value_semantic; 
    199199} 
     
    212212    // no value can be specified on command line. 
    213213    // FIXME: does not look exception-safe 
    214     OptionsDescriptionEasyInit opCall(string name, string description) { 
     214    OptionsDescriptionEasyInit opCall(char[] name, char[] description) { 
    215215        owner.add(new OptionDescription(name, new UntypedValue(true), description)); 
    216216        return this; 
    217217    } 
    218218 
    219     OptionsDescriptionEasyInit opCall(string name, ValueSemantic s) { 
     219    OptionsDescriptionEasyInit opCall(char[] name, ValueSemantic s) { 
    220220        owner.add(new OptionDescription(name, s)); 
    221221        return this; 
    222222    } 
    223223 
    224     OptionsDescriptionEasyInit opCall(string name, ValueSemantic s, string description) { 
     224    OptionsDescriptionEasyInit opCall(char[] name, ValueSemantic s, char[] description) { 
    225225        owner.add(new OptionDescription(name, s, description)); 
    226226        return this; 
    227227    } 
    228228 
    229     OptionsDescriptionEasyInit opCall(string selfdir, ValueSemantic s1, 
    230             string selfname, ValueSemantic s2) { 
     229    OptionsDescriptionEasyInit opCall(char[] selfdir, ValueSemantic s1, 
     230            char[] selfname, ValueSemantic s2) { 
    231231 
    232232        auto sd=new OptionDescription(selfdir, s1); 
     
    265265    /** Creates the instance. The 'caption' parameter gives the name of 
    266266        this 'OptionsDescription' instance. Primarily useful for output. */ 
    267     this(string caption, uint line_length = m_default_line_length) { 
     267    this(char[] caption, uint line_length = m_default_line_length) { 
    268268        m_caption=caption; 
    269269        m_line_length=line_length; 
     
    306306    } 
    307307 
    308     OptionDescription find(string name, bool approx) { 
     308    OptionDescription find(char[] name, bool approx) { 
    309309        OptionDescription d = findNothrow(name, approx); 
    310310        if (d is null) throw new UnknownOption(name); 
     
    312312    } 
    313313 
    314     OptionDescription findNothrow(string name, bool approx) { 
     314    OptionDescription findNothrow(char[] name, bool approx) { 
    315315        int found = -1; 
    316316        // We use linear search because matching specified option 
     
    337337 
    338338            if (found != -1) { 
    339                 string[] alts; 
     339                char[][] alts; 
    340340                // FIXME: the use of 'key' here might not 
    341341                // be the best approach. 
     
    363363        OptionDescription element. */ 
    364364 
    365     string toString() { 
    366         string result; 
     365    char[] toString() { 
     366        char[] result; 
    367367        if (m_caption!="") result~=m_caption ~ ":\n"; 
    368368 
     
    372372        foreach(opt; m_options) { 
    373373            if (!opt.hidden) { 
    374                 string ss; 
     374                char[] ss; 
    375375                ss = "  " ~ opt.formatName() ~ ' ' ~ opt.formatParameter(); 
    376376                width = max!(uint)(width, ss.length); 
     
    399399private: 
    400400 
    401     string m_caption; 
     401    char[] m_caption; 
    402402    uint m_line_length; 
    403403    // Data organization is chosen because: 
     
    424424 
    425425 
    426 string formatParagraph(string par, uint indent, uint line_length) { 
    427     string result; 
     426char[] formatParagraph(char[] par, uint indent, uint line_length) { 
     427    char[] result; 
    428428 
    429429    // Through reminder of this function, 'line_length' will 
     
    522522//------------------------------------------------------------------------------ 
    523523 
    524 string formatDescription(string desc, uint first_column_width, uint line_length) { 
     524char[] formatDescription(char[] desc, uint first_column_width, uint line_length) { 
    525525    // we need to use one char less per line to work correctly if actual 
    526526    // console has longer lines 
    527527    assert(line_length > 1); 
    528     string result; 
     528    char[] result; 
    529529 
    530530    if (line_length > 1) --line_length; 
     
    561561    // Uproszczony tokenizer 
    562562 
    563     string[] lines=splitlines(desc); 
     563    char[][] lines=splitlines(desc); 
    564564    foreach(line; lines) { 
    565565        result~=formatParagraph(line, first_column_width, line_length); 
     
    578578//------------------------------------------------------------------------------ 
    579579 
    580 string formatOne(OptionDescription opt, uint first_column_width, uint line_length) { 
    581     string result="  " ~ opt.formatName() ~ ' ' ~ opt.formatParameter(); 
     580char[] formatOne(OptionDescription opt, uint first_column_width, uint line_length) { 
     581    char[] result="  " ~ opt.formatName() ~ ' ' ~ opt.formatParameter(); 
    582582 
    583583    if (opt.description()!="") { 
  • trunk/doost/program_options/positional_options.d

    r9 r10  
    4141        '-1'. 
    4242    */ 
    43     PositionalOptionsDescription add(string name, int max_count) { 
     43    PositionalOptionsDescription add(char[] name, int max_count) { 
    4444        assert(max_count != -1 || m_trailing==""); 
    4545 
     
    6363        Precondition: position < max_total_count() 
    6464    */ 
    65     string nameForPosition(uint position) { 
     65    char[] nameForPosition(uint position) { 
    6666        assert(position < maxTotalCount()); 
    6767 
     
    7474    // positions is unlimited, then the last name is stored in 
    7575    // m_trailing; 
    76     string[] m_names; 
    77     string m_trailing; 
     76    char[][] m_names; 
     77    char[] m_trailing; 
    7878} 
  • trunk/doost/program_options/string2type.d

    r5 r10  
    1212import doost.common; 
    1313 
    14 T stringToType(T : string)(string s) { 
     14T stringToType(T : char[])(char[] s) { 
    1515    return s; 
    1616} 
    1717 
    18 T stringToType(T : int)(string s) { 
     18T stringToType(T : int)(char[] s) { 
    1919    return toInt(s); 
    2020} 
    2121 
    22 T stringToType(T : uint)(string s) { 
     22T stringToType(T : uint)(char[] s) { 
    2323    return toUint(s); 
    2424} 
    2525 
    26 T stringToType(T : long)(string s) { 
     26T stringToType(T : long)(char[] s) { 
    2727    return toLong(s); 
    2828} 
    2929 
    30 T stringToType(T : ulong)(string s) { 
     30T stringToType(T : ulong)(char[] s) { 
    3131    return toUlong(s); 
    3232} 
    3333 
    34 T stringToType(T : short)(string s) { 
     34T stringToType(T : short)(char[] s) { 
    3535    return toShort(s); 
    3636} 
    3737 
    38 T stringToType(T : ushort)(string s) { 
     38T stringToType(T : ushort)(char[] s) { 
    3939    return toUshort(s); 
    4040} 
    4141 
    42 T stringToType(T : byte)(string s) { 
     42T stringToType(T : byte)(char[] s) { 
    4343    return toByte(s); 
    4444} 
    4545 
    46 T stringToType(T : ubyte)(string s) { 
     46T stringToType(T : ubyte)(char[] s) { 
    4747    return toUbyte(s); 
    4848} 
    4949 
    50 T stringToType(T : float)(string s) { 
     50T stringToType(T : float)(char[] s) { 
    5151    return toFloat(s); 
    5252} 
    5353 
    54 T stringToType(T : double)(string s) { 
     54T stringToType(T : double)(char[] s) { 
    5555    return toDouble(s); 
    5656} 
    5757 
    58 T stringToType(T : real)(string s) { 
     58T stringToType(T : real)(char[] s) { 
    5959    return toReal(s); 
    6060} 
  • trunk/doost/program_options/value_semantic.d

    r9 r10  
    2121//------------------------------------------------------------------------------ 
    2222 
    23 const string arg="arg"; 
     23const char[] arg="arg"; 
    2424 
    2525//------------------------------------------------------------------------------ 
     
    3232        for automatic help message. 
    3333     */ 
    34     string name(); 
     34    char[] name(); 
    3535 
    3636    /** The minimum number of tokens for this option that 
     
    5353        option is specified more than once. 
    5454    */ 
    55     void parse(Any value_store, string[] new_tokens); 
     55    void parse(Any value_store, char[][] new_tokens); 
    5656 
    5757    /** Called to assign default value to 'value_store'. Returns 
     
    6868 
    6969/** Class which specifies a simple handling of a value: the value will 
    70     have string type and only one token is allowed. */ 
     70    have char[] type and only one token is allowed. */ 
    7171class UntypedValue : ValueSemantic { 
    7272public: 
     
    7575    } 
    7676 
    77     override string name() { 
     77    override char[] name() { 
    7878        return arg; 
    7979    } 
     
    9898        any modifications. 
    9999     */ 
    100     override void parse(Any value_store, string[] new_tokens) { 
     100    override void parse(Any value_store, char[][] new_tokens) { 
    101101        if (!value_store.empty()) throw new MultipleOccurrences("multiple_occurrences"); 
    102102        if (new_tokens.length > 1) throw new MultipleValues("multiple_values"); 
    103103 
    104         value_store = (new_tokens.length == 0) ? (new Any()).assign(cast(string)("")) : (new Any).assign(new_tokens[0]); 
     104        value_store = (new_tokens.length == 0) ? (new Any()).assign(cast(char[])("")) : (new Any).assign(new_tokens[0]); 
    105105    } 
    106106 
     
    163163        by the user. 
    164164    */ 
    165     TypedValue defaultValue(T v, string textual) { 
     165    TypedValue defaultValue(T v, char[] textual) { 
    166166        m_default_value.assign(v); 
    167167        m_default_value_as_text = textual; 
     
    197197    // value semantic overrides 
    198198 
    199     override string name() { 
     199    override char[] name() { 
    200200        if (!m_default_value.empty() && m_default_value_as_text!="") { 
    201201            return arg ~ " (=" ~ m_default_value_as_text ~ ")"; 
     
    226226    /** Creates an instance of the 'validator' class and calls 
    227227        its operator() to perform the actual conversion. */ 
    228     override void parse(Any value_store, string[] new_tokens) { 
     228    override void parse(Any value_store, char[][] new_tokens) { 
    229229        validate!(T)(value_store, new_tokens); 
    230230    } 
     
    264264    // as boost::optional to avoid unnecessary instantiations. 
    265265    Any m_default_value; 
    266     string m_default_value_as_text; 
     266    char[] m_default_value_as_text; 
    267267    bool m_composing, m_multitoken, m_zero_tokens; 
    268268    void delegate(T) m_notifier; 
     
    304304    otherwise. */ 
    305305 
    306 string getSingleString(string[] v, bool allow_empty = false) { 
     306char[] getSingleString(char[][] v, bool allow_empty = false) { 
    307307    if (v.length > 1) throw new ValidationError("multiple values not allowed"); 
    308308    if (v.length == 1) return v[0]; 
     
    328328    partial template ordering, just like the last 'long/int' parameter. 
    329329*/ 
    330 void validate(T)(Any v, string[] xs) { 
     330void validate(T)(Any v, char[][] xs) { 
    331331    checkFirstOccurrence(v); 
    332     string s=getSingleString(xs); 
     332    char[] s=getSingleString(xs); 
    333333    try { 
    334334        //v = Any(lexical_cast<T>(s)); 
     
    344344/** Validates sequences. Allows multiple values per option occurrence 
    345345   and multiple occurrences. */ 
    346 void validate(T : T[])(Any v, string[] s) { 
     346void validate(T : T[])(Any v, char[][] s) { 
    347347    if (v.empty()) { 
    348348        T[] t; 
     
    376376    be optional. 
    377377*/ 
    378 void validate(T : bool)(Any v, string[] xs) { 
     378void validate(T : bool)(Any v, char[][] xs) { 
    379379    checkFirstOccurrence(v); 
    380     string s=tolower(getSingleString(xs, true)); 
     380    char[] s=tolower(getSingleString(xs, true)); 
    381381 
    382382    if (s.length==0 || s == "on" || s == "yes" || s == "1" || s == "true") 
     
    390390//------------------------------------------------------------------------------ 
    391391 
    392 void validate(T : string)(Any v, string[] xs) { 
     392void validate(T : char[])(Any v, char[][] xs) { 
    393393    checkFirstOccurrence(v); 
    394     string s=getSingleString(xs); 
     394    char[] s=getSingleString(xs); 
    395395    if ((s!="") && (s[0] == '\'' && s[$-1] == '\'' || s[0] == '"' && s[$-1] == '"')) 
    396396        v.assign(s[1..$-2]);