mirror of
https://github.com/boostorg/locale.git
synced 2026-01-19 04:22:08 +00:00
Switch to boost::core::string_view
This is compatible to `std::string_view` and also to `boost::string_view` so hence the better option.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Copyright 2020, 2021 Peter Dimov
|
||||
# Copyright 2022-2024 Alexander Grund
|
||||
# Copyright 2022-2025 Alexander Grund
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
@@ -51,7 +51,6 @@ target_link_libraries(boost_locale
|
||||
Boost::config
|
||||
Boost::core
|
||||
Boost::iterator
|
||||
Boost::utility
|
||||
PRIVATE
|
||||
Boost::charconv
|
||||
Boost::predef
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright René Ferdinand Rivera Morell 2023-2024
|
||||
# Copyright(c) 2025 Alexander Grund
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -20,7 +21,7 @@ constant boost_dependencies :
|
||||
/boost/config//boost_config
|
||||
/boost/core//boost_core
|
||||
/boost/iterator//boost_iterator
|
||||
/boost/utility//boost_utility ;
|
||||
;
|
||||
|
||||
project /boost/locale
|
||||
: common-requirements
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2023 Alexander Grund
|
||||
// Copyright (c) 2023-2025 Alexander Grund
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <boost/locale/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -31,7 +31,7 @@ namespace boost { namespace locale { namespace detail {
|
||||
};
|
||||
template<typename Char>
|
||||
struct BOOST_SYMBOL_VISIBLE impl : base {
|
||||
explicit impl(const boost::basic_string_view<Char> value) : s(value) {}
|
||||
explicit impl(const core::basic_string_view<Char> value) : s(value) {}
|
||||
impl* clone() const override { return new impl(*this); }
|
||||
std::basic_string<Char> s;
|
||||
};
|
||||
@@ -49,7 +49,7 @@ namespace boost { namespace locale { namespace detail {
|
||||
}
|
||||
|
||||
template<typename Char>
|
||||
void set(const boost::basic_string_view<Char> s)
|
||||
void set(const core::basic_string_view<Char> s)
|
||||
{
|
||||
BOOST_ASSERT(!s.empty());
|
||||
s_.reset(new impl<Char>(s));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2022-2023 Alexander Grund
|
||||
// Copyright (c) 2022-2025 Alexander Grund
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <boost/locale/config.hpp>
|
||||
#include <boost/locale/encoding_errors.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace boost { namespace locale { namespace conv { namespace detail {
|
||||
|
||||
virtual ~charset_converter() = default;
|
||||
virtual string_type convert(const CharIn* begin, const CharIn* end) = 0;
|
||||
string_type convert(const boost::basic_string_view<CharIn> text)
|
||||
string_type convert(const core::basic_string_view<CharIn> text)
|
||||
{
|
||||
return convert(text.data(), text.data() + text.length());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//
|
||||
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
|
||||
// Copyright (c) 2025 Alexander Grund
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -240,11 +241,11 @@ namespace boost { namespace locale {
|
||||
/// Convert \a text to UTF
|
||||
///
|
||||
/// \throws conversion_error: Conversion failed
|
||||
string_type convert(const boost::string_view text) const { return impl_->convert(text); }
|
||||
string_type convert(const core::string_view text) const { return impl_->convert(text); }
|
||||
/// Convert \a text to UTF
|
||||
///
|
||||
/// \throws conversion_error: Conversion failed
|
||||
string_type operator()(const boost::string_view text) const { return convert(text); }
|
||||
string_type operator()(const core::string_view text) const { return convert(text); }
|
||||
};
|
||||
|
||||
/// Converter class to decode an UTF string and encode it using a local encoding
|
||||
@@ -254,7 +255,7 @@ namespace boost { namespace locale {
|
||||
|
||||
public:
|
||||
using char_type = CharType;
|
||||
using stringview_type = boost::basic_string_view<CharType>;
|
||||
using stringview_type = core::basic_string_view<CharType>;
|
||||
|
||||
/// Create an instance to convert UTF text to text encoded with \a charset according to policy \a how
|
||||
///
|
||||
@@ -298,11 +299,11 @@ namespace boost { namespace locale {
|
||||
/// Convert \a text
|
||||
///
|
||||
/// \throws conversion_error: Conversion failed
|
||||
std::string convert(const boost::string_view text) const { return impl_->convert(text); }
|
||||
std::string convert(const core::string_view text) const { return impl_->convert(text); }
|
||||
/// Convert \a text
|
||||
///
|
||||
/// \throws conversion_error: Conversion failed
|
||||
std::string operator()(const boost::string_view text) const { return convert(text); }
|
||||
std::string operator()(const core::string_view text) const { return convert(text); }
|
||||
};
|
||||
} // namespace conv
|
||||
}} // namespace boost::locale
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// Copyright (c) 2009-2015 Artyom Beilis (Tonkikh)
|
||||
// Copyright (c) 2021-2023 Alexander Grund
|
||||
// Copyright (c) 2021-2025 Alexander Grund
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "mo_hash.hpp"
|
||||
#include "mo_lambda.hpp"
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -141,7 +141,7 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
hash_offset_ = get(24);
|
||||
}
|
||||
|
||||
string_view find(const char* context_in, const char* key_in) const
|
||||
core::string_view find(const char* context_in, const char* key_in) const
|
||||
{
|
||||
if(!has_hash())
|
||||
return {};
|
||||
@@ -192,13 +192,13 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
return data_.data() + off;
|
||||
}
|
||||
|
||||
string_view value(unsigned id) const
|
||||
core::string_view value(unsigned id) const
|
||||
{
|
||||
const uint32_t len = get(translations_offset_ + id * 8);
|
||||
const uint32_t off = get(translations_offset_ + id * 8 + 4);
|
||||
if(len > data_.size() || off > data_.size() - len)
|
||||
throw std::runtime_error("Bad mo-file format");
|
||||
return string_view(&data_[off], len);
|
||||
return core::string_view(&data_[off], len);
|
||||
}
|
||||
|
||||
bool has_hash() const { return hash_size_ != 0; }
|
||||
@@ -233,7 +233,7 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
template<typename CharType>
|
||||
struct mo_file_use_traits {
|
||||
static constexpr bool in_use = false;
|
||||
using string_view_type = basic_string_view<CharType>;
|
||||
using string_view_type = core::basic_string_view<CharType>;
|
||||
static string_view_type use(const mo_file&, const CharType*, const CharType*)
|
||||
{
|
||||
throw std::logic_error("Unexpected call"); // LCOV_EXCL_LINE
|
||||
@@ -243,7 +243,7 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
template<>
|
||||
struct mo_file_use_traits<char> {
|
||||
static constexpr bool in_use = true;
|
||||
using string_view_type = basic_string_view<char>;
|
||||
using string_view_type = core::basic_string_view<char>;
|
||||
static string_view_type use(const mo_file& mo, const char* context, const char* key)
|
||||
{
|
||||
return mo.find(context, key);
|
||||
@@ -254,10 +254,10 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
template<>
|
||||
struct mo_file_use_traits<char8_t> {
|
||||
static constexpr bool in_use = true;
|
||||
using string_view_type = basic_string_view<char8_t>;
|
||||
using string_view_type = core::basic_string_view<char8_t>;
|
||||
static string_view_type use(const mo_file& mo, const char8_t* context, const char8_t* key)
|
||||
{
|
||||
string_view res = mo.find(reinterpret_cast<const char*>(context), reinterpret_cast<const char*>(key));
|
||||
core::string_view res = mo.find(reinterpret_cast<const char*>(context), reinterpret_cast<const char*>(key));
|
||||
return {reinterpret_cast<const char8_t*>(res.data()), res.size()};
|
||||
}
|
||||
};
|
||||
@@ -551,10 +551,10 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string extract(boost::string_view meta, const std::string& key, const boost::string_view separators)
|
||||
static std::string extract(core::string_view meta, const std::string& key, const core::string_view separators)
|
||||
{
|
||||
const size_t pos = meta.find(key);
|
||||
if(pos == boost::string_view::npos)
|
||||
if(pos == core::string_view::npos)
|
||||
return "";
|
||||
meta.remove_prefix(pos + key.size());
|
||||
const size_t end_pos = meta.find_first_of(separators);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
|
||||
// Copyright (c) 2022-2023 Alexander Grund
|
||||
// Copyright (c) 2022-2025 Alexander Grund
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <cstring>
|
||||
|
||||
namespace boost { namespace locale { namespace util {
|
||||
std::string normalize_encoding(const string_view encoding)
|
||||
std::string normalize_encoding(const core::string_view encoding)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(encoding.length());
|
||||
@@ -51,7 +51,7 @@ namespace boost { namespace locale { namespace util {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int encoding_to_windows_codepage(const string_view encoding)
|
||||
int encoding_to_windows_codepage(const core::string_view encoding)
|
||||
{
|
||||
return normalized_encoding_to_windows_codepage(normalize_encoding(encoding));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
|
||||
// Copyright (c) 2022-2023 Alexander Grund
|
||||
// Copyright (c) 2022-2025 Alexander Grund
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -9,7 +9,7 @@
|
||||
#define BOOST_LOCALE_UTIL_ENCODING_HPP
|
||||
|
||||
#include <boost/locale/config.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@@ -48,7 +48,7 @@ namespace boost { namespace locale { namespace util {
|
||||
#endif
|
||||
|
||||
/// Make encoding lowercase and remove all non-alphanumeric characters
|
||||
BOOST_LOCALE_DECL std::string normalize_encoding(string_view encoding);
|
||||
BOOST_LOCALE_DECL std::string normalize_encoding(core::string_view encoding);
|
||||
/// True if the normalized encodings are equal
|
||||
inline bool are_encodings_equal(const std::string& l, const std::string& r)
|
||||
{
|
||||
@@ -58,10 +58,10 @@ namespace boost { namespace locale { namespace util {
|
||||
BOOST_LOCALE_DECL std::vector<std::string> get_simple_encodings();
|
||||
|
||||
#if BOOST_LOCALE_USE_WIN32_API
|
||||
int encoding_to_windows_codepage(string_view encoding);
|
||||
int encoding_to_windows_codepage(core::string_view encoding);
|
||||
#else
|
||||
// Requires WinAPI -> Dummy returning invalid
|
||||
inline int encoding_to_windows_codepage(string_view) // LCOV_EXCL_LINE
|
||||
inline int encoding_to_windows_codepage(core::string_view) // LCOV_EXCL_LINE
|
||||
{
|
||||
return -1; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2024 Alexander Grund
|
||||
// Copyright (c) 2024-2025 Alexander Grund
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
#include <boost/locale/config.hpp>
|
||||
#include <boost/charconv/from_chars.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
|
||||
namespace boost { namespace locale { namespace util {
|
||||
|
||||
template<typename Integer>
|
||||
bool try_to_int(string_view s, Integer& value)
|
||||
bool try_to_int(core::string_view s, Integer& value)
|
||||
{
|
||||
if(s.size() >= 2 && s[0] == '+') {
|
||||
if(s[1] == '-') // "+-" is not allowed, invalid "+<number>" is detected by parser
|
||||
|
||||
Reference in New Issue
Block a user