From 0021ccef59c633481bb2e81d9d12d3b5ee440c41 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 30 Oct 2022 13:59:59 +0100 Subject: [PATCH] Replace boost::string_ref with std::string_view --- include/engine/api/base_api.hpp | 6 +-- include/engine/guidance/assemble_leg.hpp | 4 +- include/engine/guidance/assemble_steps.hpp | 40 ++++++++++---------- include/util/guidance/name_announcements.hpp | 5 ++- include/util/string_view.hpp | 4 +- src/engine/plugins/tile.cpp | 6 +-- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/include/engine/api/base_api.hpp b/include/engine/api/base_api.hpp index 086c787de..9e43d311c 100644 --- a/include/engine/api/base_api.hpp +++ b/include/engine/api/base_api.hpp @@ -57,8 +57,7 @@ class BaseAPI { // TODO: check forward/reverse const auto toName = [this](const auto &phantom) { - return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)) - .to_string(); + return std::string(facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))); }; const auto noEmpty = [](const auto &name) { return !name.empty(); }; @@ -128,8 +127,7 @@ class BaseAPI static_cast(static_cast(util::toFloating(snapped_location.lat)))); const auto toName = [this](const auto &phantom) { - return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)) - .to_string(); + return std::string(facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))); }; const auto noEmpty = [](const auto &name) { return !name.empty(); }; diff --git a/include/engine/guidance/assemble_leg.hpp b/include/engine/guidance/assemble_leg.hpp index 19e7ebffe..595f09b99 100644 --- a/include/engine/guidance/assemble_leg.hpp +++ b/include/engine/guidance/assemble_leg.hpp @@ -145,11 +145,11 @@ inline std::string assembleSummary(const datafacade::BaseDataFacade &facade, const auto name_id_to_string = [&](const NameID name_id) { const auto name = facade.GetNameForID(name_id); if (!name.empty()) - return name.to_string(); + return std::string(name); else { const auto ref = facade.GetRefForID(name_id); - return ref.to_string(); + return std::string(ref); } }; diff --git a/include/engine/guidance/assemble_steps.hpp b/include/engine/guidance/assemble_steps.hpp index 18e09d972..2f1b06924 100644 --- a/include/engine/guidance/assemble_steps.hpp +++ b/include/engine/guidance/assemble_steps.hpp @@ -140,11 +140,11 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa steps.push_back(RouteStep{path_point.from_edge_based_node, step_name_id, is_segregated, - name.to_string(), - ref.to_string(), - pronunciation.to_string(), - destinations.to_string(), - exits.to_string(), + std::string(name), + std::string(ref), + std::string(pronunciation), + std::string(destinations), + std::string(exits), NO_ROTARY_NAME, NO_ROTARY_NAME, from_alias(segment_duration) / 10., @@ -241,11 +241,11 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa steps.push_back(RouteStep{leg_data[leg_data.size() - 1].from_edge_based_node, step_name_id, is_segregated, - facade.GetNameForID(step_name_id).to_string(), - facade.GetRefForID(step_name_id).to_string(), - facade.GetPronunciationForID(step_name_id).to_string(), - facade.GetDestinationsForID(step_name_id).to_string(), - facade.GetExitsForID(step_name_id).to_string(), + std::string(facade.GetNameForID(step_name_id)), + std::string(facade.GetRefForID(step_name_id)), + std::string(facade.GetPronunciationForID(step_name_id)), + std::string(facade.GetDestinationsForID(step_name_id)), + std::string(facade.GetExitsForID(step_name_id)), NO_ROTARY_NAME, NO_ROTARY_NAME, from_alias(duration) / 10., @@ -287,11 +287,11 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa steps.push_back(RouteStep{source_node_id, source_name_id, is_segregated, - facade.GetNameForID(source_name_id).to_string(), - facade.GetRefForID(source_name_id).to_string(), - facade.GetPronunciationForID(source_name_id).to_string(), - facade.GetDestinationsForID(source_name_id).to_string(), - facade.GetExitsForID(source_name_id).to_string(), + std::string(facade.GetNameForID(source_name_id)), + std::string(facade.GetRefForID(source_name_id)), + std::string(facade.GetPronunciationForID(source_name_id)), + std::string(facade.GetDestinationsForID(source_name_id)), + std::string(facade.GetExitsForID(source_name_id)), NO_ROTARY_NAME, NO_ROTARY_NAME, from_alias(duration) / 10., @@ -330,11 +330,11 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa steps.push_back(RouteStep{target_node_id, target_name_id, facade.IsSegregated(target_node_id), - facade.GetNameForID(target_name_id).to_string(), - facade.GetRefForID(target_name_id).to_string(), - facade.GetPronunciationForID(target_name_id).to_string(), - facade.GetDestinationsForID(target_name_id).to_string(), - facade.GetExitsForID(target_name_id).to_string(), + std::string(facade.GetNameForID(target_name_id)), + std::string(facade.GetRefForID(target_name_id)), + std::string(facade.GetPronunciationForID(target_name_id)), + std::string(facade.GetDestinationsForID(target_name_id)), + std::string(facade.GetExitsForID(target_name_id)), NO_ROTARY_NAME, NO_ROTARY_NAME, ZERO_DURATION, diff --git a/include/util/guidance/name_announcements.hpp b/include/util/guidance/name_announcements.hpp index fa8f9db43..2b2b3794b 100644 --- a/include/util/guidance/name_announcements.hpp +++ b/include/util/guidance/name_announcements.hpp @@ -70,7 +70,10 @@ template inline auto decompose(const StringView &lhs, cons const auto trim = [](StringView view) { // we compare suffixes based on this value, it might break UTF chars, but as long as we are // consistent in handling, we do not create bad results - std::string str = boost::to_lower_copy(view.to_string()); + std::string str(view); + std::transform(str.begin(), str.end(), str.begin(), + [](unsigned char c){ return std::tolower(c); } // correct + ); auto front = str.find_first_not_of(' '); if (front == std::string::npos) diff --git a/include/util/string_view.hpp b/include/util/string_view.hpp index c7ab0df3d..d1cf4cb96 100644 --- a/include/util/string_view.hpp +++ b/include/util/string_view.hpp @@ -2,14 +2,14 @@ #define OSRM_STRING_VIEW_HPP #include -#include +#include namespace osrm { namespace util { // Convenience typedef: boost::string_ref, boost::string_view or C++17's string_view -using StringView = boost::string_ref; +using StringView = std::string_view; } // namespace util } // namespace osrm diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index f932abe73..d69dacec5 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -340,7 +340,7 @@ class SpeedLayerFeatureBuilder : public vtzero::linestring_feature_builder add_property(m_layer.key_duration, m_layer.double_index(value)); } - void set_name(const boost::string_ref &value) + void set_name(const std::string_view value) { add_property( m_layer.key_name, @@ -518,7 +518,7 @@ void encodeVectorTile(const DataFacadeBase &facade, fbuilder.set_speed(speed_kmh_idx); fbuilder.set_is_small(component_id.is_tiny); fbuilder.set_datasource( - facade.GetDatasourceName(forward_datasource_idx).to_string()); + std::string(facade.GetDatasourceName(forward_datasource_idx))); fbuilder.set_weight(from_alias(forward_weight) / 10.0); fbuilder.set_duration(from_alias(forward_duration) / 10.0); fbuilder.set_name(name); @@ -552,7 +552,7 @@ void encodeVectorTile(const DataFacadeBase &facade, fbuilder.set_speed(speed_kmh_idx); fbuilder.set_is_small(component_id.is_tiny); fbuilder.set_datasource( - facade.GetDatasourceName(reverse_datasource_idx).to_string()); + std::string(facade.GetDatasourceName(reverse_datasource_idx))); fbuilder.set_weight(from_alias(reverse_weight) / 10.0); fbuilder.set_duration(from_alias(reverse_duration) / 10.0); fbuilder.set_name(name);