Skip to content

Commit 39a2a33

Browse files
authored
[char_category] add ranges api for to_c_lower and to_c_upper (#1162)
* move print_freestanding to impl.h * impl * [print] move print_freestanding to a seperate directory to revamp it * special * add license and license-zhCN.txt for anti-tivoization * [core] Fix warnings for codecvt for clang for charxx_t * Add trim to string Overhual entire char_category apis Todo. Implement trim for string_view * add __cpp_static_call_operator to char_category_traits.h * [edit] add string_view for trim, trim.cc string.h * [string] trim_subview_prefix should have fast_io::containers::null_terminated * [char_category] add to_c_lower upper ranges support * [char_category_traits.h] fix to_c_halfwidth * fix issues with shadow * [nt] fix shadow in alpc_nt.h * [char_category] fix api before C++23
1 parent ce2b29f commit 39a2a33

File tree

4 files changed

+417
-395
lines changed

4 files changed

+417
-395
lines changed

include/fast_io_core_impl/char_category/char_category.h

Lines changed: 0 additions & 306 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,268 +1578,6 @@ inline constexpr char32_t to_c_lower_ascii_impl(char32_t ch) noexcept
15781578

15791579
} // namespace details
15801580

1581-
template <::std::integral char_type>
1582-
inline constexpr char_type to_c_lower(char_type ch) noexcept
1583-
{
1584-
using unsigned_char_type = ::std::make_unsigned_t<char_type>;
1585-
if constexpr (!::fast_io::details::is_ebcdic<char_type>)
1586-
{
1587-
return static_cast<char_type>(
1588-
static_cast<unsigned_char_type>(details::to_c_lower_ascii_impl(static_cast<unsigned_char_type>(ch))));
1589-
}
1590-
else if constexpr (::std::same_as<char, char_type>)
1591-
{
1592-
switch (ch)
1593-
{
1594-
case 'A':
1595-
return 'a';
1596-
case 'B':
1597-
return 'b';
1598-
case 'C':
1599-
return 'c';
1600-
case 'D':
1601-
return 'd';
1602-
case 'E':
1603-
return 'e';
1604-
case 'F':
1605-
return 'f';
1606-
case 'G':
1607-
return 'g';
1608-
case 'H':
1609-
return 'h';
1610-
case 'I':
1611-
return 'i';
1612-
case 'J':
1613-
return 'j';
1614-
case 'K':
1615-
return 'k';
1616-
case 'L':
1617-
return 'l';
1618-
case 'M':
1619-
return 'm';
1620-
case 'N':
1621-
return 'n';
1622-
case 'O':
1623-
return 'o';
1624-
case 'P':
1625-
return 'p';
1626-
case 'Q':
1627-
return 'q';
1628-
case 'R':
1629-
return 'r';
1630-
case 'S':
1631-
return 's';
1632-
case 'T':
1633-
return 't';
1634-
case 'U':
1635-
return 'u';
1636-
case 'V':
1637-
return 'v';
1638-
case 'W':
1639-
return 'w';
1640-
case 'X':
1641-
return 'x';
1642-
case 'Y':
1643-
return 'y';
1644-
case 'Z':
1645-
return 'z';
1646-
default:
1647-
return ch;
1648-
}
1649-
}
1650-
else if constexpr (::std::same_as<wchar_t, char_type>)
1651-
{
1652-
switch (ch)
1653-
{
1654-
case L'A':
1655-
return L'a';
1656-
case L'B':
1657-
return L'b';
1658-
case L'C':
1659-
return L'c';
1660-
case L'D':
1661-
return L'd';
1662-
case L'E':
1663-
return L'e';
1664-
case L'F':
1665-
return L'f';
1666-
case L'G':
1667-
return L'g';
1668-
case L'H':
1669-
return L'h';
1670-
case L'I':
1671-
return L'i';
1672-
case L'J':
1673-
return L'j';
1674-
case L'K':
1675-
return L'k';
1676-
case L'L':
1677-
return L'l';
1678-
case L'M':
1679-
return L'm';
1680-
case L'N':
1681-
return L'n';
1682-
case L'O':
1683-
return L'o';
1684-
case L'P':
1685-
return L'p';
1686-
case L'Q':
1687-
return L'q';
1688-
case L'R':
1689-
return L'r';
1690-
case L'S':
1691-
return L's';
1692-
case L'T':
1693-
return L't';
1694-
case L'U':
1695-
return L'u';
1696-
case L'V':
1697-
return L'v';
1698-
case L'W':
1699-
return L'w';
1700-
case L'X':
1701-
return L'x';
1702-
case L'Y':
1703-
return L'y';
1704-
case L'Z':
1705-
return L'z';
1706-
default:
1707-
return ch;
1708-
}
1709-
}
1710-
}
1711-
1712-
template <::std::integral char_type>
1713-
inline constexpr char_type to_c_upper(char_type ch) noexcept
1714-
{
1715-
using unsigned_char_type = ::std::make_unsigned_t<char_type>;
1716-
if constexpr (!::fast_io::details::is_ebcdic<char_type>)
1717-
{
1718-
return static_cast<char_type>(
1719-
static_cast<unsigned_char_type>(details::to_c_upper_ascii_impl(static_cast<unsigned_char_type>(ch))));
1720-
}
1721-
else if constexpr (::std::same_as<char, char_type>)
1722-
{
1723-
switch (ch)
1724-
{
1725-
case 'a':
1726-
return 'A';
1727-
case 'b':
1728-
return 'B';
1729-
case 'c':
1730-
return 'C';
1731-
case 'd':
1732-
return 'D';
1733-
case 'e':
1734-
return 'E';
1735-
case 'f':
1736-
return 'F';
1737-
case 'g':
1738-
return 'G';
1739-
case 'h':
1740-
return 'H';
1741-
case 'i':
1742-
return 'I';
1743-
case 'j':
1744-
return 'J';
1745-
case 'k':
1746-
return 'K';
1747-
case 'l':
1748-
return 'L';
1749-
case 'm':
1750-
return 'M';
1751-
case 'n':
1752-
return 'N';
1753-
case 'o':
1754-
return 'O';
1755-
case 'p':
1756-
return 'P';
1757-
case 'q':
1758-
return 'Q';
1759-
case 'r':
1760-
return 'R';
1761-
case 's':
1762-
return 'S';
1763-
case 't':
1764-
return 'T';
1765-
case 'u':
1766-
return 'U';
1767-
case 'v':
1768-
return 'V';
1769-
case 'w':
1770-
return 'W';
1771-
case 'x':
1772-
return 'X';
1773-
case 'y':
1774-
return 'Y';
1775-
case 'z':
1776-
return 'Z';
1777-
default:
1778-
return ch;
1779-
}
1780-
}
1781-
else if constexpr (::std::same_as<wchar_t, char_type>)
1782-
{
1783-
switch (ch)
1784-
{
1785-
case L'a':
1786-
return L'A';
1787-
case L'b':
1788-
return L'B';
1789-
case L'c':
1790-
return L'C';
1791-
case L'd':
1792-
return L'D';
1793-
case L'e':
1794-
return L'E';
1795-
case L'f':
1796-
return L'F';
1797-
case L'g':
1798-
return L'G';
1799-
case L'h':
1800-
return L'H';
1801-
case L'i':
1802-
return L'I';
1803-
case L'j':
1804-
return L'J';
1805-
case L'k':
1806-
return L'K';
1807-
case L'l':
1808-
return L'L';
1809-
case L'm':
1810-
return L'M';
1811-
case L'n':
1812-
return L'N';
1813-
case L'o':
1814-
return L'O';
1815-
case L'p':
1816-
return L'P';
1817-
case L'q':
1818-
return L'Q';
1819-
case L'r':
1820-
return L'R';
1821-
case L's':
1822-
return L'S';
1823-
case L't':
1824-
return L'T';
1825-
case L'u':
1826-
return L'U';
1827-
case L'v':
1828-
return L'V';
1829-
case L'w':
1830-
return L'W';
1831-
case L'x':
1832-
return L'X';
1833-
case L'y':
1834-
return L'Y';
1835-
case L'z':
1836-
return L'Z';
1837-
default:
1838-
return ch;
1839-
}
1840-
}
1841-
}
1842-
18431581
/*
18441582
All Ascii based charset, only 6 character is supported
18451583
space (0x20, ' ')
@@ -2183,50 +1921,6 @@ inline constexpr bool is_c_fullwidth(char_type ch) noexcept
21831921
To do: to_c_fullwidth
21841922
*/
21851923

