⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _punct.cc

📁 realview22.rar
💻 CC
📖 第 1 页 / 共 2 页
字号:
            const char *__gdef = _C_grouping;
            do {
                if (*__gdef != *_C_gpos && *__gdef != CHAR_MAX)
                    break;

                if (__gdef[1])
                    ++__gdef;
            } while (--_C_gpos > _C_groups);

            if (_C_gpos > _C_groups || *_C_gpos > *__gdef)
                this->_C_error |= this->_C_bad_grouping;
        }
    }

    if (__last > this->_C_digits)
        this->_C_state |= this->_C_advanced;

    return __last;
}


template <class _CharT, class _InputIter>
char* __rw_digit_reader<_CharT, _InputIter>::_C_get_digits (double) __softfp
{
    // get leading digits if any, discaring leading zeros
    this->_C_base = 10;
    char *__first = _C_get_digits (0);

    // get a set of valid punctuators
    const _CharT *__punct = this->_C_dmap._C_get_punct ();

    this->_C_frac_beg = __first;

    if (!this->_C_error && !eof ()) {
        if (*_C_in == this->_C_get_decimal_point ()) {
            // advance past decimal point and append fractional part
            // to the end of internal buffer
            ++_C_in;
            __first = _C_get_digit_string (__first);
        }
    }

    // 7.19.6.1 of C99: determine whether we're parsing one of:
    // "inf", "infinity", "nan", "nan(n-char-sequence)"

    if (__first == this->_C_digits && !eof ()) {

        const ctype<char> &__ctp = _USE_FACET (ctype<char>, _C_io.getloc ());

        char __c = (__ctp.tolower)(char (*_C_in));

        if ('i' == __c) {
            static const char __inf[] = "infinity";

            for (const char *__p = __inf; ; ++__p, ++_C_in) {
                // both "inf" and "infinity" are recognized
                if (   !*__p || 3 == __p - __inf
                    && *__p != (__ctp.tolower)(char(*_C_in))) {
                    this->_C_state |= this->_C_infinity;
                    return __first;
                }
                if (eof () || *__p != (__ctp.tolower)(char(*_C_in)))
                    break;   // error
            }
        }
        else if ('n' == __c) {
            for (const char *__p = "nan"; ; ++__p, ++_C_in) {
                // both "nan" and "nan(n-char-sequence)" are recognized
                if (!*__p) {
                    if (eof ()) {
                        this->_C_state |= this->_C_nan;
                        return __first;
                    }
                    if ('(' == *_C_in) {
                        // FIXME: "(n-char-sequence)" ignored
                        while (!eof ())
                            if (')' == *_C_in++) {
                                this->_C_state |= this->_C_nan;
                                return __first;
                            }
                    }
                    break;   // error
                }
                else if (eof () || (__ctp.tolower)(char(*_C_in)) != *__p)
                    break;   // error
            }
        }
    }

    if (__first == this->_C_digits)
        this->_C_error |= this->_C_no_digits;

    this->_C_exp_beg  = __first;
    this->_C_state   &= ~this->_C_exp_negative;

    _CharT __ch;

    if (   !this->_C_error && !eof ()
        && (  (__ch = *_C_in) == __punct [this->_C_e]
            || __ch == __punct [this->_C_E])) {

        // advance past 'e' or 'E' and append exponent
        // to the end of internal buffer
        ++_C_in;
        if (eof ())
            this->_C_error |= this->_C_bad_exponent;
        else {
            // check for '+' or '-' after 'e' or 'E'
            if ((__ch = *_C_in) == __punct [this->_C_plus])
                ++_C_in;
            else if (__ch == __punct [this->_C_minus]) {
                this->_C_state |= this->_C_exp_negative;
                ++_C_in;
            }

            // read _C_in (decimal) exponent digits
            int __radix   = this->_C_base;
            this->_C_base = 10;
            __first       = _C_get_digit_string (__first);
            this->_C_base = __radix;

            if (__first == this->_C_exp_beg)
                this->_C_error |= this->_C_bad_exponent;
        }
    }

    return __first;
}


template <class _CharT, class _InputIter>
char* __rw_digit_reader<_CharT, _InputIter>::
    _C_get_digit_groups (char *__first) {

    char *__eod=_C_get_digit_string (__first);
    
    if (_C_gpos==_C_groups+sizeof _C_groups)
        this->_C_error|=this->_C_too_many_groups;
    else {
        ptrdiff_t __i=__eod-__first;
        if (__i >= CHAR_MAX)
            this->_C_error|=this->_C_group_too_long;
        else {
            if (__i!=0) {
                *_C_gpos++=char(__i);
                if (!eof () && *_C_in==thousands_sep) {
                    ++_C_in;
                    __eod=_C_get_digit_groups (__eod);
                }
            }
        }
    }
    
    return __eod;
}


template <class _CharT, class _InputIter>
int __rw_digit_reader<_CharT, _InputIter>::
    _C_get_keyword (const __rw_keyword_map<_CharT> &__in_map) {

    const __rw_keyword_def<_CharT> *__map_ptr=__in_map._C_defs;
    const __rw_keyword_def<_CharT> *__end_ptr=__in_map._C_defs+__in_map._C_numdefs;
    
    __rw_keyword_def<_CharT> __can_ary[40],       // Candidate names.
        *__can_ptr=__can_ary; 
    
    const _CharT *__name;
    int           __res;
    _CharT        __input;
    
    // The first pass produces a set of candidate
    // names in the local array. Successive passes
    // deal with local array exclusively -- iteratively
    // stripping matching characters and keeping their
    // related map info while discarding map info if not
    // matching.
    
    for ( ; ; ) {
        if (eof ()) {
            for ( ; __map_ptr<__end_ptr; ++__map_ptr) 
                if (!*__map_ptr->_C_name)               
                    return __map_ptr->_C_indx;            
            return -1;                                
        }
        
        __input=*_C_in;
        __res=-1;
        
        for ( ; __map_ptr<__end_ptr; ++__map_ptr) {
            __name=__map_ptr->_C_name;
            if (__input==*__name) {
                __can_ptr->_C_name=++__name;
                __can_ptr->_C_indx=__map_ptr->_C_indx;
                ++__can_ptr;                 
            }
            else if (*__name==0 )        // End of abbreviated name.
                __res=__can_ptr->_C_indx;// NOTE: If an abbreviation is followed
                                         // by characters that could match the 
        }                                // full name, continues reading until
                                         // full name is matched, else fails
                                         // (per 22.2.5.1.2-6 in the Standard)  
        if (__can_ptr==__can_ary)        // 
            return __res;                // EX: If table has "Sunday" and "Sun",
                                         // input "Sund" will fail, but "Suni"
                                         // evals to "Sun".
        
        ++_C_in;
        
        if (__can_ptr==__can_ary+1) { // Only one matching candidate name left.
            for (__name=__can_ary[0]._C_name; *__name; ++__name) {
                if (eof () || *_C_in!=*__name) 
                    return -1;
                ++_C_in;
            }
            return __can_ary[0]._C_indx;
        }
        
        __end_ptr =__can_ptr;         // After first pass, vars refer
        __can_ptr =__can_ary;         // to local array.
        __map_ptr =__can_ary;         
        
    }

}

// ---------------------------------------------------
// Template __rw_digit_writer_base_1 member templates.
// ---------------------------------------------------


template <class _CharT>
__rw_digit_writer_base_1<_CharT>::
__rw_digit_writer_base_1(ios_base                      &__flags,
                         const __rw_punct_data<_CharT> &__mp)
    : __rw_digit_writer_base (__flags),
      __rw_digit_handler_base_1<_CharT>(__flags.getloc (), __mp) {

    _C_flags    &= ~(ios_base::floatfield | ios_base::showpos);
    _C_flags    |= ios_base::fixed;
    _C_base      = 10;
    _C_precision =  0;
}

// --------------------------------------------
// Template __rw_digit_writer member templates.
// --------------------------------------------

