lib/icu/Collate: pass std::string_view
This commit is contained in:
parent
e620677d7c
commit
91c75a133f
@ -199,7 +199,7 @@ gcc_pure
|
|||||||
static bool
|
static bool
|
||||||
directory_cmp(const Directory &a, const Directory &b) noexcept
|
directory_cmp(const Directory &a, const Directory &b) noexcept
|
||||||
{
|
{
|
||||||
return IcuCollate(a.path.c_str(), b.path.c_str()) < 0;
|
return IcuCollate(a.path, b.path) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -96,7 +96,7 @@ song_cmp(const Song &a, const Song &b) noexcept
|
|||||||
return ret < 0;
|
return ret < 0;
|
||||||
|
|
||||||
/* still no difference? compare file name */
|
/* still no difference? compare file name */
|
||||||
return IcuCollate(a.filename.c_str(), b.filename.c_str()) < 0;
|
return IcuCollate(a.filename, b.filename) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -29,6 +29,11 @@
|
|||||||
#include <unicode/ustring.h>
|
#include <unicode/ustring.h>
|
||||||
#else
|
#else
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <string>
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -73,19 +78,14 @@ IcuCollateFinish() noexcept
|
|||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
int
|
int
|
||||||
IcuCollate(const char *a, const char *b) noexcept
|
IcuCollate(std::string_view a, std::string_view b) noexcept
|
||||||
{
|
{
|
||||||
#if !CLANG_CHECK_VERSION(3,6)
|
|
||||||
/* disabled on clang due to -Wtautological-pointer-compare */
|
|
||||||
assert(a != nullptr);
|
|
||||||
assert(b != nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_ICU
|
#ifdef HAVE_ICU
|
||||||
assert(collator != nullptr);
|
assert(collator != nullptr);
|
||||||
|
|
||||||
UErrorCode code = U_ZERO_ERROR;
|
UErrorCode code = U_ZERO_ERROR;
|
||||||
return (int)ucol_strcollUTF8(collator, a, -1, b, -1, &code);
|
return (int)ucol_strcollUTF8(collator, a.data(), a.size(),
|
||||||
|
b.data(), b.size(), &code);
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
AllocatedString<wchar_t> wa = nullptr, wb = nullptr;
|
AllocatedString<wchar_t> wa = nullptr, wb = nullptr;
|
||||||
@ -120,6 +120,8 @@ IcuCollate(const char *a, const char *b) noexcept
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
return strcoll(a, b);
|
/* need to duplicate for the fallback because std::string_view
|
||||||
|
is not null-terminated */
|
||||||
|
return strcoll(std::string(a).c_str(), std::string(b).c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "util/Compiler.h"
|
#include "util/Compiler.h"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws #std::runtime_error on error.
|
* Throws #std::runtime_error on error.
|
||||||
*/
|
*/
|
||||||
@ -31,8 +33,8 @@ IcuCollateInit();
|
|||||||
void
|
void
|
||||||
IcuCollateFinish() noexcept;
|
IcuCollateFinish() noexcept;
|
||||||
|
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure
|
||||||
int
|
int
|
||||||
IcuCollate(const char *a, const char *b) noexcept;
|
IcuCollate(std::string_view a, std::string_view b) noexcept;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user