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

📄 _time.cc

📁 realview22.rar
💻 CC
📖 第 1 页 / 共 2 页
字号:

template <class _CharT, class _OutputIter>
_OutputIter time_put<_CharT, _OutputIter>::put
    (_OutputIter __out, ios_base &__io, _CharT __fill, const tm *__tm, 
     const _CharT* __pattern, const _CharT* __patt_end) const {
    _C_check_init ();

    size_t __patt_len = __patt_end-__pattern;
    char __scratch [40];
    char *__narrow_patt = (__patt_len<=sizeof __scratch)
                          ? __scratch
                          : new char[__patt_len];
  
    _USE_FACET (ctype<_CharT>, __io.getloc ())
        .narrow (__pattern, __patt_end, ' ', __narrow_patt);

    char *__np = __narrow_patt;
    for (const _CharT* __wp = __pattern; __wp<__patt_end; ++__wp, ++__np)
        if (*__np!='%')
            *__out++ = *__wp;
        else if (++__wp<__patt_end) {
            switch (*++__np) {

            case 'O':
                // POSIX-style modifier
                if (++__wp<__patt_end)
                    __out = do_put(__out, __io, __fill,
                                   __tm, *++__np, 'O');
                break;

            case '%':
                // Literal percent sign
                *__out++ = *__wp;
                break;

            default:
                // Treat everything else as a time format specifier.
                __out = do_put (__out, __io, __fill, __tm, *__np, ' ');
            }
        }

    if (__narrow_patt!=__scratch)
        delete[] __narrow_patt;

    return __out;
}

