use std::string_view
This commit is contained in:
parent
d6590f88b0
commit
56a9647d56
@ -65,11 +65,12 @@ namespace nana
|
|||||||
bool review_utf8(std::string& text);
|
bool review_utf8(std::string& text);
|
||||||
|
|
||||||
const std::string& to_utf8(const std::string&);
|
const std::string& to_utf8(const std::string&);
|
||||||
std::string to_utf8(const std::wstring&);
|
|
||||||
|
|
||||||
#ifdef _nana_std_has_string_view
|
#ifdef _nana_std_has_string_view
|
||||||
|
std::string to_utf8(std::wstring_view sv);
|
||||||
std::wstring to_wstring(std::string_view utf8_str);
|
std::wstring to_wstring(std::string_view utf8_str);
|
||||||
#else
|
#else
|
||||||
|
std::string to_utf8(const std::wstring&);
|
||||||
std::wstring to_wstring(const std::string& utf8_str);
|
std::wstring to_wstring(const std::string& utf8_str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* A Combox Implementation
|
* A Combox Implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -77,6 +77,7 @@ namespace nana
|
|||||||
public:
|
public:
|
||||||
item_proxy(drawer_impl*, std::size_t pos);
|
item_proxy(drawer_impl*, std::size_t pos);
|
||||||
item_proxy& text(const ::std::string&);
|
item_proxy& text(const ::std::string&);
|
||||||
|
|
||||||
::std::string text() const;
|
::std::string text() const;
|
||||||
item_proxy& select();
|
item_proxy& select();
|
||||||
bool selected() const;
|
bool selected() const;
|
||||||
@ -103,22 +104,19 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
item_proxy& value(const T& t)
|
item_proxy& value(T&& val)
|
||||||
{
|
{
|
||||||
*_m_anyobj(true) = t;
|
*_m_anyobj(true) = ::std::forward<T>(val);
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
item_proxy& value(T&& t)
|
|
||||||
{
|
|
||||||
*_m_anyobj(true) = ::std::move(t);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
/// Behavior of Iterator's value_type
|
/// Behavior of Iterator's value_type
|
||||||
|
#ifdef _nana_std_has_string_view
|
||||||
|
bool operator==(::std::string_view) const;
|
||||||
|
#else
|
||||||
bool operator==(const ::std::string&) const;
|
bool operator==(const ::std::string&) const;
|
||||||
bool operator==(const char*) const;
|
bool operator==(const char*) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Behavior of Iterator
|
/// Behavior of Iterator
|
||||||
item_proxy & operator=(const item_proxy&);
|
item_proxy & operator=(const item_proxy&);
|
||||||
@ -192,19 +190,11 @@ namespace nana
|
|||||||
return _m_at_key(std::move(p));
|
return _m_at_key(std::move(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key>
|
|
||||||
void erase_key(const Key& kv)
|
|
||||||
{
|
|
||||||
typedef typename nana::detail::type_escape<Key>::type key_t;
|
|
||||||
std::unique_ptr<nana::detail::key_interface> p(new nana::key<key_t, std::less<key_t> >(kv));
|
|
||||||
_m_erase(p.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Key>
|
template<typename Key>
|
||||||
void erase_key(Key&& kv)
|
void erase_key(Key&& kv)
|
||||||
{
|
{
|
||||||
typedef typename nana::detail::type_escape<Key>::type key_t;
|
typedef typename nana::detail::type_escape<Key>::type key_t;
|
||||||
std::unique_ptr<nana::detail::key_interface> p(new nana::key<key_t, std::less<key_t> >(std::move(kv)));
|
std::unique_ptr<nana::detail::key_interface> p(new nana::key<key_t, std::less<key_t> >(std::forward<Key>(kv)));
|
||||||
_m_erase(p.get());
|
_m_erase(p.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -933,15 +933,20 @@ namespace nana
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
item_proxy & value(T&& t)
|
item_proxy & value(T&& t)
|
||||||
{
|
{
|
||||||
*_m_value(true) = std::forward<T>(t);
|
*_m_value(true) = ::std::forward<T>(t);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Behavior of Iterator's value_type
|
/// Behavior of Iterator's value_type
|
||||||
|
#ifdef _nana_std_has_string_view
|
||||||
|
bool operator==(::std::string_view sv) const;
|
||||||
|
bool operator==(::std::wstring_view sv) const;
|
||||||
|
#else
|
||||||
bool operator==(const char * s) const;
|
bool operator==(const char * s) const;
|
||||||
bool operator==(const wchar_t * s) const;
|
bool operator==(const wchar_t * s) const;
|
||||||
bool operator==(const ::std::string& s) const;
|
bool operator==(const ::std::string& s) const;
|
||||||
bool operator==(const ::std::wstring& s) const;
|
bool operator==(const ::std::wstring& s) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Behavior of Iterator
|
/// Behavior of Iterator
|
||||||
item_proxy & operator=(const item_proxy&);
|
item_proxy & operator=(const item_proxy&);
|
||||||
|
|||||||
@ -175,12 +175,12 @@ namespace nana
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_utf8(const std::wstring& text)
|
#ifdef _nana_std_has_string_view
|
||||||
|
std::string to_utf8(std::wstring_view text)
|
||||||
{
|
{
|
||||||
return ::nana::charset(text).to_bytes(::nana::unicode::utf8);
|
return ::nana::charset(std::wstring{text}).to_bytes(::nana::unicode::utf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _nana_std_has_string_view
|
|
||||||
std::wstring to_wstring(std::string_view utf8_str)
|
std::wstring to_wstring(std::string_view utf8_str)
|
||||||
{
|
{
|
||||||
if (utf8_str.empty())
|
if (utf8_str.empty())
|
||||||
@ -189,6 +189,11 @@ namespace nana
|
|||||||
return ::nana::charset(std::string{ utf8_str.data(), utf8_str.size() }, unicode::utf8);
|
return ::nana::charset(std::string{ utf8_str.data(), utf8_str.size() }, unicode::utf8);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
std::string to_utf8(const std::wstring& text)
|
||||||
|
{
|
||||||
|
return ::nana::charset(text).to_bytes(::nana::unicode::utf8);
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring to_wstring(const std::string& utf8_str)
|
std::wstring to_wstring(const std::string& utf8_str)
|
||||||
{
|
{
|
||||||
return ::nana::charset(utf8_str, ::nana::unicode::utf8);
|
return ::nana::charset(utf8_str, ::nana::unicode::utf8);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* A Combox Implementation
|
* A Combox Implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -823,6 +823,14 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Behavior of Iterator's value_type
|
/// Behavior of Iterator's value_type
|
||||||
|
#ifdef _nana_std_has_string_view
|
||||||
|
bool item_proxy::operator == (::std::string_view s) const
|
||||||
|
{
|
||||||
|
if (pos_ == nana::npos)
|
||||||
|
return false;
|
||||||
|
return (impl_->at(pos_).item_text == s);
|
||||||
|
}
|
||||||
|
#else
|
||||||
bool item_proxy::operator == (const ::std::string& s) const
|
bool item_proxy::operator == (const ::std::string& s) const
|
||||||
{
|
{
|
||||||
if (pos_ == nana::npos)
|
if (pos_ == nana::npos)
|
||||||
@ -836,6 +844,7 @@ namespace nana
|
|||||||
return false;
|
return false;
|
||||||
return (impl_->at(pos_).item_text == s);
|
return (impl_->at(pos_).item_text == s);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// Behavior of Iterator
|
/// Behavior of Iterator
|
||||||
|
|||||||
@ -4825,6 +4825,17 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Behavior of Iterator's value_type
|
//Behavior of Iterator's value_type
|
||||||
|
#ifdef _nana_std_has_string_view
|
||||||
|
bool item_proxy::operator==(std::string_view sv) const
|
||||||
|
{
|
||||||
|
return (text(0) == sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool item_proxy::operator==(std::wstring_view sv) const
|
||||||
|
{
|
||||||
|
return (text(0) == to_utf8(sv));
|
||||||
|
}
|
||||||
|
#else
|
||||||
bool item_proxy::operator==(const char * s) const
|
bool item_proxy::operator==(const char * s) const
|
||||||
{
|
{
|
||||||
return this->operator==(std::string(s));
|
return this->operator==(std::string(s));
|
||||||
@ -4844,6 +4855,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
return (text(0) == to_utf8(s));
|
return (text(0) == to_utf8(s));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
item_proxy & item_proxy::operator=(const item_proxy& rhs)
|
item_proxy & item_proxy::operator=(const item_proxy& rhs)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user