Exemple #1
0
static tb_wchar_t* tb_printf_string(tb_wchar_t* pb, tb_wchar_t* pe, tb_printf_entry_t e, tb_wchar_t const* s)
{
    if (s)
    {
        tb_int_t n = tb_wcsnlen(s, e.precision);

        // fill space at left side, e.g. "   abcd"
        if (!(e.flags & TB_PRINTF_FLAG_LEFT)) 
        {
            while (n < e.width--) 
                if (pb < pe) *pb++ = L' ';
        }

        // copy string
        tb_int_t i = 0;
        for (i = 0; i < n; ++i)
            if (pb < pe) *pb++ = *s++;

        // fill space at right side, e.g. "abcd    "
        while (n < e.width--) 
            if (pb < pe) *pb++ = L' ';
    }
    else 
    {
        // null
        if (pb < pe) *pb++ = L'n';
        if (pb < pe) *pb++ = L'u';
        if (pb < pe) *pb++ = L'l';
        if (pb < pe) *pb++ = L'l';
    }

    return pb;
}
Exemple #2
0
static tb_void_t tb_test_wcsnlen(tb_wchar_t const* s, tb_size_t size)
{
    __tb_volatile__ tb_long_t   n = 1000000;
    __tb_volatile__ tb_long_t   r = 0;
    tb_hong_t t = tb_mclock();
    while (n--)
    {
        r = tb_wcsnlen(s, size);
    }
    t = tb_mclock() - t;
    tb_wprintf(L"%lld ms, tb_test_wcsnlen(%s, %ld) = %d\n", t, s, size, r);
}