Ustring format_int(T t, uint64_t flags, int prec) { static constexpr auto float_flags = Format::digits | Format::exp | Format::fixed | Format::general | Format::stripz; static constexpr auto int_flags = Format::binary | Format::decimal | Format::hex | Format::roman; static constexpr auto sign_flags = Format::sign | Format::signz; if ((flags & float_flags) && ! (flags & int_flags)) return format_float(t, flags, prec); if (ibits(flags & int_flags) > 1 || ibits(flags & sign_flags) > 1) throw std::invalid_argument("Inconsistent integer formatting flags"); char sign = 0; if (t > static_cast<T>(0)) { if (flags & (Format::sign | Format::signz)) sign = '+'; } else if (t == static_cast<T>(0)) { if (flags & Format::sign) sign = '+'; } else { t = RS_Detail::SimpleAbs<T>()(t); sign = '-'; } Ustring s; if (flags & Format::binary) s = format_radix(t, 2, prec); else if (flags & Format::roman) s = roman(unsigned(t)); else if (flags & Format::hex) s = format_radix(t, 16, prec); else s = format_radix(t, 10, prec); if (sign) s.insert(s.begin(), sign); return s; }
Ustring format_radix(T t, int base, int prec) { // Argument will never be negative Ustring s; auto b = static_cast<T>(base); prec = std::max(prec, 1); while (t > 0 || int(s.size()) < prec) { auto d = t % b; s += char(d + (d <= 9 ? '0' : 'a' - 10)); t /= b; } std::reverse(s.begin(), s.end()); return s; }
void Entry::calculate_title( const Ustring& text ) { if( text.size() < 1 ) { m_name = _( STRING::EMPTY_ENTRY_TITLE ); return; } unsigned int l_pos = text.find( '\n', 0 ); if( l_pos == std::string::npos ) m_name = text; else m_name = text.substr( 0, l_pos ); }
void Label::Set_text(const Ustring& t) { if(t.Length() == text.Length()) return; text = t; Calculate_request_size(); }
Ustring char_name(char32_t c, uint32_t flags) { using namespace UnicornDetail; static const CharacterNameMap map; Ustring name; if (flags & Cname::control) { auto name_ptr = control_character_name(c); if (name_ptr) name = name_ptr; } if (name.empty() && (flags & Cname::update)) { auto name_ptr = table_lookup(corrected_names_table, c, static_cast<const char*>(nullptr)); if (name_ptr) name = name_ptr; } if (name.empty()) name = map[c]; if (name.empty()) { if (is_unified_ideograph(c)) name = "CJK UNIFIED IDEOGRAPH-" + ascii_uppercase(hex(c, 4)); else if (is_compatibility_ideograph(c)) name = "CJK COMPATIBILITY IDEOGRAPH-" + ascii_uppercase(hex(c, 4)); else name = hangul_name(c); } if (flags & Cname::lower) name = ascii_lowercase(name); if (name.empty() && (flags & Cname::label)) { if (c <= last_unicode_char) { auto gc = char_general_category(c); if (gc == GC::Cc) name = "<control-"; else if (gc == GC::Co) name = "<private-use-"; else if (gc == GC::Cs) name = "<surrogate-"; else if (char_is_noncharacter(c)) name = "<noncharacter-"; else name = "<reserved-"; } else { name = "<noncharacter-"; } if (flags & Cname::lower) name += hex(c, 4); else name += ascii_uppercase(hex(c, 4)); name += '>'; } if (flags & Cname::prefix) { Ustring prefix = char_as_hex(c); if (name.empty()) name = prefix; else name = prefix + ' ' + name; } return name; }
std::function<bool(char32_t)> gc_predicate(const Ustring& cat, bool sense) { auto table = make_category_table(cat.data(), cat.size()); return make_category_function(table, sense); }
Result Date::parse_string( Date::date_t* date, const Ustring& str_date ) { char c_cur; unsigned int num[ 4 ] = { 0, 0, 0, 0 }; // fourth int is for trailing spaces int i( 0 ); for( unsigned j = 0; j < str_date.size(); j++ ) { c_cur = str_date[ j ]; switch( c_cur ) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if( i > 2 ) return INVALID; num[ i ] *= 10; num[ i ] += ( c_cur - '0' ); break; case ' ': if( num[ i ] > 0 ) i++; break; case '.': case '-': case '/': if( num[ i ] == 0 || i == 2 ) return INVALID; else i++; break; default: return INVALID; } } if( num[ 2 ] ) // temporal { unsigned int year( 0 ); unsigned int month( 0 ); unsigned int day( 0 ); if( num[ 0 ] > 31 && num[ 1 ] <= 12 && num[ 2 ] <= 31 ) // YMD { year = num[ 0 ]; month = num[ 1 ]; day = num[ 2 ]; } else { if( num[ 0 ] <= 12 && num[ 1 ] <= 12 ) // both DMY and MDY possible { if( s_date_format_order[ 0 ] == 'M' ) { month = num[ 0 ]; day = num[ 1 ]; } else { day = num[ 0 ]; month = num[ 1 ]; } } else if( num[ 0 ] <= 31 && num[ 1 ] <= 12 ) // DMY { month = num[ 1 ]; day = num[ 0 ]; } else if( num[ 0 ] <= 12 && num[ 1 ] <= 31 ) // MDY { month = num[ 1 ]; day = num[ 0 ]; } else return INVALID; year = num[ 2 ]; if( year < 100 ) year += ( year < 30 ? 2000 : 1900 ); } if( year < YEAR_MIN || year > YEAR_MAX ) return OUT_OF_RANGE; Date date_tmp( year, month, day ); if( ! date_tmp.is_valid() ) // checks days in month return INVALID; if( date ) // pass NULL when just used for checking *date = date_tmp.m_date; } else if( num[ 1 ] ) // ordinal { if( num[ 0 ] > CHAPTER_MAX || num[ 1 ] > ORDER_MAX ) return OUT_OF_RANGE; if( date ) // pass NULL when just used for checking *date = make_date( num[ 0 ], num[ 1 ] ); } else return INVALID; return OK; }
inline GC encode_gc(const Ustring& cat) noexcept { return encode_gc(cat.data()); }