Converted uses of utils::string_view to std::string_view
This commit is contained in:
parent
c081233d9d
commit
c5b1fa9dfd
24 changed files with 98 additions and 131 deletions
|
@ -198,7 +198,6 @@
|
|||
<ClInclude Include="..\..\src\serialization\preprocessor.hpp" />
|
||||
<ClInclude Include="..\..\src\serialization\schema_validator.hpp" />
|
||||
<ClInclude Include="..\..\src\serialization\string_utils.hpp" />
|
||||
<ClInclude Include="..\..\src\serialization\string_view.hpp" />
|
||||
<ClInclude Include="..\..\src\serialization\tokenizer.hpp" />
|
||||
<ClInclude Include="..\..\src\serialization\unicode.hpp" />
|
||||
<ClInclude Include="..\..\src\serialization\validator.hpp" />
|
||||
|
|
|
@ -151,9 +151,6 @@
|
|||
<ClInclude Include="..\..\src\spirit_po\version.hpp">
|
||||
<Filter>spirit_po</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\serialization\string_view.hpp">
|
||||
<Filter>Serialization</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\utils\type_trait_aliases.hpp">
|
||||
<Filter>Utils</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace font {
|
|||
|
||||
// Helper functions for link-aware text feature
|
||||
|
||||
inline bool looks_like_url(utils::string_view str)
|
||||
inline bool looks_like_url(std::string_view str)
|
||||
{
|
||||
return (str.size() >= 8) && ((str.substr(0,7) == "http://") || (str.substr(0,8) == "https://"));
|
||||
}
|
||||
|
|
|
@ -721,7 +721,7 @@ void pango_text::rerender(const bool force)
|
|||
auto end_of_line = std::find(start_of_line, text_.cend(), '\n');
|
||||
|
||||
auto part_layout = std::unique_ptr<PangoLayout, std::function<void(void*)>> { pango_layout_new(context_.get()), g_object_unref};
|
||||
auto line = utils::string_view(&*start_of_line, std::distance(start_of_line, end_of_line));
|
||||
auto line = std::string_view(&*start_of_line, std::distance(start_of_line, end_of_line));
|
||||
set_markup(line, *part_layout);
|
||||
copy_layout_properties(*layout_, *part_layout);
|
||||
|
||||
|
@ -757,7 +757,7 @@ void pango_text::rerender(const bool force)
|
|||
}
|
||||
}
|
||||
|
||||
bool pango_text::set_markup(utils::string_view text, PangoLayout& layout) {
|
||||
bool pango_text::set_markup(std::string_view text, PangoLayout& layout) {
|
||||
char* raw_text;
|
||||
std::string semi_escaped;
|
||||
bool valid = validate_markup(text, &raw_text, semi_escaped);
|
||||
|
@ -767,7 +767,7 @@ bool pango_text::set_markup(utils::string_view text, PangoLayout& layout) {
|
|||
|
||||
if(valid) {
|
||||
if(link_aware_) {
|
||||
std::string formatted_text = format_links(text.to_string());
|
||||
std::string formatted_text = format_links(std::string(text));
|
||||
pango_layout_set_markup(&layout, formatted_text.c_str(), formatted_text.size());
|
||||
} else {
|
||||
pango_layout_set_markup(&layout, text.data(), text.size());
|
||||
|
@ -776,7 +776,7 @@ bool pango_text::set_markup(utils::string_view text, PangoLayout& layout) {
|
|||
ERR_GUI_L << "pango_text::" << __func__
|
||||
<< " text '" << text
|
||||
<< "' has broken markup, set to normal text.\n";
|
||||
set_text(_("The text contains invalid Pango markup: ") + text.to_string(), false);
|
||||
set_text(_("The text contains invalid Pango markup: ") + std::string(text), false);
|
||||
}
|
||||
|
||||
return valid;
|
||||
|
@ -820,7 +820,7 @@ std::string pango_text::format_links(const std::string& text) const
|
|||
return result;
|
||||
}
|
||||
|
||||
bool pango_text::validate_markup(utils::string_view text, char** raw_text, std::string& semi_escaped) const
|
||||
bool pango_text::validate_markup(std::string_view text, char** raw_text, std::string& semi_escaped) const
|
||||
{
|
||||
if(pango_parse_markup(text.data(), text.size(),
|
||||
0, nullptr, raw_text, nullptr, nullptr)) {
|
||||
|
@ -835,7 +835,7 @@ bool pango_text::validate_markup(utils::string_view text, char** raw_text, std::
|
|||
* So only try to recover from broken ampersands, by simply replacing them
|
||||
* with the escaped version.
|
||||
*/
|
||||
semi_escaped = semi_escape_text(text.to_string());
|
||||
semi_escaped = semi_escape_text(std::string(text));
|
||||
|
||||
/*
|
||||
* If at least one ampersand is replaced the semi-escaped string
|
||||
|
|
|
@ -169,7 +169,7 @@ public:
|
|||
* and not including any characters from the delimiters set.
|
||||
*
|
||||
* @param position The pixel position in the text area.
|
||||
* @param delimiters
|
||||
* @param delimiters
|
||||
*
|
||||
* @returns The token containing position, and none of the
|
||||
* delimiter characters. If position is out of bounds,
|
||||
|
@ -396,15 +396,15 @@ private:
|
|||
* a bit harder to recover from the errors and still set the markup.
|
||||
*
|
||||
* @param text The text to set as markup.
|
||||
* @param layout
|
||||
* @param layout
|
||||
*
|
||||
* @returns Whether the markup was set or an
|
||||
* unrecoverable error occurred and the text is
|
||||
* set as plain text with an error message.
|
||||
*/
|
||||
bool set_markup(utils::string_view text, PangoLayout& layout);
|
||||
bool set_markup(std::string_view text, PangoLayout& layout);
|
||||
|
||||
bool validate_markup(utils::string_view text, char** raw_text, std::string& semi_escaped) const;
|
||||
bool validate_markup(std::string_view text, char** raw_text, std::string& semi_escaped) const;
|
||||
|
||||
static void copy_layout_properties(PangoLayout& src, PangoLayout& dst);
|
||||
|
||||
|
|
|
@ -184,20 +184,20 @@ unsigned int cached_zoom = 0;
|
|||
|
||||
const std::string data_uri_prefix = "data:";
|
||||
struct parsed_data_URI{
|
||||
explicit parsed_data_URI(utils::string_view data_URI);
|
||||
utils::string_view scheme;
|
||||
utils::string_view mime;
|
||||
utils::string_view base64;
|
||||
utils::string_view data;
|
||||
explicit parsed_data_URI(std::string_view data_URI);
|
||||
std::string_view scheme;
|
||||
std::string_view mime;
|
||||
std::string_view base64;
|
||||
std::string_view data;
|
||||
bool good;
|
||||
};
|
||||
parsed_data_URI::parsed_data_URI(utils::string_view data_URI)
|
||||
parsed_data_URI::parsed_data_URI(std::string_view data_URI)
|
||||
{
|
||||
const std::size_t colon = data_URI.find(':');
|
||||
const utils::string_view after_scheme = data_URI.substr(colon + 1);
|
||||
const std::string_view after_scheme = data_URI.substr(colon + 1);
|
||||
|
||||
const std::size_t comma = after_scheme.find(',');
|
||||
const utils::string_view type_info = after_scheme.substr(0, comma);
|
||||
const std::string_view type_info = after_scheme.substr(0, comma);
|
||||
|
||||
const std::size_t semicolon = type_info.find(';');
|
||||
|
||||
|
@ -267,8 +267,8 @@ void locator::parse_arguments()
|
|||
parsed_data_URI parsed{fn};
|
||||
|
||||
if(!parsed.good) {
|
||||
utils::string_view view{ fn };
|
||||
utils::string_view stripped = view.substr(0, view.find(","));
|
||||
std::string_view view{ fn };
|
||||
std::string_view stripped = view.substr(0, view.find(","));
|
||||
ERR_DP << "Invalid data URI: " << stripped << std::endl;
|
||||
}
|
||||
|
||||
|
@ -560,8 +560,8 @@ static surface load_image_data_uri(const image::locator& loc)
|
|||
parsed_data_URI parsed{loc.get_filename()};
|
||||
|
||||
if(!parsed.good) {
|
||||
utils::string_view fn = loc.get_filename();
|
||||
utils::string_view stripped = fn.substr(0, fn.find(","));
|
||||
std::string_view fn = loc.get_filename();
|
||||
std::string_view stripped = fn.substr(0, fn.find(","));
|
||||
ERR_DP << "Invalid data URI: " << stripped << std::endl;
|
||||
} else if(parsed.mime.substr(0, 5) != "image") {
|
||||
ERR_DP << "Data URI not of image MIME type: " << parsed.mime << std::endl;
|
||||
|
|
|
@ -978,24 +978,24 @@ bool luaW_tableget(lua_State *L, int index, const char* key)
|
|||
return true;
|
||||
}
|
||||
|
||||
utils::string_view luaW_tostring(lua_State *L, int index)
|
||||
std::string_view luaW_tostring(lua_State *L, int index)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char* str = lua_tolstring(L, index, &len);
|
||||
if(!str) {
|
||||
throw luaL_error (L, "not a string");
|
||||
}
|
||||
return utils::string_view(str, len);
|
||||
return std::string_view(str, len);
|
||||
}
|
||||
|
||||
utils::string_view luaW_tostring_or_default(lua_State *L, int index, utils::string_view def)
|
||||
std::string_view luaW_tostring_or_default(lua_State *L, int index, std::string_view def)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char* str = lua_tolstring(L, index, &len);
|
||||
if(!str) {
|
||||
return def;
|
||||
}
|
||||
return utils::string_view(str, len);
|
||||
return std::string_view(str, len);
|
||||
}
|
||||
|
||||
void chat_message(const std::string& caption, const std::string& msg)
|
||||
|
|
|
@ -26,10 +26,10 @@ class vconfig;
|
|||
#include "config.hpp"
|
||||
#include "variable_info.hpp"
|
||||
#include "map/location.hpp"
|
||||
#include "serialization/string_view.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace lua_common {
|
||||
int intf_textdomain(lua_State *L);
|
||||
|
@ -182,8 +182,8 @@ bool luaW_checkvariable(lua_State *L, variable_access_create& v, int n);
|
|||
|
||||
bool luaW_tableget(lua_State *L, int index, const char* key);
|
||||
|
||||
utils::string_view luaW_tostring(lua_State *L, int index);
|
||||
utils::string_view luaW_tostring_or_default(lua_State *L, int index, utils::string_view def = utils::string_view());
|
||||
std::string_view luaW_tostring(lua_State *L, int index);
|
||||
std::string_view luaW_tostring_or_default(lua_State *L, int index, std::string_view def = std::string_view());
|
||||
|
||||
/**
|
||||
* Displays a message in the chat window.
|
||||
|
@ -193,7 +193,7 @@ void chat_message(const std::string& caption, const std::string& msg);
|
|||
/**
|
||||
* Calls a Lua function stored below its @a nArgs arguments at the top of the stack.
|
||||
* @param L the pointer to the lua interpreter.
|
||||
* @param nArgs
|
||||
* @param nArgs
|
||||
* @param nRets LUA_MULTRET for unbounded return values.
|
||||
* @param allow_wml_error controls where any stack traces are output.
|
||||
* @return true if the call was successful and @a nRets return values are available.
|
||||
|
|
|
@ -50,7 +50,7 @@ private:
|
|||
|
||||
using knows_sets_t = std::map<std::string, std::set<map_location>>;
|
||||
using offset_list_t = std::vector<std::pair<int, int>>;
|
||||
using utils::string_view;
|
||||
using std::string_view;
|
||||
using dynamic_bitset = boost::dynamic_bitset<>;
|
||||
using location_set = std::set<map_location>;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ static lg::log_domain log_scripting_lua("scripting/lua");
|
|||
static const char terrinmapKey[] = "terrainmap";
|
||||
static const char maplocationKey[] = "special_locations";
|
||||
|
||||
using utils::string_view;
|
||||
using std::string_view;
|
||||
|
||||
//////// SPECIAL LOCATION ////////
|
||||
|
||||
|
@ -118,7 +118,7 @@ int impl_slocs_set(lua_State* L)
|
|||
|
||||
//////// MAP ////////
|
||||
|
||||
mapgen_gamemap::mapgen_gamemap(utils::string_view s)
|
||||
mapgen_gamemap::mapgen_gamemap(std::string_view s)
|
||||
: tiles_()
|
||||
, starting_positions_()
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
using terrain_code = t_translation::terrain_code;
|
||||
using terrain_map = t_translation::ter_map;
|
||||
using starting_positions = t_translation::starting_positions;
|
||||
explicit mapgen_gamemap(utils::string_view data);
|
||||
explicit mapgen_gamemap(std::string_view data);
|
||||
mapgen_gamemap(int w, int h, terrain_code);
|
||||
|
||||
std::string to_string() const;
|
||||
|
|
|
@ -137,7 +137,7 @@ void luaW_pushwidgettable(lua_State* L, gui2::widget* wg, gui2::window* owner)
|
|||
}
|
||||
|
||||
|
||||
bool luaW_setwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, utils::string_view name)
|
||||
bool luaW_setwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, std::string_view name)
|
||||
{
|
||||
//stack: function
|
||||
luaW_pushwidgettable(L, wg, owner);
|
||||
|
@ -159,7 +159,7 @@ bool luaW_setwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner,
|
|||
return existed_already;
|
||||
}
|
||||
|
||||
void luaW_getwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, utils::string_view name)
|
||||
void luaW_getwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, std::string_view name)
|
||||
{
|
||||
luaW_pushwidgettable(L, wg, owner);
|
||||
//stack: {name = function},
|
||||
|
@ -171,7 +171,7 @@ void luaW_getwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner,
|
|||
//stack: function
|
||||
}
|
||||
|
||||
void luaW_callwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, utils::string_view name)
|
||||
void luaW_callwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, std::string_view name)
|
||||
{
|
||||
luaW_getwidgetcallback(L, wg, owner, name);
|
||||
assert(lua_isfunction(L, -1));
|
||||
|
|
|
@ -43,8 +43,8 @@ void luaW_clearwindowtable(lua_State* L, gui2::window* owner);
|
|||
/** [-0, +1, -] */
|
||||
void luaW_pushwidgettable(lua_State* L, gui2::widget* wg, gui2::window* owner);
|
||||
/** returns true if a callback already existed. [-1, +0, -] */
|
||||
bool luaW_setwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, utils::string_view name);
|
||||
bool luaW_setwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, std::string_view name);
|
||||
/** pushed ther callback function onoto the stack [-0, +1, -] */
|
||||
void luaW_getwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, utils::string_view name);
|
||||
void luaW_getwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, std::string_view name);
|
||||
/** callas a widgets callback [-0, +0, e] */
|
||||
void luaW_callwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, utils::string_view name);
|
||||
void luaW_callwidgetcallback(lua_State* L, gui2::widget* wg, gui2::window* owner, std::string_view name);
|
||||
|
|
|
@ -118,7 +118,7 @@ struct BOOST_PP_CAT(getter_, id) { value_type do_it(widgt_type& w); lua_State* L
|
|||
struct BOOST_PP_CAT(getter_adder_, id) { \
|
||||
BOOST_PP_CAT(getter_adder_, id) () \
|
||||
{ \
|
||||
utils::split_foreach(name, ',', 0, [](utils::string_view name_part){\
|
||||
utils::split_foreach(name, ',', 0, [](std::string_view name_part){\
|
||||
getters[std::string(name_part)].push_back([](lua_State* L, gui2::widget& w) { \
|
||||
if(widgt_type* pw = dynamic_cast<widgt_type*>(&w)) { \
|
||||
lua_push(L, BOOST_PP_CAT(getter_, id){L}.do_it(*pw)); \
|
||||
|
@ -138,7 +138,7 @@ struct BOOST_PP_CAT(setter_, id) { void do_it(widgt_type& w, const value_type& v
|
|||
struct BOOST_PP_CAT(setter_adder_, id) { \
|
||||
BOOST_PP_CAT(setter_adder_, id) ()\
|
||||
{ \
|
||||
utils::split_foreach(name, ',', 0, [](utils::string_view name_part){\
|
||||
utils::split_foreach(name, ',', 0, [](std::string_view name_part){\
|
||||
setters[std::string(name_part)].push_back([](lua_State* L, int idx, gui2::widget& w) { \
|
||||
if(widgt_type* pw = dynamic_cast<widgt_type*>(&w)) { \
|
||||
BOOST_PP_CAT(setter_, id){L}.do_it(*pw, lua_check<value_type>(L, idx)); \
|
||||
|
@ -489,7 +489,7 @@ int impl_widget_get(lua_State* L)
|
|||
}
|
||||
|
||||
}
|
||||
utils::string_view str = lua_check<utils::string_view>(L, 2);
|
||||
std::string_view str = lua_check<std::string_view>(L, 2);
|
||||
|
||||
tgetters::iterator it = getters.find(std::string(str));
|
||||
if(it != getters.end()) {
|
||||
|
@ -513,7 +513,7 @@ int impl_widget_get(lua_State* L)
|
|||
int impl_widget_set(lua_State* L)
|
||||
{
|
||||
gui2::widget& w = luaW_checkwidget(L, 1);
|
||||
utils::string_view str = lua_check<utils::string_view>(L, 2);
|
||||
std::string_view str = lua_check<std::string_view>(L, 2);
|
||||
|
||||
|
||||
tsetters::iterator it = setters.find(std::string(str));
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
#include "scripting/lua_common.hpp"
|
||||
#include "scripting/lua_widget.hpp"
|
||||
|
||||
#include "serialization/string_view.hpp"
|
||||
#include "tstring.hpp"
|
||||
#include "map/location.hpp"
|
||||
#include "lua/lauxlib.h"
|
||||
#include "lua/lua.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
|
||||
class enum_tag;
|
||||
|
@ -89,21 +89,21 @@ namespace lua_check_impl
|
|||
lua_pushlstring(L, val.c_str(), val.size());
|
||||
}
|
||||
|
||||
//utils::string_view
|
||||
//std::string_view
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_same_v<T, utils::string_view>, utils::string_view>
|
||||
std::enable_if_t<std::is_same_v<T, std::string_view>, std::string_view>
|
||||
lua_check(lua_State *L, int n)
|
||||
{
|
||||
return luaW_tostring(L, n);
|
||||
}
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_same_v<T, utils::string_view>, utils::string_view>
|
||||
std::enable_if_t<std::is_same_v<T, std::string_view>, std::string_view>
|
||||
lua_to_or_default(lua_State *L, int n, const T& def)
|
||||
{
|
||||
return luaW_tostring_or_default(L, n, def);
|
||||
}
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_same_v<T, utils::string_view>, void>
|
||||
std::enable_if_t<std::is_same_v<T, std::string_view>, void>
|
||||
lua_push(lua_State *L, const T& val)
|
||||
{
|
||||
lua_pushlstring(L, val.data(), val.size());
|
||||
|
@ -165,7 +165,7 @@ namespace lua_check_impl
|
|||
lua_to_or_default(lua_State *L, int n, const T& def)
|
||||
{
|
||||
T val;
|
||||
utils::string_view str = lua_check_impl::lua_to_or_default<utils::string_view>(L, n, utils::string_view());
|
||||
std::string_view str = lua_check_impl::lua_to_or_default<std::string_view>(L, n, std::string_view());
|
||||
if(!val.parse(str))
|
||||
{
|
||||
return def;
|
||||
|
@ -302,7 +302,7 @@ namespace lua_check_impl
|
|||
|
||||
//std::vector and similar but not std::string
|
||||
template<typename T>
|
||||
std::enable_if_t<is_container<T>::value && !std::is_same_v<T, std::string> && !std::is_same_v<T, utils::string_view>, T>
|
||||
std::enable_if_t<is_container<T>::value && !std::is_same_v<T, std::string> && !std::is_same_v<T, std::string_view>, T>
|
||||
lua_check(lua_State * L, int n)
|
||||
{
|
||||
if (lua_istable(L, n))
|
||||
|
@ -333,7 +333,7 @@ namespace lua_check_impl
|
|||
//also accepts things like std::vector<int>() | std::adaptors::transformed(..)
|
||||
template<typename T>
|
||||
std::enable_if_t<
|
||||
is_container<T>::value && !std::is_same_v<T, std::string> && !std::is_same_v<T, utils::string_view> && !is_map<T>::value
|
||||
is_container<T>::value && !std::is_same_v<T, std::string> && !std::is_same_v<T, std::string_view> && !is_map<T>::value
|
||||
, void
|
||||
>
|
||||
lua_push(lua_State * L, const T& list )
|
||||
|
@ -390,7 +390,7 @@ void lua_push(lua_State *L, const T& val)
|
|||
*
|
||||
*/
|
||||
template<typename T>
|
||||
std::decay_t<T> luaW_table_get_def(lua_State *L, int index, utils::string_view k, const T& def)
|
||||
std::decay_t<T> luaW_table_get_def(lua_State *L, int index, std::string_view k, const T& def)
|
||||
{
|
||||
if(!lua_istable(L, index)) {
|
||||
luaL_argerror(L, index, "table expected");
|
||||
|
@ -412,7 +412,7 @@ std::decay_t<T> luaW_table_get_def(lua_State *L, int index, utils::string_view k
|
|||
|
||||
|
||||
template<typename T>
|
||||
void luaW_table_set(lua_State *L, int index, utils::string_view k, const T& value)
|
||||
void luaW_table_set(lua_State *L, int index, std::string_view k, const T& value)
|
||||
{
|
||||
if(!lua_istable(L, index)) {
|
||||
luaL_argerror(L, index, "table expected");
|
||||
|
|
|
@ -49,7 +49,7 @@ char itoa(unsigned value, const std::string& map)
|
|||
return map[value & 0x3f];
|
||||
}
|
||||
|
||||
std::vector<uint8_t> generic_decode_be(utils::string_view in, const std::vector<int>& atoi_map)
|
||||
std::vector<uint8_t> generic_decode_be(std::string_view in, const std::vector<int>& atoi_map)
|
||||
{
|
||||
const int last_char = in.find_last_not_of("=");
|
||||
const int num_chars = last_char + 1;
|
||||
|
@ -83,7 +83,7 @@ std::vector<uint8_t> generic_decode_be(utils::string_view in, const std::vector<
|
|||
return out;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> generic_decode_le(utils::string_view in, const std::vector<int>& atoi_map)
|
||||
std::vector<uint8_t> generic_decode_le(std::string_view in, const std::vector<int>& atoi_map)
|
||||
{
|
||||
const int last_char = in.find_last_not_of("=");
|
||||
const int length = last_char * 6 / 8;
|
||||
|
@ -212,7 +212,7 @@ std::string generic_encode_le(utils::byte_string_view in, const std::string& ito
|
|||
}
|
||||
|
||||
namespace base64 {
|
||||
std::vector<uint8_t> decode(utils::string_view in)
|
||||
std::vector<uint8_t> decode(std::string_view in)
|
||||
{
|
||||
return generic_decode_be(in, base64_atoi_map());
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ std::string encode(utils::byte_string_view bytes)
|
|||
}
|
||||
}
|
||||
namespace crypt64{
|
||||
std::vector<uint8_t> decode(utils::string_view in)
|
||||
std::vector<uint8_t> decode(std::string_view in)
|
||||
{
|
||||
return generic_decode_le(in, crypt64_atoi_map());
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "serialization/string_view.hpp"
|
||||
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
|
@ -26,12 +24,12 @@ using byte_string_view = std::basic_string_view<uint8_t>;
|
|||
|
||||
// Official Base64 encoding (RFC4648)
|
||||
namespace base64 {
|
||||
std::vector<uint8_t> decode(utils::string_view encoded);
|
||||
std::vector<uint8_t> decode(std::string_view encoded);
|
||||
std::string encode(utils::byte_string_view bytes);
|
||||
}
|
||||
// crypt()-compatible radix-64 encoding
|
||||
namespace crypt64 {
|
||||
std::vector<uint8_t> decode(utils::string_view encoded);
|
||||
std::vector<uint8_t> decode(std::string_view encoded);
|
||||
std::string encode(utils::byte_string_view bytes);
|
||||
// Single character functions. For special use only
|
||||
int decode(char encoded_char);
|
||||
|
|
|
@ -59,7 +59,7 @@ bool notspace(const char c)
|
|||
return !portable_isspace(c);
|
||||
}
|
||||
|
||||
void trim(string_view& s)
|
||||
void trim(std::string_view& s)
|
||||
{
|
||||
s.remove_prefix(std::min(s.find_first_not_of(" \t\r\n"), s.size()));
|
||||
if(s.empty()) {
|
||||
|
@ -79,19 +79,19 @@ void trim(string_view& s)
|
|||
* REMOVE_EMPTY causes empty pieces to be skipped/removed.
|
||||
* STRIP_SPACES causes the leading and trailing spaces of each piece to be ignored/stripped.
|
||||
*/
|
||||
std::vector<std::string> split(string_view s, const char sep, const int flags)
|
||||
std::vector<std::string> split(std::string_view s, const char sep, const int flags)
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
split_foreach(s, sep, flags, [&](string_view item) {
|
||||
split_foreach(s, sep, flags, [&](std::string_view item) {
|
||||
res.emplace_back(item);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
std::set<std::string> split_set(string_view s, char sep, const int flags)
|
||||
std::set<std::string> split_set(std::string_view s, char sep, const int flags)
|
||||
{
|
||||
std::set<std::string> res;
|
||||
split_foreach(s, sep, flags, [&](string_view item) {
|
||||
split_foreach(s, sep, flags, [&](std::string_view item) {
|
||||
res.emplace(item);
|
||||
});
|
||||
return res;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "font/constants.hpp"
|
||||
#include "serialization/string_view.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
@ -24,6 +23,7 @@
|
|||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -42,10 +42,10 @@ enum {
|
|||
STRIP_SPACES = 0x02 /** STRIP_SPACES: strips leading and trailing blank spaces. */
|
||||
};
|
||||
|
||||
void trim(string_view& s);
|
||||
void trim(std::string_view& s);
|
||||
|
||||
template<typename F>
|
||||
void split_foreach_impl(string_view s, char sep, const F& f)
|
||||
void split_foreach_impl(std::string_view s, char sep, const F& f)
|
||||
{
|
||||
if(s.empty()) {
|
||||
return;
|
||||
|
@ -53,7 +53,7 @@ void split_foreach_impl(string_view s, char sep, const F& f)
|
|||
while(true)
|
||||
{
|
||||
int partend = s.find(sep);
|
||||
if(partend == int(string_view::npos)) {
|
||||
if(partend == int(std::string_view::npos)) {
|
||||
break;
|
||||
}
|
||||
f(s.substr(0, partend));
|
||||
|
@ -63,9 +63,9 @@ void split_foreach_impl(string_view s, char sep, const F& f)
|
|||
}
|
||||
|
||||
template<typename F>
|
||||
void split_foreach(string_view s, char sep, const int flags, const F& f)
|
||||
void split_foreach(std::string_view s, char sep, const int flags, const F& f)
|
||||
{
|
||||
split_foreach_impl(s, sep, [&](string_view item) {
|
||||
split_foreach_impl(s, sep, [&](std::string_view item) {
|
||||
if(flags & STRIP_SPACES) {
|
||||
trim(item);
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ void split_foreach(string_view s, char sep, const int flags, const F& f)
|
|||
|
||||
|
||||
/** Splits a (comma-)separated string into a vector of pieces. */
|
||||
std::vector<std::string> split(string_view val, const char c = ',', const int flags = REMOVE_EMPTY | STRIP_SPACES);
|
||||
std::set<std::string> split_set(string_view val, const char c = ',', const int flags = REMOVE_EMPTY | STRIP_SPACES);
|
||||
std::vector<std::string> split(std::string_view val, const char c = ',', const int flags = REMOVE_EMPTY | STRIP_SPACES);
|
||||
std::set<std::string> split_set(std::string_view val, const char c = ',', const int flags = REMOVE_EMPTY | STRIP_SPACES);
|
||||
|
||||
/**
|
||||
* This function is identical to split(), except it does not split when it otherwise would if the
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
Copyright (c) Marshall Clow 2012-2015.
|
||||
Copyright (c) Beman Dawes 2015
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/* This file is the Boost string_view implementation in a single header file.
|
||||
We have an in-tree copy because not all versions of Boost we support have
|
||||
that class. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
using string_view = boost::string_view;
|
||||
} // namespace utils
|
|
@ -118,7 +118,7 @@ bool terrain_filter::match_internal(const map_location& loc, const unit* ref_uni
|
|||
|
||||
if(cfg_.has_attribute("terrain")) {
|
||||
if(cache_.parsed_terrain == nullptr) {
|
||||
cache_.parsed_terrain.reset(new t_translation::ter_match(utils::string_view(cfg_["terrain"].str())));
|
||||
cache_.parsed_terrain.reset(new t_translation::ter_match(std::string_view(cfg_["terrain"].str())));
|
||||
}
|
||||
if(!cache_.parsed_terrain->is_empty) {
|
||||
const t_translation::terrain_code letter = fc_->get_disp_context().map().get_terrain_info(loc).number();
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace t_translation {
|
|||
*/
|
||||
static terrain_code get_mask_(const terrain_code& terrain);
|
||||
|
||||
static ter_layer string_to_layer_(utils::string_view str);
|
||||
static ter_layer string_to_layer_(std::string_view str);
|
||||
|
||||
/**
|
||||
* Converts a string to a layer.
|
||||
|
@ -74,7 +74,7 @@ namespace t_translation {
|
|||
*/
|
||||
static ter_layer string_to_layer_(const std::string& str)
|
||||
{
|
||||
return string_to_layer_(utils::string_view(str));
|
||||
return string_to_layer_(std::string_view(str));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,8 +89,8 @@ namespace t_translation {
|
|||
* @return The terrain code found in the string if no
|
||||
* valid terrain is found VOID will be returned.
|
||||
*/
|
||||
static terrain_code string_to_number_(utils::string_view str, std::vector<std::string>& start_positions, const ter_layer filler);
|
||||
static terrain_code string_to_number_(utils::string_view str, const ter_layer filler = NO_LAYER);
|
||||
static terrain_code string_to_number_(std::string_view str, std::vector<std::string>& start_positions, const ter_layer filler);
|
||||
static terrain_code string_to_number_(std::string_view str, const ter_layer filler = NO_LAYER);
|
||||
|
||||
/**
|
||||
* Converts a terrain number to a string
|
||||
|
@ -172,7 +172,7 @@ ter_match::ter_match() :
|
|||
is_empty(true)
|
||||
{}
|
||||
|
||||
ter_match::ter_match(utils::string_view str, const ter_layer filler) :
|
||||
ter_match::ter_match(std::string_view str, const ter_layer filler) :
|
||||
terrain(t_translation::read_list(str, filler)),
|
||||
mask(),
|
||||
masked_terrain(),
|
||||
|
@ -205,7 +205,7 @@ ter_match::ter_match(const terrain_code& tcode):
|
|||
}
|
||||
}
|
||||
|
||||
terrain_code read_terrain_code(utils::string_view str, const ter_layer filler)
|
||||
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
|
||||
{
|
||||
return string_to_number_(str, filler);
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ std::string write_terrain_code(const terrain_code& tcode)
|
|||
return number_to_string_(tcode);
|
||||
}
|
||||
|
||||
ter_list read_list(utils::string_view str, const ter_layer filler)
|
||||
ter_list read_list(std::string_view str, const ter_layer filler)
|
||||
{
|
||||
// Handle an empty string
|
||||
ter_list result;
|
||||
|
@ -230,7 +230,7 @@ ter_list read_list(utils::string_view str, const ter_layer filler)
|
|||
// Get a terrain chunk
|
||||
const std::string separators = ",";
|
||||
const size_t pos_separator = str.find_first_of(separators, offset);
|
||||
utils::string_view terrain = str.substr(offset, pos_separator - offset);
|
||||
std::string_view terrain = str.substr(offset, pos_separator - offset);
|
||||
|
||||
// Process the chunk
|
||||
const terrain_code tile = string_to_number_(terrain, filler);
|
||||
|
@ -239,7 +239,7 @@ ter_list read_list(utils::string_view str, const ter_layer filler)
|
|||
result.push_back(tile);
|
||||
|
||||
// Evaluate the separator
|
||||
if(pos_separator == utils::string_view::npos) {
|
||||
if(pos_separator == std::string_view::npos) {
|
||||
offset = str.length();
|
||||
} else {
|
||||
offset = pos_separator + 1;
|
||||
|
@ -289,7 +289,7 @@ static std::pair<int, int> get_map_size(const char* begin, const char* end)
|
|||
return{ w, h };
|
||||
}
|
||||
|
||||
ter_map read_game_map(utils::string_view str, starting_positions& starting_positions, coordinate border_offset)
|
||||
ter_map read_game_map(std::string_view str, starting_positions& starting_positions, coordinate border_offset)
|
||||
{
|
||||
std::size_t offset = 0;
|
||||
int x = 0, y = 0, width = 0;
|
||||
|
@ -312,7 +312,7 @@ ter_map read_game_map(utils::string_view str, starting_positions& starting_posit
|
|||
// Get a terrain chunk
|
||||
const std::string separators = ",\n\r";
|
||||
const std::size_t pos_separator = str.find_first_of(separators, offset);
|
||||
utils::string_view terrain = str.substr(offset, pos_separator - offset);
|
||||
std::string_view terrain = str.substr(offset, pos_separator - offset);
|
||||
|
||||
// Process the chunk
|
||||
std::vector<std::string> sp;
|
||||
|
@ -704,7 +704,7 @@ static terrain_code get_mask_(const terrain_code& terrain)
|
|||
}
|
||||
}
|
||||
|
||||
static ter_layer string_to_layer_(utils::string_view str)
|
||||
static ter_layer string_to_layer_(std::string_view str)
|
||||
{
|
||||
if(str.empty()) {
|
||||
return NO_LAYER;
|
||||
|
@ -733,12 +733,12 @@ static ter_layer string_to_layer_(utils::string_view str)
|
|||
return result;
|
||||
}
|
||||
|
||||
static terrain_code string_to_number_(utils::string_view str, const ter_layer filler) {
|
||||
static terrain_code string_to_number_(std::string_view str, const ter_layer filler) {
|
||||
std::vector<std::string> dummy;
|
||||
return string_to_number_(str, dummy, filler);
|
||||
}
|
||||
|
||||
static terrain_code string_to_number_(utils::string_view str, std::vector<std::string>& start_positions, const ter_layer filler)
|
||||
static terrain_code string_to_number_(std::string_view str, std::vector<std::string>& start_positions, const ter_layer filler)
|
||||
{
|
||||
terrain_code result;
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
#include "exceptions.hpp"
|
||||
#include "map/location.hpp"
|
||||
#include "serialization/string_view.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace t_translation {
|
||||
|
||||
|
@ -102,7 +103,7 @@ namespace t_translation {
|
|||
*/
|
||||
struct ter_match{
|
||||
ter_match();
|
||||
ter_match(utils::string_view str, const ter_layer filler = NO_LAYER);
|
||||
ter_match(std::string_view str, const ter_layer filler = NO_LAYER);
|
||||
ter_match(const terrain_code& tcode);
|
||||
|
||||
ter_list terrain;
|
||||
|
@ -180,7 +181,7 @@ namespace t_translation {
|
|||
*
|
||||
* @return A single terrain code
|
||||
*/
|
||||
terrain_code read_terrain_code(utils::string_view str, const ter_layer filler = NO_LAYER);
|
||||
terrain_code read_terrain_code(std::string_view str, const ter_layer filler = NO_LAYER);
|
||||
|
||||
/**
|
||||
* Writes a single terrain code to a string.
|
||||
|
@ -202,7 +203,7 @@ namespace t_translation {
|
|||
*
|
||||
* @returns A vector which contains the terrain codes found in the string
|
||||
*/
|
||||
ter_list read_list(utils::string_view str, const ter_layer filler = NO_LAYER);
|
||||
ter_list read_list(std::string_view str, const ter_layer filler = NO_LAYER);
|
||||
|
||||
/**
|
||||
* Writes a list of terrains to a string, only writes the new format.
|
||||
|
@ -248,7 +249,7 @@ namespace t_translation {
|
|||
* @returns A 2D vector with the terrains found the vector data is stored
|
||||
* like result[x][y] where x the column number is and y the row number.
|
||||
*/
|
||||
ter_map read_game_map(utils::string_view str, starting_positions& positions, coordinate border_offset = coordinate{ 0, 0 });
|
||||
ter_map read_game_map(std::string_view str, starting_positions& positions, coordinate border_offset = coordinate{ 0, 0 });
|
||||
|
||||
/**
|
||||
* Write a gamemap in to a vector string.
|
||||
|
|
|
@ -35,12 +35,13 @@
|
|||
#include "formula/callable_objects.hpp"
|
||||
#include "formula/formula.hpp"
|
||||
#include "formula/function_gamestate.hpp"
|
||||
#include "serialization/string_view.hpp"
|
||||
#include "deprecation.hpp"
|
||||
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue