Skip to content

Commit

Permalink
Remove ICU related code from source and cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Aug 12, 2024
1 parent 822407b commit ec5f342
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 361 deletions.
22 changes: 3 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# FindICU requires 3.7
# add_link_options() requires 3.13
cmake_minimum_required(VERSION 3.13)

set(CMAKE_SUPPRESS_REGENERATION true)

# use ICU_ROOT
# https://cmake.org/cmake/help/latest/policy/CMP0074.html
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
Expand All @@ -23,7 +22,6 @@ project(upa_url VERSION ${UPA_URL_VERSION} LANGUAGES CXX)
# ${upa_lib_name}-config.cmake
# It also must be used as the package name argument to find_package
set(upa_lib_name upa)
set(upa_lib_name_in upa-icu)
# Exported name for library target files; also used to create an alias
# target: upa::${upa_lib_export}
set(upa_lib_export url)
Expand Down Expand Up @@ -55,7 +53,6 @@ option(UPA_BUILD_TOOLS "Build tools." OFF)
option(UPA_INSTALL "Generate the install target." ON)
# library options
option(UPA_AMALGAMATED "Use amalgamated URL library source." OFF)
option(UPA_USE_WINDOWS_ICU "Use ICU library bundled with Windows 10 version 1903 or later." OFF)
# tests build options
option(UPA_TEST_COVERAGE "Build tests with code coverage reporting" OFF)
option(UPA_TEST_COVERAGE_CLANG "Build tests with Clang source-based code coverage" OFF)
Expand Down Expand Up @@ -114,14 +111,9 @@ endif()

include_directories(deps)

# Are Upa URL and ICU libraries needed?
# Is the Upa URL library needed?
if (UPA_BUILD_TESTS OR UPA_BUILD_BENCH OR UPA_BUILD_FUZZER OR UPA_BUILD_EXAMPLES OR
UPA_BUILD_EXTRACTED OR UPA_INSTALL OR NOT UPA_BUILD_TOOLS)
if (NOT UPA_USE_WINDOWS_ICU)
# This library depends on ICU
find_package(ICU REQUIRED COMPONENTS i18n uc)
endif()

if (UPA_AMALGAMATED)
add_library(${upa_lib_target} STATIC
single_include/upa/url.cpp)
Expand All @@ -131,7 +123,6 @@ if (UPA_BUILD_TESTS OR UPA_BUILD_BENCH OR UPA_BUILD_FUZZER OR UPA_BUILD_EXAMPLES
add_library(${upa_lib_target} STATIC
src/idna.cpp
src/url.cpp
src/url_idna.cpp
src/url_ip.cpp
src/url_percent_encode.cpp
src/url_search_params.cpp
Expand All @@ -143,13 +134,6 @@ if (UPA_BUILD_TESTS OR UPA_BUILD_BENCH OR UPA_BUILD_FUZZER OR UPA_BUILD_EXAMPLES
add_library(upa::${upa_lib_export} ALIAS ${upa_lib_target})
set_target_properties(${upa_lib_target} PROPERTIES
EXPORT_NAME ${upa_lib_export})
if (UPA_USE_WINDOWS_ICU)
target_compile_definitions(${upa_lib_target} PRIVATE UPA_USE_WINDOWS_ICU=1)
set(upa_lib_name_in ${upa_lib_name})
else()
target_include_directories(${upa_lib_target} PRIVATE ${ICU_INCLUDE_DIR})
target_link_libraries(${upa_lib_target} INTERFACE ICU::i18n ICU::uc)
endif()
endif()

# Test targets
Expand Down Expand Up @@ -274,7 +258,7 @@ if (UPA_INSTALL AND NOT UPA_AMALGAMATED)

# generate the config file that includes the exports
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${upa_lib_name_in}-config.cmake.in
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${upa_lib_name}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${upa_lib_name}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${upa_lib_name}
NO_SET_AND_CHECK_MACRO
Expand Down
6 changes: 0 additions & 6 deletions cmake/upa-icu-config.cmake.in

This file was deleted.

67 changes: 1 addition & 66 deletions include/upa/url_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@
#ifndef UPA_URL_HOST_H
#define UPA_URL_HOST_H

#ifndef UPA_USE_ICU
#define UPA_USE_ICU 0 // NOLINT(*-macro-*)
#endif // UPA_USE_ICU

#include "buffer.h"
#include "config.h"
#include "idna.h"
#include "str_arg.h"
#if UPA_USE_ICU
# include "url_idna.h"
#else
# include "idna.h"
#endif
#include "url_ip.h"
#include "url_percent_encode.h"
#include "url_result.h"
Expand Down Expand Up @@ -221,62 +213,6 @@ inline validation_errc host_parser::parse_host(const CharT* first, const CharT*
return validation_errc::domain_invalid_code_point;
}

#if UPA_USE_ICU
// Input for domain_to_ascii
simple_buffer<char16_t> buff_uc;

// copy ASCII chars
for (auto it = first; it != ptr; ++it) {
const auto uch = static_cast<UCharT>(*it);
buff_uc.push_back(static_cast<char16_t>(uch));
}

// Let buff_uc be the result of running UTF-8 decode (to UTF-16) without BOM
// on the percent decoding of UTF-8 encode on input
for (auto it = ptr; it != last;) {
const auto uch = static_cast<UCharT>(*it++);
if (uch < 0x80) {
if (uch != '%') {
buff_uc.push_back(static_cast<char16_t>(uch));
continue;
}
// uch == '%'
unsigned char uc8; // NOLINT(cppcoreguidelines-init-variables)
if (detail::decode_hex_to_byte(it, last, uc8)) {
if (uc8 < 0x80) {
buff_uc.push_back(static_cast<char16_t>(uc8));
continue;
}
// percent encoded utf-8 sequence
// TODO: gal po vieną code_point, tuomet užtektų utf-8 buferio vienam simboliui
simple_buffer<char> buff_utf8;
buff_utf8.push_back(static_cast<char>(uc8));
while (it != last && *it == '%') {
++it; // skip '%'
if (!detail::decode_hex_to_byte(it, last, uc8))
uc8 = '%';
buff_utf8.push_back(static_cast<char>(uc8));
}
url_utf::convert_utf8_to_utf16(buff_utf8.data(), buff_utf8.data() + buff_utf8.size(), buff_uc);
//buff_utf8.clear();
continue;
}
// detected an invalid percent-encoding sequence
buff_uc.push_back('%');
} else { // uch >= 0x80
--it;
url_utf::append_utf16(url_utf::read_utf_char(it, last).value, buff_uc);
}
}


// domain to ASCII
simple_buffer<char16_t> buff_ascii;

const auto res = domain_to_ascii(buff_uc.data(), buff_uc.size(), buff_ascii);
if (res != validation_errc::ok)
return res;
#else
std::string buff_ascii;

const auto pes = std::find(ptr, last, '%');
Expand Down Expand Up @@ -337,7 +273,6 @@ inline validation_errc host_parser::parse_host(const CharT* first, const CharT*
if (!idna::domain_to_ascii(buff_ascii, buff_uc.begin(), buff_uc.end()))
return validation_errc::domain_to_ascii;
}
#endif

if (detail::contains_forbidden_domain_char(buff_ascii.data(), buff_ascii.data() + buff_ascii.size())) {
// 7. If asciiDomain contains a forbidden domain code point, domain-invalid-code-point
Expand Down
Loading

0 comments on commit ec5f342

Please sign in to comment.