Skip to content

Commit 88605ea

Browse files
lemireanonrig
authored andcommitted
Make it so that we can disable ICU.
1 parent 0cfea87 commit 88605ea

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_subdirectory(src)
2121
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake)
2222

2323
option(ADA_BENCHMARKS "Build benchmarks" OFF)
24+
option(ADA_USE_ICU "Use ICU if available" ON)
2425

2526
if(BUILD_TESTING OR ADA_BENCHMARKS)
2627
include(${PROJECT_SOURCE_DIR}/cmake/import.cmake)
@@ -37,6 +38,7 @@ else()
3738
endif()
3839
endif(BUILD_TESTING)
3940

41+
if(ADA_USE_ICU)
4042

4143
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
4244
message(STATUS "Apple system detected.")
@@ -83,7 +85,12 @@ else(ICU_FOUND)
8385
return()
8486
endif(MSVC)
8587
endif(ICU_FOUND)
88+
89+
else(ADA_USE_ICU)
90+
target_compile_definitions(ada PUBLIC ADA_HAS_ICU=0)
91+
8692
### Going forward, we have ICU for sure, except under Windows.
93+
endif(ADA_USE_ICU)
8794

8895
If(ADA_BENCHMARKS)
8996
message(STATUS "Ada benchmarks enabled.")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Specification for URL parser can be found from the
1111
## Requirements
1212

1313
- A recent C++ compiler supporting C++17. We test GCC 9 or better, LLVM 10 or better and Microsoft Visual Studio 2022.
14-
- We use [ICU](https://icu.unicode.org) under non-Windows systems (macOS, Linux). Under Windows, [we rely on Microsoft's builtin IdnToAscii function](https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-idntoascii).
14+
- We use [ICU](https://icu.unicode.org) when it is available.
1515

1616
## Usage
1717

include/ada/common_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,6 @@ namespace ada {
218218
#include <unicode/utf8.h>
219219
#endif // ADA_HAS_ICU
220220

221+
#define ADA_WINDOWS_TO_ASCII_FALLBACK 0 // we never use anything but ICU. No fallback.
221222

222223
#endif // ADA_COMMON_DEFS_H

singleheader/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ if (Python3_Interpreter_FOUND)
5050
if(MSVC)
5151
target_link_libraries(ada-singleheader-include-source INTERFACE Normaliz)
5252
else()
53-
target_link_libraries(ada-singleheader-include-source INTERFACE ICU::uc ICU::i18n)
53+
if(ADA_USE_ICU)
54+
target_link_libraries(ada-singleheader-include-source INTERFACE ICU::uc ICU::i18n)
55+
else(ADA_USE_ICU)
56+
target_compile_definitions(ada-singleheader-include-source INTERFACE ADA_HAS_ICU=0)
57+
endif(ADA_USE_ICU)
5458
endif()
5559
if (BUILD_TESTING)
5660
add_executable(demo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/demo.cpp>)

src/unicode.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,11 @@ constexpr static uint8_t is_forbidden_domain_code_point_table[] = {
411411
}
412412
out.value().resize(length); // we possibly want to call :shrink_to_fit otherwise we use 255 bytes.
413413
out.value().shrink_to_fit();
414-
415-
#elif defined(_WIN32)
414+
if(std::any_of(out.value().begin(), out.value().end(), ada::unicode::is_forbidden_domain_code_point)) {
415+
out = std::nullopt;
416+
return false;
417+
}
418+
#elif defined(_WIN32) && ADA_WINDOWS_TO_ASCII_FALLBACK
416419
(void)be_strict; // unused.
417420
// Fallback on the system if ICU is not available.
418421
// Windows function assumes UTF-16.
@@ -522,14 +525,14 @@ constexpr static uint8_t is_forbidden_domain_code_point_table[] = {
522525
}
523526
out = std::string(required_buffer_size, 0);
524527
for(size_t i = 0; i < required_buffer_size; i++) { (*out)[i] = char(ascii_buffer.get()[i]); }
525-
#else
526-
(void)be_strict; // unused.
527-
out = input; // We cannot do much more for now.
528-
#endif
529528
if(std::any_of(out.value().begin(), out.value().end(), ada::unicode::is_forbidden_domain_code_point)) {
530529
out = std::nullopt;
531530
return false;
532531
}
532+
#else
533+
(void)be_strict; // unused.
534+
out = input; // We cannot do much more for now.
535+
#endif
533536
return true;
534537
}
535538

tests/wpt_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ int main(int argc, char** argv) {
473473
results[name] = true; // we pretend. The setters fail under Windows due to IDN issues.
474474
#endif // _WIN32
475475
}
476+
#if ADA_HAS_ICU
476477
name = "urltestdata_encoding("+std::string(ADA_URLTESTDATA_JSON)+")";
477478
if(all_tests || name.find(filter) != std::string::npos) {
478479
results[name] = urltestdata_encoding(ADA_URLTESTDATA_JSON);
@@ -481,6 +482,7 @@ int main(int argc, char** argv) {
481482
if(all_tests || name.find(filter) != std::string::npos) {
482483
results[name] = urltestdata_encoding(URLTESTDATA_JSON);
483484
}
485+
#endif
484486
name = "verifydnslength_tests("+std::string(VERIFYDNSLENGTH_TESTS_JSON)+")";
485487
if(all_tests || name.find(filter) != std::string::npos) {
486488
results[name] = verifydnslength_tests(VERIFYDNSLENGTH_TESTS_JSON);

0 commit comments

Comments
 (0)