template <class _CharT, class _OutputIter>
void __rw_digit_writer<_CharT, _OutputIter>::_C_put_digits (_CharT __fill) {

    char *__p=this->_C_start;
    bool __has_sign=false, __has_point=false,
        __has_prefix_8=false, __has_prefix_16=false;
    
    if (__p<this->_C_end && (*__p==' ' || *__p=='-' || *__p=='+')) {
        __has_sign=true;
        __p++;
    }

    if (__p+1 < this->_C_end
        && (this->_C_base == 16 && *__p == '0'
            && (*(__p+1) == 'x') || *(__p+1) == 'X'))
        __has_prefix_16 = true;
    
    if (__p+1 < this->_C_end
        && (this->_C_base == 8 && *__p == '0'))
        __has_prefix_8 = true;
            
    //  Locate the end of the integral digits.
    char *__dec;
    if (!this->_C_fractional)
        __dec=this->_C_end;
    else {
        __dec=this->_C_start;
        if (__has_sign) __dec++;
        for ( ; __dec<this->_C_end; ++__dec)
            if (*__dec<'0' || *__dec>'9') {
                if (*__dec!='e' && *__dec!='E')
                    __has_point=true;
                break;
            }
    }

    
    // Calculate the number and pattern of separators needed if any.
    _CharT __separator = _CharT ();
    
    _RWSTD_C::ptrdiff_t __ungrouped = __dec - this->_C_start;
    if (__has_sign)
        __ungrouped--;
    if (__has_prefix_16)
        __ungrouped -= 2;
    if (__has_prefix_8)
        __ungrouped--;

    if (this->_C_separable) {
        __ungrouped = this->_C_calc_groups (int (__ungrouped),
                                            this->_C_get_grouping ());
        if (this->_C_num_groups)
            __separator=this->_C_get_thousands_sep ();
    }
    
    // Compute the number of __fill _CharT-s needed, and where they should be put.
    ptrdiff_t __left_fill=0, __internal_fill=0, __right_fill=0;
    if (this->_C_width>0) {
        ptrdiff_t __w=this->_C_width - (this->_C_end - this->_C_start)
                                     - this->_C_num_groups;
        this->_C_width=0;

        if (__w>0) {
            switch (this->_C_adjust) {
            case __rw_digit_writer_base::_C_left:
                __right_fill=__w;
                break;
            case __rw_digit_writer_base::_C_internal:
                __internal_fill=__w;
                break;
            default:
                __left_fill=__w;
            }
        }
    }
    
    // widen the sign + digits + exponent string

    // default buffer, will allocate larger if necessary
    _CharT  __widebuf [__rw_digit_writer_base::_C_DEF_BUFSIZE];
    _CharT *__wide_digits = __widebuf;

    // increase the size of the buffer
    if (this->_C_end - this->_C_start >= __rw_digit_writer_base::_C_DEF_BUFSIZE)
        __wide_digits = new _CharT [this->_C_end - this->_C_start + 1];
    
    this->_C_ctyp.widen (this->_C_start, this->_C_end, __wide_digits);
    
    // Write the widened string with fill and decorations to output.
    _CharT *__digit_pos = __wide_digits;
    while (__left_fill--)
        *_C_out++ = __fill;

    if (__has_sign)
        *_C_out++ = *__digit_pos++;    // the widened sign

    if (__has_prefix_16) {
        *_C_out++ = *__digit_pos++; // the "0"
        *_C_out++ = *__digit_pos++; // the "x"
    }
    if (__has_prefix_8) 
        *_C_out++ = *__digit_pos++; // the "0"

    while (__internal_fill--)
        *_C_out++ = __fill;

    while (__ungrouped--)
        *_C_out++ = *__digit_pos++;

    while (this->_C_num_groups--) {
        *_C_out++ = __separator;

        while (this->_C_group[0]--)
            *_C_out++=*__digit_pos++;
        ++this->_C_group;
    }
    
    if (__has_point) {
        *_C_out++=this->_C_get_decimal_point ();
        ++__digit_pos;
    }
    
    __ungrouped = this->_C_end - __dec;

    if (__has_point)
        __ungrouped--;

    while ((__ungrouped--) > 0)
        *_C_out++ = *__digit_pos++;
    
    while (__right_fill--)
        *_C_out++ = __fill;

    if (__wide_digits != __widebuf)
        delete[] __wide_digits;
}

template <class _CharT, class _OutputIter>
void __rw_digit_writer<_CharT, _OutputIter>::
    _C_put_keyword (const string_type &__instr, _CharT __fillchar) {

    ptrdiff_t __left_fill=0, __right_fill=0;
    ptrdiff_t __fillnum=this->_C_width-__instr.length ();
    if (__fillnum>0) {
        switch (this->_C_adjust) {
        case __rw_digit_writer_base::_C_left:
            __right_fill=__fillnum;
            break;
        case __rw_digit_writer_base::_C_internal:
        default:
            __left_fill=__fillnum;
        }
        if (__left_fill)
            do *_C_out++=__fillchar;
            while (--__left_fill);
    }
    
    const _CharT *__tmp=__instr.c_str (), *__endtmp=__tmp+__instr.length ();
    while (__tmp<__endtmp)
        *_C_out++=*__tmp++;
    
    if (__right_fill)
        do *_C_out++=__fillchar;
        while (--__right_fill);
}

_RWSTD_NAMESPACE_END   // __rw

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -