|
|
@@ -13,6 +13,7 @@
|
|
|
|
|
|
#include <jvalidate/detail/expect.h>
|
|
|
|
|
|
+#ifdef JVALIDATE_HAS_ICU
|
|
|
namespace jvalidate::detail {
|
|
|
/**
|
|
|
* @brief Calclates the string-length of the argument, treating multi-byte
|
|
|
@@ -25,12 +26,8 @@ namespace jvalidate::detail {
|
|
|
* graphemes/codepoints in the string.
|
|
|
*/
|
|
|
inline size_t length(std::string_view arg) {
|
|
|
-#ifdef JVALIDATE_HAS_ICU
|
|
|
icu::UnicodeString ucs = icu::UnicodeString::fromUTF8(icu::StringPiece(arg));
|
|
|
return ucs.countChar32();
|
|
|
-#else
|
|
|
- return arg.size();
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -49,7 +46,6 @@ inline size_t length(std::string_view arg) {
|
|
|
* @returns The regular expression, with some more parenthesis added.
|
|
|
*/
|
|
|
inline std::string regex_escape(std::string_view arg) {
|
|
|
-#ifdef JVALIDATE_HAS_ICU
|
|
|
icu::UnicodeString const ucs = icu::UnicodeString::fromUTF8(icu::StringPiece(arg));
|
|
|
// Short-circuit if there are no multi-byte codepoints or graphemes, since
|
|
|
// C++ regexes don't have any problems with those.
|
|
|
@@ -90,9 +86,6 @@ inline std::string regex_escape(std::string_view arg) {
|
|
|
|
|
|
std::string out;
|
|
|
return rval.toUTF8String(out);
|
|
|
-#else
|
|
|
- return std::string(arg);
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
inline std::u32string to_u32(std::string_view arg) {
|
|
|
@@ -103,7 +96,7 @@ inline std::u32string to_u32(std::string_view arg) {
|
|
|
rval.resize(capacity);
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
- ucs.toUTF32(reinterpret_cast<int*>(rval.data()), capacity, status);
|
|
|
+ ucs.toUTF32(reinterpret_cast<int *>(rval.data()), capacity, status);
|
|
|
// This should never occur - unless there's like an alloc error
|
|
|
if (U_FAILURE(status)) {
|
|
|
JVALIDATE_THROW(std::runtime_error, "UTF-32 Translation Error");
|
|
|
@@ -112,3 +105,5 @@ inline std::u32string to_u32(std::string_view arg) {
|
|
|
return rval;
|
|
|
}
|
|
|
}
|
|
|
+#else
|
|
|
+#endif
|