export dem symbols

master
Daniel Kolesa 2018-01-11 23:38:03 +01:00
parent a93ae710d0
commit dab034d9e0
3 changed files with 100 additions and 86 deletions

View File

@ -279,7 +279,8 @@ struct parse_state {
code_vec const &singles
) {
format(
writer, "%s %s%s(char32_t c) noexcept {\n", ret_type, prefix, fname
writer, "OSTD_EXPORT %s %s%s(char32_t c) noexcept {\n",
ret_type, prefix, fname
);
format(writer, " return utf::uctype_func<\n");
auto it1 = { &ranges, &laces1, &laces2, &singles };

View File

@ -61,6 +61,7 @@
#include <vector>
#include <stdexcept>
#include <ostd/platform.hh>
#include <ostd/range.hh>
#include <ostd/algorithm.hh>
@ -74,10 +75,10 @@ static_assert(
);
namespace detail {
std::size_t tstrlen(char const *p) noexcept;
std::size_t tstrlen(char16_t const *p) noexcept;
std::size_t tstrlen(char32_t const *p) noexcept;
std::size_t tstrlen(wchar_t const *p) noexcept;
OSTD_EXPORT std::size_t tstrlen(char const *p) noexcept;
OSTD_EXPORT std::size_t tstrlen(char16_t const *p) noexcept;
OSTD_EXPORT std::size_t tstrlen(char32_t const *p) noexcept;
OSTD_EXPORT std::size_t tstrlen(wchar_t const *p) noexcept;
}
/** @addtogroup Strings
@ -800,14 +801,14 @@ namespace utf {
* The string is advanced past the Unicode character in the front.
* If the decoding fails, `false` is returned, otherwise it's `true`.
*/
bool decode(string_range &r, char32_t &ret) noexcept;
OSTD_EXPORT bool decode(string_range &r, char32_t &ret) noexcept;
/* @brief Get the Unicode code point for a UTF-16 sequence.
*
* The string is advanced past the Unicode character in the front.
* If the decoding fails, `false` is returned, otherwise it's `true`.
*/
bool decode(u16string_range &r, char32_t &ret) noexcept;
OSTD_EXPORT bool decode(u16string_range &r, char32_t &ret) noexcept;
/* @brief Get the Unicode code point from a UTF-32 string.
*
@ -815,7 +816,7 @@ namespace utf {
* returns `false` for the front character, in which case the string
* will not be advanced.
*/
bool decode(u32string_range &r, char32_t &ret) noexcept;
OSTD_EXPORT bool decode(u32string_range &r, char32_t &ret) noexcept;
/* @brief Get the Unicode code point for a wide Unicode char/sequence.
*
@ -825,13 +826,13 @@ namespace utf {
* priority (on systems where two or more of the types are the same
* size).
*/
bool decode(wstring_range &r, char32_t &ret) noexcept;
OSTD_EXPORT bool decode(wstring_range &r, char32_t &ret) noexcept;
namespace detail {
std::size_t encode(
OSTD_EXPORT std::size_t encode(
char (&ret)[4], char32_t ch
) noexcept;
std::size_t encode(
OSTD_EXPORT std::size_t encode(
char16_t (&ret)[2], char32_t ch
) noexcept;
}
@ -959,7 +960,8 @@ namespace utf {
* If you're sure the string is valid or you don't need to handle the
* error, you can use the more convenient overload below.
*/
std::size_t length(string_range r, string_range &cont) noexcept;
OSTD_EXPORT std::size_t length(string_range r, string_range &cont)
noexcept;
/** @brief Get the number of Unicode code points in a string.
*
@ -972,7 +974,8 @@ namespace utf {
* If you're sure the string is valid or you don't need to handle the
* error, you can use the more convenient overload below.
*/
std::size_t length(u16string_range r, u16string_range &cont) noexcept;
OSTD_EXPORT std::size_t length(u16string_range r, u16string_range &cont)
noexcept;
/** @brief Get the number of Unicode code points in a string.
*
@ -985,7 +988,8 @@ namespace utf {
* If you're sure the string is valid or you don't need to handle the
* error, you can use the more convenient overload below.
*/
std::size_t length(u32string_range r, u32string_range &cont) noexcept;
OSTD_EXPORT std::size_t length(u32string_range r, u32string_range &cont)
noexcept;
/** @brief Get the number of Unicode code points in a string.
*
@ -1001,7 +1005,8 @@ namespace utf {
* The behavior of this function is platform dependent as wide
* characters represent different things on different systems.
*/
std::size_t length(wstring_range r, wstring_range &cont) noexcept;
OSTD_EXPORT std::size_t length(wstring_range r, wstring_range &cont)
noexcept;
/** @brief Get the number of Unicode code points in a UTF-8 string.
*
@ -1013,7 +1018,7 @@ namespace utf {
* If you need to stop at an invalid code unit and get the
* continuation string, use the overload above.
*/
std::size_t length(string_range r) noexcept;
OSTD_EXPORT std::size_t length(string_range r) noexcept;
/** @brief Get the number of Unicode code points in a UTF-16 string.
*
@ -1025,7 +1030,7 @@ namespace utf {
* If you need to stop at an invalid code unit and get the
* continuation string, use the overload above.
*/
std::size_t length(u16string_range r) noexcept;
OSTD_EXPORT std::size_t length(u16string_range r) noexcept;
/** @brief Get the number of Unicode code points in a UTF-32 string.
*
@ -1033,7 +1038,7 @@ namespace utf {
* invalid values as code points, so this function effectively just
* returns the size of the given range.
*/
std::size_t length(u32string_range r) noexcept;
OSTD_EXPORT std::size_t length(u32string_range r) noexcept;
/** @brief Get the number of Unicode code points in a wide string.
*
@ -1048,7 +1053,7 @@ namespace utf {
* The behavior of this function is platform dependent as wide
* characters represent different things on different systems.
*/
std::size_t length(wstring_range r) noexcept;
OSTD_EXPORT std::size_t length(wstring_range r) noexcept;
namespace detail {
template<typename IC, typename OC>
@ -1135,7 +1140,7 @@ namespace utf {
* This is true for either utf::isalpha() or utf::isdigit(). Also
* equivalent to std::isalnum().
*/
bool isalnum(char32_t c) noexcept;
OSTD_EXPORT bool isalnum(char32_t c) noexcept;
/** @brief Check whether a code point is alphabetic.
*
@ -1145,7 +1150,7 @@ namespace utf {
*
* The categories considered alphabetic are `L*`.
*/
bool isalpha(char32_t c) noexcept;
OSTD_EXPORT bool isalpha(char32_t c) noexcept;
/** @brief Check whether a code point is a blank.
*
@ -1154,7 +1159,7 @@ namespace utf {
*
* The blank characters are only space (U+20) and tab (`U+9`).
*/
bool isblank(char32_t c) noexcept;
OSTD_EXPORT bool isblank(char32_t c) noexcept;
/** @brief Check whether a code point is a control character.
*
@ -1163,7 +1168,7 @@ namespace utf {
*
* The category considered control characters is `Cc`.
*/
bool iscntrl(char32_t c) noexcept;
OSTD_EXPORT bool iscntrl(char32_t c) noexcept;
/** @brief Check whether a code point is a digit.
*
@ -1173,14 +1178,14 @@ namespace utf {
*
* The category considered a digit is `Nd`.
*/
bool isdigit(char32_t c) noexcept;
OSTD_EXPORT bool isdigit(char32_t c) noexcept;
/** @brief Check whether a code point is graphic.
*
* This is true when the input is not utf::isspace() and is
* utf::isprint(). Also equivalent to std::isgraph().
*/
bool isgraph(char32_t c) noexcept;
OSTD_EXPORT bool isgraph(char32_t c) noexcept;
/** @brief Check whether a code point is lowercase.
*
@ -1190,7 +1195,7 @@ namespace utf {
*
* The category considered a lowercase is `Ll`.
*/
bool islower(char32_t c) noexcept;
OSTD_EXPORT bool islower(char32_t c) noexcept;
/** @brief Check whether a code point is printable.
*
@ -1198,7 +1203,7 @@ namespace utf {
* all characters that are not utf::iscntrl() and that are not
* U+2028, U+2029, U+FFF9, U+FFFA, U+FFFB.
*/
bool isprint(char32_t c) noexcept;
OSTD_EXPORT bool isprint(char32_t c) noexcept;
/** @brief Check whether a code point is punctuation.
*
@ -1207,7 +1212,7 @@ namespace utf {
* false for others. Punctuation characters are those that satisfy
* utf::isgraph() but are not utf::isalnum().
*/
bool ispunct(char32_t c) noexcept;
OSTD_EXPORT bool ispunct(char32_t c) noexcept;
/** @brief Check whether a code point is a whitespace.
*
@ -1217,7 +1222,7 @@ namespace utf {
* The categories considered blanks are `Z*` with the `B`, `S` and `WS`
* bidirectional categories.
*/
bool isspace(char32_t c) noexcept;
OSTD_EXPORT bool isspace(char32_t c) noexcept;
/** @brief Check whether a code point is titlecase.
*
@ -1226,7 +1231,7 @@ namespace utf {
*
* The category considered a uppercase is `Lt`.
*/
bool istitle(char32_t c) noexcept;
OSTD_EXPORT bool istitle(char32_t c) noexcept;
/** @brief Check whether a code point is uppercase.
*
@ -1236,7 +1241,7 @@ namespace utf {
*
* The category considered a uppercase is `Lu`.
*/
bool isupper(char32_t c) noexcept;
OSTD_EXPORT bool isupper(char32_t c) noexcept;
/** @brief Check whether a code point is a valid character.
*
@ -1247,7 +1252,7 @@ namespace utf {
*
* This is Unicode specific and has no standard ctype equivalent.
*/
bool isvalid(char32_t c) noexcept;
OSTD_EXPORT bool isvalid(char32_t c) noexcept;
/** @brief Check whether a code point is a hexadecimal digit.
*
@ -1259,7 +1264,7 @@ namespace utf {
* but unlike the former it never changes behavior, i.e. it cannot
* support codepage extensions, being Unicode only.
*/
bool isxdigit(char32_t c) noexcept;
OSTD_EXPORT bool isxdigit(char32_t c) noexcept;
/** @brief Convert a Unicode code point to lowercase.
*
@ -1268,7 +1273,7 @@ namespace utf {
* this just returns the input unchanged, otherwise it returns the
* matching lowercase variant.
*/
char32_t tolower(char32_t c) noexcept;
OSTD_EXPORT char32_t tolower(char32_t c) noexcept;
/** @brief Convert a Unicode code point to uppercase.
*
@ -1277,7 +1282,7 @@ namespace utf {
* this just returns the input unchanged, otherwise it returns the
* matching uppercase variant.
*/
char32_t toupper(char32_t c) noexcept;
OSTD_EXPORT char32_t toupper(char32_t c) noexcept;
/** @brief Compare two UTF-8 strings.
*
@ -1324,7 +1329,7 @@ namespace utf {
*
* @see basic_char_range::case_compare()
*/
int case_compare(string_range s1, string_range s2) noexcept;
OSTD_EXPORT int case_compare(string_range s1, string_range s2) noexcept;
/** @brief Compare two UTF-16 strings as case insensitive.
*
@ -1335,7 +1340,8 @@ namespace utf {
*
* @see basic_char_range::case_compare()
*/
int case_compare(u16string_range s1, u16string_range s2) noexcept;
OSTD_EXPORT int case_compare(u16string_range s1, u16string_range s2)
noexcept;
/** @brief Compare two UTF-32 strings as case insensitive.
*
@ -1346,7 +1352,8 @@ namespace utf {
*
* @see basic_char_range::case_compare()
*/
int case_compare(u32string_range s1, u32string_range s2) noexcept;
OSTD_EXPORT int case_compare(u32string_range s1, u32string_range s2)
noexcept;
/** @brief Compare two wide strings as case insensitive.
*
@ -1360,7 +1367,7 @@ namespace utf {
*
* @see basic_char_range::case_compare()
*/
int case_compare(wstring_range s1, wstring_range s2) noexcept;
OSTD_EXPORT int case_compare(wstring_range s1, wstring_range s2) noexcept;
/** @} */
} /* namespace utf */

View File

@ -8,6 +8,8 @@
#include <cstring>
#include <limits>
#include <type_traits>
#include "ostd/platform.hh"
#include "ostd/string.hh"
#include "ostd/format.hh"
@ -40,16 +42,16 @@ sloop:
return (p - bp);
}
std::size_t tstrlen(char const *p) noexcept {
OSTD_EXPORT std::size_t tstrlen(char const *p) noexcept {
return tstrlen_impl(p);
}
std::size_t tstrlen(char16_t const *p) noexcept {
OSTD_EXPORT std::size_t tstrlen(char16_t const *p) noexcept {
return tstrlen_impl(p);
}
std::size_t tstrlen(char32_t const *p) noexcept {
OSTD_EXPORT std::size_t tstrlen(char32_t const *p) noexcept {
return tstrlen_impl(p);
}
std::size_t tstrlen(wchar_t const *p) noexcept {
OSTD_EXPORT std::size_t tstrlen(wchar_t const *p) noexcept {
return tstrlen_impl(p);
}
@ -140,7 +142,7 @@ namespace detail {
return 1;
}
std::size_t encode(
OSTD_EXPORT std::size_t encode(
char (&ret)[4], char32_t ch
) noexcept {
if (ch <= 0x7F) {
@ -174,7 +176,7 @@ namespace detail {
return 0;
}
std::size_t encode(
OSTD_EXPORT std::size_t encode(
char16_t (&ret)[2], char32_t ch
) noexcept {
/* surrogate code point or out of bounds */
@ -223,7 +225,7 @@ namespace detail {
}
} /* namespace detail */
bool decode(string_range &r, char32_t &ret) noexcept {
OSTD_EXPORT bool decode(string_range &r, char32_t &ret) noexcept {
auto tn = r.size();
auto *beg = reinterpret_cast<unsigned char const *>(r.data());
if (std::size_t n; (n = detail::u8_decode(beg, beg + tn, ret))) {
@ -233,7 +235,7 @@ bool decode(string_range &r, char32_t &ret) noexcept {
return false;
}
bool decode(u16string_range &r, char32_t &ret) noexcept {
OSTD_EXPORT bool decode(u16string_range &r, char32_t &ret) noexcept {
auto tn = r.size();
auto *beg = r.data();
if (std::size_t n; (n = detail::u16_decode(beg, beg + tn, ret))) {
@ -243,7 +245,7 @@ bool decode(u16string_range &r, char32_t &ret) noexcept {
return false;
}
bool decode(u32string_range &r, char32_t &ret) noexcept {
OSTD_EXPORT bool decode(u32string_range &r, char32_t &ret) noexcept {
if (r.empty()) {
return false;
}
@ -256,7 +258,7 @@ bool decode(u32string_range &r, char32_t &ret) noexcept {
return true;
}
bool decode(wstring_range &r, char32_t &ret) noexcept {
OSTD_EXPORT bool decode(wstring_range &r, char32_t &ret) noexcept {
std::size_t n, tn = r.size();
if constexpr(is_wchar_u32) {
if (!tn) {
@ -283,35 +285,39 @@ bool decode(wstring_range &r, char32_t &ret) noexcept {
return false;
}
std::size_t length(string_range r, string_range &cont) noexcept {
OSTD_EXPORT std::size_t length(string_range r, string_range &cont) noexcept {
return detail::length(r, cont);
}
std::size_t length(u16string_range r, u16string_range &cont) noexcept {
OSTD_EXPORT std::size_t length(u16string_range r, u16string_range &cont)
noexcept
{
return detail::length(r, cont);
}
std::size_t length(u32string_range r, u32string_range &cont) noexcept {
OSTD_EXPORT std::size_t length(u32string_range r, u32string_range &cont)
noexcept
{
return detail::length(r, cont);
}
std::size_t length(wstring_range r, wstring_range &cont) noexcept {
OSTD_EXPORT std::size_t length(wstring_range r, wstring_range &cont) noexcept {
return detail::length(r, cont);
}
std::size_t length(string_range r) noexcept {
OSTD_EXPORT std::size_t length(string_range r) noexcept {
return detail::length(r);
}
std::size_t length(u16string_range r) noexcept {
OSTD_EXPORT std::size_t length(u16string_range r) noexcept {
return detail::length(r);
}
std::size_t length(u32string_range r) noexcept {
OSTD_EXPORT std::size_t length(u32string_range r) noexcept {
return detail::length(r);
}
std::size_t length(wstring_range r) noexcept {
OSTD_EXPORT std::size_t length(wstring_range r) noexcept {
return detail::length(r);
}
@ -319,19 +325,19 @@ std::size_t length(wstring_range r) noexcept {
* the other ones use custom tables for lookups
*/
bool isalnum(char32_t c) noexcept {
OSTD_EXPORT bool isalnum(char32_t c) noexcept {
return (utf::isalpha(c) || utf::isdigit(c));
}
bool isblank(char32_t c) noexcept {
OSTD_EXPORT bool isblank(char32_t c) noexcept {
return ((c == ' ') || (c == '\t'));
}
bool isgraph(char32_t c) noexcept {
OSTD_EXPORT bool isgraph(char32_t c) noexcept {
return (!utf::isspace(c) && utf::isprint(c));
}
bool isprint(char32_t c) noexcept {
OSTD_EXPORT bool isprint(char32_t c) noexcept {
switch (c) {
case 0x2028:
case 0x2029:
@ -344,11 +350,11 @@ bool isprint(char32_t c) noexcept {
}
}
bool ispunct(char32_t c) noexcept {
OSTD_EXPORT bool ispunct(char32_t c) noexcept {
return (utf::isgraph(c) && !utf::isalnum(c));
}
bool isvalid(char32_t c) noexcept {
OSTD_EXPORT bool isvalid(char32_t c) noexcept {
/* surrogate code points */
if ((c >= 0xD800) && (c <= 0xDFFF)) {
return false;
@ -365,7 +371,7 @@ bool isvalid(char32_t c) noexcept {
return (c <= utf::max_unicode);
}
bool isxdigit(char32_t c) noexcept {
OSTD_EXPORT bool isxdigit(char32_t c) noexcept {
if ((c >= '0') && (c <= '9')) {
return true;
}
@ -478,15 +484,15 @@ struct uctype_func {
};
/* these are geneated */
bool isalpha(char32_t c) noexcept;
bool iscntrl(char32_t c) noexcept;
bool isdigit(char32_t c) noexcept;
bool islower(char32_t c) noexcept;
bool isspace(char32_t c) noexcept;
bool istitle(char32_t c) noexcept;
bool isupper(char32_t c) noexcept;
char32_t tolower(char32_t c) noexcept;
char32_t toupper(char32_t c) noexcept;
OSTD_EXPORT bool isalpha(char32_t c) noexcept;
OSTD_EXPORT bool iscntrl(char32_t c) noexcept;
OSTD_EXPORT bool isdigit(char32_t c) noexcept;
OSTD_EXPORT bool islower(char32_t c) noexcept;
OSTD_EXPORT bool isspace(char32_t c) noexcept;
OSTD_EXPORT bool istitle(char32_t c) noexcept;
OSTD_EXPORT bool isupper(char32_t c) noexcept;
OSTD_EXPORT char32_t tolower(char32_t c) noexcept;
OSTD_EXPORT char32_t toupper(char32_t c) noexcept;
#if __has_include("string_utf.hh")
#include "string_utf.hh"
@ -496,42 +502,42 @@ char32_t toupper(char32_t c) noexcept;
* is generated during build) by providing a bunch of ASCII only fallbacks
*/
bool isalpha(char32_t c) noexcept {
OSTD_EXPORT bool isalpha(char32_t c) noexcept {
return (utf::isupper(c) || utf::islower(c));
}
bool iscntrl(char32_t c) noexcept {
OSTD_EXPORT bool iscntrl(char32_t c) noexcept {
return ((c <= 0x1F) || (c == 0x7F));
}
bool isdigit(char32_t c) noexcept {
OSTD_EXPORT bool isdigit(char32_t c) noexcept {
return ((c >= '0') && (c <= '9'));
}
bool islower(char32_t c) noexcept {
OSTD_EXPORT bool islower(char32_t c) noexcept {
return ((c >= 'a') && (c <= 'z'));
}
bool isspace(char32_t c) noexcept {
OSTD_EXPORT bool isspace(char32_t c) noexcept {
return ((c == ' ') || ((c >= 0x09) && (c <= 0x0D)));
}
bool istitle(char32_t) noexcept {
OSTD_EXPORT bool istitle(char32_t) noexcept {
return false;
}
bool isupper(char32_t c) noexcept {
OSTD_EXPORT bool isupper(char32_t c) noexcept {
return ((c >= 'A') && (c <= 'Z'));
}
char32_t tolower(char32_t c) noexcept {
OSTD_EXPORT char32_t tolower(char32_t c) noexcept {
if (utf::isupper(c)) {
return c | 32;
}
return c;
}
char32_t toupper(char32_t c) noexcept {
OSTD_EXPORT char32_t toupper(char32_t c) noexcept {
if (utf::islower(c)) {
return c ^ 32;
}
@ -593,23 +599,23 @@ namespace detail {
}
}
int case_compare(string_range s1, string_range s2) noexcept {
OSTD_EXPORT int case_compare(string_range s1, string_range s2) noexcept {
auto *beg1 = reinterpret_cast<unsigned char const *>(s1.data());
auto *beg2 = reinterpret_cast<unsigned char const *>(s2.data());
return detail::case_compare(beg1, beg1 + s1.size(), beg2, beg2 + s2.size());
}
int case_compare(u16string_range s1, u16string_range s2) noexcept {
OSTD_EXPORT int case_compare(u16string_range s1, u16string_range s2) noexcept {
auto *beg1 = s1.data(), *beg2 = s2.data();
return detail::case_compare(beg1, beg1 + s1.size(), beg2, beg2 + s2.size());
}
int case_compare(u32string_range s1, u32string_range s2) noexcept {
OSTD_EXPORT int case_compare(u32string_range s1, u32string_range s2) noexcept {
auto *beg1 = s1.data(), *beg2 = s2.data();
return detail::case_compare(beg1, beg1 + s1.size(), beg2, beg2 + s2.size());
}
int case_compare(wstring_range s1, wstring_range s2) noexcept {
OSTD_EXPORT int case_compare(wstring_range s1, wstring_range s2) noexcept {
using C = std::conditional_t<is_wchar_u8, unsigned char, wchar_fixed_t>;
auto *beg1 = reinterpret_cast<C const *>(s1.data());
auto *beg2 = reinterpret_cast<C const *>(s2.data());