deploy string_view
This commit is contained in:
parent
8ac4ee6ff8
commit
1671975859
5 changed files with 25 additions and 25 deletions
|
@ -779,7 +779,7 @@ void terrain_builder::add_constraints(terrain_builder::constraint_set& constrain
|
|||
|
||||
{
|
||||
terrain_constraint& constraint = add_constraints(
|
||||
constraints, loc, t_translation::ter_match(cfg["type"], t_translation::WILDCARD), global_images);
|
||||
constraints, loc, t_translation::ter_match(cfg["type"].str(), t_translation::WILDCARD), global_images);
|
||||
|
||||
std::vector<std::string> item_string = utils::square_parenthetical_split(cfg["set_flag"], ',', "[", "]");
|
||||
constraint.set_flag.insert(constraint.set_flag.end(), item_string.begin(), item_string.end());
|
||||
|
|
|
@ -117,7 +117,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(cfg_["terrain"]));
|
||||
cache_.parsed_terrain.reset(new t_translation::ter_match(utils::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();
|
||||
|
|
|
@ -73,7 +73,7 @@ terrain_type::terrain_type(const config& cfg) :
|
|||
editor_name_(cfg["editor_name"].t_str()),
|
||||
description_(cfg["description"].t_str()),
|
||||
help_topic_text_(cfg["help_topic_text"].t_str()),
|
||||
number_(t_translation::read_terrain_code(cfg["string"])),
|
||||
number_(t_translation::read_terrain_code(cfg["string"].str())),
|
||||
mvt_type_(),
|
||||
vision_type_(),
|
||||
def_type_(),
|
||||
|
@ -96,7 +96,7 @@ terrain_type::terrain_type(const config& cfg) :
|
|||
keep_(cfg["recruit_from"].to_bool()),
|
||||
overlay_(number_.base == t_translation::NO_LAYER),
|
||||
combined_(false),
|
||||
editor_default_base_(t_translation::read_terrain_code(cfg["default_base"])),
|
||||
editor_default_base_(t_translation::read_terrain_code(cfg["default_base"].str())),
|
||||
hide_help_(cfg["hide_help"].to_bool(false)),
|
||||
hide_in_editor_(cfg["hidden"].to_bool(false)),
|
||||
hide_if_impassable_(cfg["hide_if_impassable"].to_bool(false))
|
||||
|
|
|
@ -88,8 +88,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_(std::string str, std::string& start_position, const ter_layer filler);
|
||||
static terrain_code string_to_number_(const std::string& str, const ter_layer filler = NO_LAYER);
|
||||
static terrain_code string_to_number_(utils::string_view, std::string& start_position, const ter_layer filler);
|
||||
static terrain_code string_to_number_(utils::string_view, const ter_layer filler = NO_LAYER);
|
||||
|
||||
/**
|
||||
* Converts a terrain number to a string
|
||||
|
@ -166,7 +166,7 @@ ter_match::ter_match() :
|
|||
is_empty(true)
|
||||
{}
|
||||
|
||||
ter_match::ter_match(const std::string& str, const ter_layer filler) :
|
||||
ter_match::ter_match(utils::string_view str, const ter_layer filler) :
|
||||
terrain(t_translation::read_list(str, filler)),
|
||||
mask(),
|
||||
masked_terrain(),
|
||||
|
@ -199,7 +199,7 @@ ter_match::ter_match(const terrain_code& tcode):
|
|||
}
|
||||
}
|
||||
|
||||
terrain_code read_terrain_code(const std::string& str, const ter_layer filler)
|
||||
terrain_code read_terrain_code(utils::string_view str, const ter_layer filler)
|
||||
{
|
||||
return string_to_number_(str, filler);
|
||||
}
|
||||
|
@ -223,8 +223,8 @@ ter_list read_list(utils::string_view str, const ter_layer filler)
|
|||
|
||||
// Get a terrain chunk
|
||||
const std::string separators = ",";
|
||||
const std::size_t pos_separator = str.find_first_of(separators, offset);
|
||||
const std::string terrain = str.substr(offset, pos_separator - offset).to_string();
|
||||
const size_t pos_separator = str.find_first_of(separators, offset);
|
||||
utils::string_view terrain = str.substr(offset, pos_separator - offset);
|
||||
|
||||
// Process the chunk
|
||||
const terrain_code tile = string_to_number_(terrain, filler);
|
||||
|
@ -233,7 +233,7 @@ ter_list read_list(utils::string_view str, const ter_layer filler)
|
|||
result.push_back(tile);
|
||||
|
||||
// Evaluate the separator
|
||||
if(pos_separator == std::string::npos) {
|
||||
if(pos_separator == utils::string_view::npos) {
|
||||
offset = str.length();
|
||||
} else {
|
||||
offset = pos_separator + 1;
|
||||
|
@ -283,22 +283,22 @@ static std::pair<int, int> get_map_size(const char* begin, const char* end)
|
|||
return{ w, h };
|
||||
}
|
||||
|
||||
ter_map read_game_map(const std::string& str, starting_positions& starting_positions, coordinate border_offset)
|
||||
ter_map read_game_map(utils::string_view str, starting_positions& starting_positions, coordinate border_offset)
|
||||
{
|
||||
std::size_t offset = 0;
|
||||
int x = 0, y = 0, width = 0;
|
||||
|
||||
// Skip the leading newlines
|
||||
while(offset < str.length() && utils::isnewline(str[offset])) {
|
||||
++offset;
|
||||
while(!str.empty() && utils::isnewline(str.front())) {
|
||||
str.remove_prefix(1);
|
||||
}
|
||||
|
||||
// Did we get an empty map?
|
||||
if((offset + 1) >= str.length()) {
|
||||
if(str.length() <= 1) {
|
||||
return ter_map();
|
||||
}
|
||||
|
||||
auto map_size = get_map_size(&str[offset], str.c_str() + str.size());
|
||||
auto map_size = get_map_size(&str[0], &str[0] + str.size());
|
||||
ter_map result(map_size.first, map_size.second);
|
||||
|
||||
while(offset < str.length()) {
|
||||
|
@ -306,7 +306,7 @@ ter_map read_game_map(const std::string& 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);
|
||||
const std::string terrain = str.substr(offset, pos_separator - offset);
|
||||
utils::string_view terrain = str.substr(offset, pos_separator - offset);
|
||||
|
||||
// Process the chunk
|
||||
std::string starting_position;
|
||||
|
@ -728,14 +728,14 @@ static ter_layer string_to_layer_(const char* begin, const char* end)
|
|||
return result;
|
||||
}
|
||||
|
||||
static terrain_code string_to_number_(const std::string& str, const ter_layer filler) {
|
||||
static terrain_code string_to_number_(utils::string_view str, const ter_layer filler) {
|
||||
std::string dummy;
|
||||
return string_to_number_(str, dummy, filler);
|
||||
}
|
||||
|
||||
static terrain_code string_to_number_(std::string str, std::string& start_position, const ter_layer filler)
|
||||
static terrain_code string_to_number_(utils::string_view str, std::string& start_position, const ter_layer filler)
|
||||
{
|
||||
const char* c_str = str.c_str();
|
||||
const char* c_str = &str[0];
|
||||
terrain_code result;
|
||||
|
||||
// Strip the spaces around us
|
||||
|
@ -749,7 +749,7 @@ static terrain_code string_to_number_(std::string str, std::string& start_positi
|
|||
// Split if we have 1 space inside
|
||||
std::size_t offset = str.find(' ', begin);
|
||||
if(offset < end) {
|
||||
start_position = str.substr(begin, offset - begin);
|
||||
start_position = std::string(str.substr(begin, offset - begin));
|
||||
begin = offset + 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace t_translation {
|
|||
*/
|
||||
struct terrain_code {
|
||||
terrain_code(const std::string& b, const std::string& o);
|
||||
terrain_code(const std::string& b, ter_layer o = NO_LAYER);
|
||||
explicit terrain_code(const std::string& b, ter_layer o = NO_LAYER);
|
||||
terrain_code(ter_layer b, ter_layer o) : base(b), overlay(o) {}
|
||||
terrain_code() : base(0), overlay(NO_LAYER) {}
|
||||
|
||||
|
@ -104,7 +104,7 @@ namespace t_translation {
|
|||
*/
|
||||
struct ter_match{
|
||||
ter_match();
|
||||
ter_match(const std::string& str, const ter_layer filler = NO_LAYER);
|
||||
ter_match(utils::string_view str, const ter_layer filler = NO_LAYER);
|
||||
ter_match(const terrain_code& tcode);
|
||||
|
||||
ter_list terrain;
|
||||
|
@ -182,7 +182,7 @@ namespace t_translation {
|
|||
*
|
||||
* @return A single terrain code
|
||||
*/
|
||||
terrain_code read_terrain_code(const std::string& str, const ter_layer filler = NO_LAYER);
|
||||
terrain_code read_terrain_code(utils::string_view, const ter_layer filler = NO_LAYER);
|
||||
|
||||
/**
|
||||
* Writes a single terrain code to a string.
|
||||
|
@ -249,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(const std::string& str, starting_positions& positions, coordinate border_offset = coordinate{ 0, 0 });
|
||||
ter_map read_game_map(utils::string_view, starting_positions& positions, coordinate border_offset = coordinate{ 0, 0 });
|
||||
|
||||
/**
|
||||
* Write a gamemap in to a vector string.
|
||||
|
|
Loading…
Add table
Reference in a new issue