template <class _CharT, class _OutputIter>
_OutputIter time_put<_CharT, _OutputIter>::
do_put (_OutputIter __out, ios_base &__io, _CharT __fill, const tm *__tm, 
        char __fmat, char __modif) const {

    _C_check_init (); 

    const _CharT __pcnt[] = { '%', '%', '\0' };
    if (*__pcnt == _CharT (__fmat))
        return put (__out, __io, __fill, __tm, __pcnt, __pcnt + 2);

    static const char do_as_pattern[] = "xXcDrT";
    const char *__p = strchr (do_as_pattern, __fmat);
    if (__p) {
        // Catch formats implemented as calls to the pattern-based
        // method before going to the expense of constructing a
        // __rw_digit_writer.
        unsigned __i = __p-do_as_pattern;

        const _TYPENAME _RW::__rw_timepunct<_CharT>::string_type& __s =
            _RW::__rw_keyword_cracker<_CharT>::_C_get_patt_string (*_C_timp,
                                                                   __i);

        return put (__out, __io, __fill, __tm,
                    __s.c_str (), __s.c_str ()+__s.length ());
    }
    
    _RW::__rw_digit_writer<_CharT, _OutputIter> __writer (__out, __io);
    __writer._C_width = 0;
    
    if ('O' == __modif) {
        // Uppercase letter O (not zero)
        // -- requests ordinal string if defined.
        int __n, __m;
        switch (__fmat) {
        case 'C':
            // Exclusive Rogue Wave extension: Lets you announce, "Welcome
            // to the %OC century!" (See note on unmodified 'C' below.)
            __n = (__tm->tm_year+1999)/100;
            break;
        case 'd':
        case 'e':
            __n = __tm->tm_mday;
            break;
        case 'H':
            __n = __tm->tm_hour+1;
            break;
        case 'I':
            __n = __tm->tm_hour+1;
            if (__n>12)
                __n -= 12;
            break;
        case 'm':
            __n = __tm->tm_mon+1;
            break;
        case 'M':
            __n = __tm->tm_min+1;
            break;
        case 'S':
            __n = __tm->tm_sec+1;
            break;
        case 'u':
            __n = __tm->tm_wday;
            if (__n==0) __n = 7;
            break;
        case 'w':
            __n = __tm->tm_wday;
            break;
        case 'U':
            // Week number of year (assuming weeks start on Sunday).
            // set __m to wday of first day of year
            __m = (__tm->tm_wday)-((__tm->tm_yday)%7);
            // Correct __m to account for "days before first Sunday"
            // and "Sunday first day of year" conditions
            if ( __m <= 0 ) 
                __m += 7;
            if ( __m == 7 )
                // Sunday is first day of year
                __n = ((__tm->tm_yday)/7)+1;
            else
                // if not, shift Sunday to first day of week 1
                __n = ((__tm->tm_yday)+__m)/7;
            break;
        case 'W':
            // Week number of year (assuming weeks start on Monday).
            // set __m to wday of first day of year
            __m = (__tm->tm_wday)-((__tm->tm_yday)%7);
            // Correct __m to account for "days before first Monday"
            // and "Monday first day of year" conditions
            if ( __m <= 0 ) 
                __m += 7;
            if ( __m == 1 )
                // Monday is first day of year
                __n = ((__tm->tm_yday)/7)+1;
            else
                // if not, shift Monday to first day of week 1
                __n = (((__tm->tm_yday)+(__m-1))/7);
            break;
        case 'y':
            __n = ((__tm->tm_year+1900)%100)+1;
            break;
        default:
            __n = 999; // Cause error output.
        }
        
        __writer._C_put_keyword
            (__writer._C_get_ord_string (*_C_timp, __n), __fill);
        
    }
    else {
        bool __abbrev = false;

        const _TYPENAME
            _RW::__rw_timepunct<_CharT>::string_type *__s = 0;

        _TYPENAME _RW::__rw_timepunct<_CharT>::string_type __tzs;

        int __n = 0, __m = 0;

        __writer._C_base = 10;
        __writer._C_separable = false;

        switch (__fmat) {
        case 'a':
            __abbrev = true;
        case 'A':
            // Week day name or abbreviation.
            __s = &__writer._C_get_day_string (*_C_timp,
                                               __tm->tm_wday, __abbrev);
            break;
            
        case 'b':
        case 'h':
            __abbrev = true;
        case 'B':
            // Month name or abbreviation.
            __s = &__writer
                ._C_get_month_string (*_C_timp, __tm->tm_mon, __abbrev);
            break;
            
        case 'C':
            // Century. Note that we begin the 20th century in 1901, not 1900.
            // The draft standard does not seem to address this controversy.
            __n = (__tm->tm_year+1999)/100;
            break;
            
        case 'd':
            // Day of month with leading zero.
            __writer._C_iprecision = 2;
        case 'e':
            // Day of month with leading blank.
            __n = __tm->tm_mday;
            __writer._C_width = 2;
            break;
            
        case 'H':
            // Hour (24-hour clock).
            __n = __tm->tm_hour;
            __writer._C_iprecision = 2;
            break;
            
        case 'I':
            // Hour (12-hour clock, caller must append am/pm to resolve
            // ambiguity).
            __n = __tm->tm_hour;
            if (__n==0)
                __n = 12;
            else if (__n>12)
                __n -= 12;
            __writer._C_iprecision = 2;
            break;
            
        case 'j':
            // 3-digit day of year.
            __n = __tm->tm_yday+1;
            __writer._C_iprecision = 3;
            break;
            
        case 'm':
            // Month number.
            __n = __tm->tm_mon+1;
            __writer._C_iprecision = 2;
            break;
            
        case 'M':
            // Minutes.
            __n = __tm->tm_min;
            __writer._C_iprecision = 2;
            break;
            
        case 'n':
            // Newline character.
            *__out++ = __writer._C_ctyp.widen ('\n');
            break;
            
        case 'p':
            // ante/post meridian string.
            __s = &__writer._C_get_ampm_string (*_C_timp, __tm->tm_hour>=12);
            break;
            
        case 'S':
            // Seconds.
            __n = __tm->tm_sec;
            __writer._C_iprecision = 2;
            break;
            
        case 't':
            // Tab character.
            *__out++ = __writer._C_ctyp.widen ('\t');
            break;
            
        case 'u':
            // Weekday (1-7, 1==Monday)
            __n = __tm->tm_wday;
            if (__n==0)
                __n = 7;
            break;
            
        case 'U':
            // Week number of year (assuming weeks start on Sunday).
            // set __m to wday of first day of year
            __m = (__tm->tm_wday)-((__tm->tm_yday)%7);
            // Correct __m to account for "days before first Sunday"
            // and "Sunday first day of year" conditions
            if ( __m <= 0 ) 
                __m += 7;
            if ( __m == 7 )
                // Sunday is first day of year
                __n = ((__tm->tm_yday)/7)+1;
            else
                // if not, shift Sunday to first day of week 1
                __n = ((__tm->tm_yday)+__m)/7;
            __writer._C_iprecision = 2;
            break;
            
        case 'w':
            // Weekday (0-6, 0==Sunday).
            __n = __tm->tm_wday;
            break;
            
        case 'W':
            // Week number of year (assuming weeks start on Monday).
            // set __m to wday of first day of year
            __m = (__tm->tm_wday)-((__tm->tm_yday)%7);
            // Correct __m to account for "days before first Monday"
            // and "Monday first day of year" conditions
            if ( __m <= 0 ) 
                __m += 7;
            if ( __m == 1 )
                // Monday is first day of year
                __n = ((__tm->tm_yday)/7)+1;
            else
                // if not, shift Monday to first day of week 1
                __n = (((__tm->tm_yday)+(__m-1))/7);
            __writer._C_iprecision = 2;
            break;
            
        case 'y':
            // Year without century.
            __n = (__tm->tm_year+1900)%100;
            __writer._C_iprecision = 2;
            break;
            
        case 'Y':
            // Year with century.
            __n = __tm->tm_year+1900;
            break;
            
        case 'Z':
            // Time Zone.
        {
            _RW::__rw_use_c_lib_locale __loc (__io.getloc ().name ().c_str ());
            const size_t __bufsize = 64U;
            char __buf[__bufsize];
            size_t __buflen = 0;
            if (0 != (__buflen = strftime (__buf, __bufsize, "x%Z", __tm))) {
                _CharT *__temp = new _CharT[__buflen];
                __writer._C_ctyp.widen (__buf+1, __buf+__buflen, __temp);
                __temp[__buflen-1] = _CharT ();
                __tzs = __temp;
                delete[] __temp;
                __s = &__tzs;
                break;
            }
        }
        
        default:
            // Everything else is an error.
            __s = &__writer._C_get_day_string (*_C_timp, 99, false);
        }
        
        if (__s)
            __writer._C_put_keyword (*__s, __fill);
        else {
            __writer._C_digitize ((unsigned long) __n);
            __writer._C_put_digits (__fill);
        }
    }
    
    return __out;
}


_RWSTD_NAMESPACE_END   // std

⌨️ 快捷键说明

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