コード例 #1
0
ファイル: tokenizer.c プロジェクト: MarcoGiancarli/tokenizer
TokenT *_octal(TokenizerT *tk) {
    nextChar(tk);
    if(isOctal(tk->inputIter[0])) {
        return _octal(tk);
    } else {
        return makeToken(tk, "octal integer");
    }
}
コード例 #2
0
ファイル: tokenizer.c プロジェクト: MarcoGiancarli/tokenizer
/*
 * Handle being given a zero as the first char in a new token.
 */
TokenT *_zero(TokenizerT *tk) {
    nextChar(tk);
    if(isOctal(tk->inputIter[0])) {
        return _octal(tk);
    } else if(tk->inputIter[0] == 'x' || (tk->inputIter[0]) == 'X') {
        return _hex(tk, 1);
    } else if(tk->inputIter[0] == '.') {
        return _float(tk, 1);
    } else {
        return makeToken(tk, "zero integer");
    }
}
コード例 #3
0
ファイル: vsprintf.c プロジェクト: LuoZhongYao/none
static inline char *_toNumber(char *str,long long value,_bool sign,
        HexBase base,int size,int style,int mask){
    char signString = '+';
    const char *dig = _lowerDigits;
    int tmp[64];       //缓存转换后的值.还不是ASCII 
    int length = 0;

    if(style & STYLE_LARGE) dig = _upperDigits;
    if(style & STYLE_LEFT) style &= (~STYLE_ZEROPAD); //左对齐就不能使用0填充
    //如果不是10进制,则都按无符号处理 ,并且无正负符号显示
    //如果是10进制,则去除前缀属性
    if(DECIMAL != base){
        sign = _false;
        style &= ~STYLE_SIGN;
    } else {
        style &= ~STYLE_SPECIAL;
    }

    if(style & STYLE_SPECIAL){
        if(HEX == base) size -= 2;
        else if(OCTAL == base) size -= 1;
    }

    //如果是有符号数,却小于0,则取其补码,并设置符号标志,非16进制在前面已经去除
    //符号,所以不会受影响
    if((_true == sign) && ((long long)value) < 0){
            style |= STYLE_SIGN;
            value = ~value + 1;
            signString = '-';
    }

    value &= mask;
    if(style & STYLE_SIGN) size --;

    switch(base){
        case OCTAL:length = _octal(tmp,value);break;
        case DECIMAL:length = _decimal(tmp,value);break;
        case HEX:length = _hex(tmp,value);break;
    } 
    size -= length;

    if(!(style & (STYLE_ZEROPAD|STYLE_LEFT))) while(size-- > 0) *str++ = ' ';
    if(style & STYLE_SIGN) *str++ = signString;
    if(style & STYLE_SPECIAL){
        *str++ = '0';
        if(HEX == base) *str++ = dig[0x10];
    }
    if(style & STYLE_ZEROPAD) while(size-- > 0) *str++ = '0';
    while(length-- > 0) *str++ = dig[tmp[length]];
    if(style & STYLE_LEFT) while(size-- > 0) *str++ = ' ';

    return str;
}