Require ICU

This commit is contained in:
Jonas Kvinge 2024-05-19 01:45:19 +02:00
parent 0983ba1339
commit c102d8731a
5 changed files with 5 additions and 73 deletions

View File

@ -99,8 +99,6 @@ if(CCACHE_EXECUTABLE)
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_EXECUTABLE})
endif()
option(USE_ICU "Use ICU" ON)
find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
find_package(Backtrace)
@ -108,14 +106,7 @@ if(Backtrace_FOUND)
set(HAVE_BACKTRACE ON)
endif()
find_package(Boost REQUIRED)
if(USE_ICU)
find_package(ICU COMPONENTS uc i18n REQUIRED)
if(ICU_FOUND)
set(HAVE_ICU ON)
endif()
else()
find_package(Iconv)
endif()
find_package(ICU COMPONENTS uc i18n REQUIRED)
find_package(Protobuf CONFIG)
if(NOT Protobuf_FOUND)
find_package(Protobuf REQUIRED)

View File

@ -995,14 +995,9 @@ link_directories(
${SQLITE_LIBRARY_DIRS}
${PROTOBUF_LIBRARY_DIRS}
${SINGLEAPPLICATION_LIBRARY_DIRS}
${ICU_LIBRARY_DIRS}
)
if(HAVE_ICU)
link_directories(${ICU_LIBRARY_DIRS})
else()
link_directories(${Iconv_LIBRARY_DIRS})
endif()
if(HAVE_ALSA)
link_directories(${ALSA_LIBRARY_DIRS})
endif()
@ -1086,6 +1081,7 @@ target_include_directories(strawberry_lib SYSTEM PUBLIC
${GOBJECT_INCLUDE_DIRS}
${SQLITE_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIRS}
${ICU_INCLUDE_DIRS}
)
if(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
@ -1108,6 +1104,7 @@ target_link_libraries(strawberry_lib PUBLIC
${GLIB_LIBRARIES}
${GOBJECT_LIBRARIES}
${SQLITE_LIBRARIES}
${ICU_LIBRARIES}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Gui
@ -1128,17 +1125,6 @@ if(HAVE_X11_GLOBALSHORTCUTS AND HAVE_X11EXTRAS)
target_link_libraries(strawberry_lib PUBLIC Qt${QT_VERSION_MAJOR}::X11Extras)
endif()
if(HAVE_ICU)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${ICU_INCLUDE_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${ICU_LIBRARIES})
else()
if(FREEBSD AND NOT Iconv_LIBRARIES)
set(Iconv_LIBRARIES iconv)
endif()
target_include_directories(strawberry_lib SYSTEM PRIVATE ${Iconv_INCLUDE_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${Iconv_LIBRARIES})
endif()
if(HAVE_ALSA)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${ALSA_INCLUDE_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${ALSA_LIBRARIES})

View File

@ -21,7 +21,6 @@
#cmakedefine HAVE_MUSICBRAINZ
#cmakedefine HAVE_GLOBALSHORTCUTS
#cmakedefine HAVE_X11_GLOBALSHORTCUTS
#cmakedefine HAVE_ICU
#cmakedefine USE_INSTALL_PREFIX

View File

@ -22,11 +22,7 @@
#include <cstdio>
#include <string>
#ifdef HAVE_ICU
# include <unicode/translit.h>
#else
# include <iconv.h>
#endif
#include <unicode/translit.h>
#include <QByteArray>
#include <QString>
@ -38,8 +34,6 @@ namespace Utilities {
QString Transliterate(const QString &accented_str) {
#ifdef HAVE_ICU
UErrorCode errorcode = U_ZERO_ERROR;
ScopedPtr<icu::Transliterator> transliterator;
transliterator.reset(icu::Transliterator::createInstance("Any-Latin; Latin-ASCII;", UTRANS_FORWARD, errorcode));
@ -55,40 +49,6 @@ QString Transliterate(const QString &accented_str) {
return QString::fromStdString(unaccented_str);
#else
#ifdef LC_ALL
setlocale(LC_ALL, "");
#endif
iconv_t conv = iconv_open("ASCII//TRANSLIT", "UTF-8");
if (conv == reinterpret_cast<iconv_t>(-1)) return accented_str;
QByteArray utf8 = accented_str.toUtf8();
size_t input_len = utf8.length() + 1;
char *input_ptr = new char[input_len];
char *input = input_ptr;
size_t output_len = input_len * 2;
char *output_ptr = new char[output_len];
char *output = output_ptr;
snprintf(input, input_len, "%s", utf8.constData());
iconv(conv, &input, &input_len, &output, &output_len);
iconv_close(conv);
QString ret(output_ptr);
ret = ret.replace('?', '_');
delete[] input_ptr;
delete[] output_ptr;
return ret;
#endif // HAVE_ICU
} // Transliterate
} // namespace Utilities

View File

@ -151,16 +151,12 @@ TEST_F(OrganizeFormatTest, ReplaceNonAscii) {
song_.set_artist(QLatin1String(""));
EXPECT_EQ(QLatin1String(""), format_.GetFilenameForSong(song_).filename);
#ifdef HAVE_ICU
song_.set_artist(QStringLiteral("Владимир Высоцкий"));
EXPECT_EQ(QStringLiteral("Vladimir_Vysockij"), format_.GetFilenameForSong(song_).filename);
song_.set_artist(QStringLiteral("エックス・ジャパン"));
EXPECT_EQ(QStringLiteral("ekkusujapan"), format_.GetFilenameForSong(song_).filename);
#endif
}
TEST_F(OrganizeFormatTest, TrackNumberPadding) {