// 数字的格式可以用A[.[B]][e|EC]或者.B[e|EC]表示,其中A和C都是
// 整数(可以有正负号,也可以没有),而B是一个无符号整数
bool isNumeric(const char* str)
{
    if(str == nullptr)
        return false;

    bool numeric = scanInteger(&str);

    // 如果出现'.',接下来是数字的小数部分
    if(*str == '.')
    {
        ++str;

        // 下面一行代码用||的原因:
        // 1. 小数可以没有整数部分,例如.123等于0.123;
        // 2. 小数点后面可以没有数字,例如233.等于233.0;
        // 3. 当然小数点前面和后面可以有数字,例如233.666
        numeric = scanUnsignedInteger(&str) || numeric;
    }

    // 如果出现'e'或者'E',接下来跟着的是数字的指数部分
    if(*str == 'e' || *str == 'E')
    {
        ++str;

        // 下面一行代码用&&的原因:
        // 1. 当e或E前面没有数字时,整个字符串不能表示数字,例如.e1、e1;
        // 2. 当e或E后面没有整数时,整个字符串不能表示数字,例如12e、12e+5.4
        numeric = numeric && scanInteger(&str);
    }

    return numeric && *str == '\0';
}
Beispiel #2
0
Dictionary *StringReader :: ReadDictionary(const char *source, const char *idString)
{
    const char *str1 = source;
    double value;
    int size;
    char key [ 100 + 1 ]; // 'key' is eventually of size 1, but some words that are
                                      // read in the meantime in the data file can be larger !
    Dictionary *dict;

    dict = new Dictionary();
    str1 = getPosAfter(source, idString); // move after idString
    str1 = scanInteger(str1, & size);    // read number of conditions
    if ( size == 0 ) {
        return dict;                     // no - conditions - return void dictionary
    }

    if ( str1 == NULL ) {
        return dict;                     // end of line - return void dictionary
    }

    for ( int i = 1; i <= size; i++ ) {
        readSimpleString(str1, key, 100 + 1, & str1);
        str1 = scanDouble(str1, & value);
        dict->add(key [ 0 ], value);
    }

    return dict;
}
Beispiel #3
0
IntArray *StringReader :: ReadIntArray(const char *source, const char *idString)
{
    const char *str1 = source;
    int value, size;
    IntArray *arry;


    str1 = getPosAfter(source, idString);
    str1 = scanInteger(str1, & size);
    //  if(size ==0) return NULL;   // if commented returns new array of size = 0 for size = 0
    if ( str1 == NULL ) {
        size = 0;
    }

    arry = new IntArray(size);
    for ( int i = 1; i <= size; i++ ) {
        str1 = scanInteger(str1, & value);
        arry->at(i) = value;
    }

    return arry;
}
Beispiel #4
0
const char *StringReader :: readKeyAndVal(const char *source, char *key, int *val, int maxchar, const char **remain)
{
    key = readSimpleString(source, key, maxchar, remain);
    * remain = scanInteger(* remain, val);
    return * remain;
}