Changeset 7f6e9eb


Ignore:
Timestamp:
Aug 11, 2020, 2:58:26 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5bcdc8c
Parents:
7ed1d8f
Message:

Added support for doubles in parseargs

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseargs.cfa

    r7ed1d8f r7f6e9eb  
    1919        extern          long long int strtoll (const char* str, char** endptr, int base);
    2020        extern unsigned long long int strtoull(const char* str, char** endptr, int base);
     21        extern                 double strtod  (const char* str, char** endptr);
    2122}
    2223
     
    162163}
    163164
     165bool parse(const char * arg, int & value) {
     166        char * end;
     167        int r = strtoll(arg, &end, 10);
     168        if(*end != '\0') return false;
     169
     170        value = r;
     171        return true;
     172}
     173
    164174bool parse(const char * arg, unsigned & value) {
    165175        char * end;
     
    182192}
    183193
    184 bool parse(const char * arg, int & value) {
    185         char * end;
    186         int r = strtoll(arg, &end, 10);
    187         if(*end != '\0') return false;
    188 
    189         value = r;
    190         return true;
    191 }
     194bool parse(const char * arg, double & value) {
     195        char * end;
     196        double r = strtod(arg, &end);
     197        if(*end != '\0') return false;
     198
     199        value = r;
     200        return true;
     201}
  • libcfa/src/parseargs.hfa

    r7ed1d8f r7f6e9eb  
    3838
    3939bool parse(const char *, const char * & );
     40bool parse(const char *, int & );
    4041bool parse(const char *, unsigned & );
    4142bool parse(const char *, size_t & );
    42 bool parse(const char *, int & );
     43bool parse(const char *, double & );
Note: See TracChangeset for help on using the changeset viewer.