|
|
@@ -21,9 +21,6 @@
|
|
|
#include <jvalidate/detail/expect.h>
|
|
|
|
|
|
namespace jvalidate::detail {
|
|
|
-inline size_t length_u8(std::string_view arg) { return arg.length(); }
|
|
|
-inline size_t length_u32(std::u32string_view arg) { return arg.length(); }
|
|
|
-
|
|
|
inline std::string_view to_u8(std::string_view arg) { return arg; }
|
|
|
inline std::u32string_view to_u32(std::u32string_view arg) { return arg; }
|
|
|
}
|
|
|
@@ -34,26 +31,12 @@ namespace jvalidate::detail {
|
|
|
* @brief Calculates the string-length of the argument, treating multi-byte
|
|
|
* characters as their individual bytes (as if the string was a std::string).
|
|
|
*
|
|
|
- * @param arg A string encoded in UTF32
|
|
|
- *
|
|
|
- * @returns A number no greater than 4 * arg.length(), depending on the number
|
|
|
- * of graphemes/codepoints in the string.
|
|
|
- */
|
|
|
-inline size_t length_u8(std::u32string_view arg) {
|
|
|
- return ada::idna::utf8_length_from_utf32(arg.data(), arg.length());
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * @brief Calculates the string-length of the argument, treating multi-byte
|
|
|
- * characters and unicode graphemes as single characters (which std::string
|
|
|
- * cannot do).
|
|
|
- *
|
|
|
* @param arg Any UTF8 compatible string (including a standard ASCII string)
|
|
|
*
|
|
|
* @returns A number no greater than arg.length(), depending on the number of
|
|
|
* graphemes/codepoints in the string.
|
|
|
*/
|
|
|
-inline size_t length_u32(std::string_view arg) {
|
|
|
+inline size_t length(std::string_view arg) {
|
|
|
return ada::idna::utf32_length_from_utf8(arg.data(), arg.length());
|
|
|
}
|
|
|
|
|
|
@@ -69,24 +52,20 @@ inline std::u32string to_u32(std::string_view str) {
|
|
|
return std::u32string(data.get(), data.get() + bytes);
|
|
|
}
|
|
|
#elif JVALIDATE_HAS_ICU
|
|
|
-inline size_t length_u32(std::string_view arg) {
|
|
|
- icu::UnicodeString ucs = icu::UnicodeString::fromUTF8(icu::StringPiece(arg));
|
|
|
- return ucs.countChar32();
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
-#if JVALIDATE_HAS_IDNA || JVALIDATE_HAS_ICU
|
|
|
/**
|
|
|
- * @brief A proxy for jvalidate::detail::length_u32. This method is provided
|
|
|
- * so that it is possible to use maxLength and minLength constraints even when
|
|
|
- * building without IDNA or ICU in the toolchain.
|
|
|
+ * @brief Calculates the string-length of the argument, treating multi-byte
|
|
|
+ * characters and unicode graphemes as single characters (which std::string
|
|
|
+ * cannot do).
|
|
|
*
|
|
|
* @param arg Any UTF8 compatible string (including a standard ASCII string)
|
|
|
*
|
|
|
* @returns A number no greater than arg.length(), depending on the number of
|
|
|
* graphemes/codepoints in the string.
|
|
|
*/
|
|
|
-inline size_t length(std::string_view arg) { return length_u32(arg); }
|
|
|
+inline size_t length(std::string_view arg) {
|
|
|
+ icu::UnicodeString ucs = icu::UnicodeString::fromUTF8(icu::StringPiece(arg));
|
|
|
+ return ucs.countChar32();
|
|
|
+}
|
|
|
#else
|
|
|
/**
|
|
|
* @brief Calculates the string-length of the argument, without attempting to
|