2186-
template <::std::integral char_type>
2187-
inline constexpr char_type to_c_halfwidth(char_type ch) noexcept
2188-
{
2189-
using unsigned_char_type = ::std::make_unsigned_t<char_type>;
2190-
if constexpr (sizeof(char_type) < sizeof(char32_t))
2191-
{
2192-
return ch;
2193-
}
2194-
else if constexpr (!::std::same_as<char_type, char32_t> && sizeof(char_type) == sizeof(char32_t))
2195-
{
2196-
return static_cast<char_type>(to_c_halfwidth(static_cast<char32_t>(ch)));
2197-
}
2198-
else if constexpr (::std::signed_integral<char_type>)
2199-
{
2200-
return static_cast<char_type>(to_c_halfwidth(static_cast<unsigned_char_type>(ch)));
2201-
}
2202-
else if constexpr (::std::same_as<char_type, wchar_t> && ::fast_io::details::wide_is_none_utf_endian)
2203-
{
2204-
constexpr unsigned_char_type fullwidth_exclaimation_mark_val{0xFF01};
2205-
constexpr unsigned_char_type num{94};
2206-
constexpr unsigned_char_type halfwidth_exclaimation_mark_val{u8'!'};
2207-
unsigned_char_type cht{ch};
2208-
cht = ::fast_io::byte_swap(cht);
2209-
unsigned_char_type const umav{static_cast<unsigned_char_type>(cht - fullwidth_exclaimation_mark_val)};
2210-
if (umav < num)
2211-
{
2212-
return static_cast<unsigned_char_type>(umav + halfwidth_exclaimation_mark_val);
2213-
}
2214-
return cht;
2215-
}
2216-
else
2217-
{
2218-
constexpr unsigned_char_type fullwidth_exclaimation_mark_val{0xFF01};
2219-
constexpr unsigned_char_type num{94};
2220-
constexpr unsigned_char_type halfwidth_exclaimation_mark_val{u8'!'};
2221-
unsigned_char_type const umav{static_cast<unsigned_char_type>(ch - fullwidth_exclaimation_mark_val)};
2222-
if (umav < num)
2223-
{
2224-
return static_cast<unsigned_char_type>(umav + halfwidth_exclaimation_mark_val);
2225-
}
2226-
return ch;
2227-
}
2228-
}
2229-
22301924
template <::std::integral T>
22311925
inline constexpr bool is_dos_path_invalid_character(T ch) noexcept
22321926
{

0 commit comments

Comments
 (0)