diff --git a/source/blender/blenkernel/intern/bake_items_serialize.cc b/source/blender/blenkernel/intern/bake_items_serialize.cc index 5c7caac23d6..2db47a84c0d 100644 --- a/source/blender/blenkernel/intern/bake_items_serialize.cc +++ b/source/blender/blenkernel/intern/bake_items_serialize.cc @@ -134,7 +134,7 @@ BlobSlice DiskBlobWriter::write_as_stream(const StringRef file_extension, BLI_assert(file_extension.startswith(".")); independent_file_count_++; const std::string file_name = fmt::format( - "{}_file_{}{}", base_name_, independent_file_count_, std::string_view(file_extension)); + "{}_file_{}{}", base_name_, independent_file_count_, file_extension); char path[FILE_MAX]; BLI_path_join(path, sizeof(path), blob_dir_.c_str(), file_name.c_str()); diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh index c2ce0711516..35d11cb3f2b 100644 --- a/source/blender/blenlib/BLI_string_ref.hh +++ b/source/blender/blenlib/BLI_string_ref.hh @@ -621,4 +621,18 @@ constexpr bool operator>=(StringRef a, StringRef b) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Formatting + * \{ */ + +/** + * Support using the fmt library with #StringRef and implicitly also #StringRefNull. + */ +inline std::string_view format_as(StringRef str) +{ + return str; +} + +/** \} */ + } // namespace blender diff --git a/source/blender/blenlib/intern/timeit.cc b/source/blender/blenlib/intern/timeit.cc index 6907b214da2..61779c00a2d 100644 --- a/source/blender/blenlib/intern/timeit.cc +++ b/source/blender/blenlib/intern/timeit.cc @@ -2,12 +2,12 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ +#include "BLI_string_ref.hh" #include "BLI_timeit.hh" #include #include #include -#include #include @@ -43,7 +43,7 @@ void print_duration(Nanoseconds duration) { fmt::memory_buffer buf; format_duration(duration, buf); - std::cout << std::string_view(buf.data(), buf.size()); + std::cout << StringRef(buf.data(), buf.size()); } ScopedTimer::~ScopedTimer() @@ -54,8 +54,8 @@ ScopedTimer::~ScopedTimer() fmt::memory_buffer buf; fmt::format_to(fmt::appender(buf), FMT_STRING("Timer '{}' took "), name_); format_duration(duration, buf); - buf.append(std::string_view("\n")); - std::cout << std::string_view(buf.data(), buf.size()); + buf.append(StringRef("\n")); + std::cout << StringRef(buf.data(), buf.size()); } ScopedTimerAveraged::~ScopedTimerAveraged() @@ -70,12 +70,12 @@ ScopedTimerAveraged::~ScopedTimerAveraged() fmt::memory_buffer buf; fmt::format_to(fmt::appender(buf), FMT_STRING("Timer '{}': (Average: "), name_); format_duration(total_time_ / total_count_, buf); - buf.append(std::string_view(", Min: ")); + buf.append(StringRef(", Min: ")); format_duration(min_time_, buf); - buf.append(std::string_view(", Last: ")); + buf.append(StringRef(", Last: ")); format_duration(duration, buf); - buf.append(std::string_view(")\n")); - std::cout << std::string_view(buf.data(), buf.size()); + buf.append(StringRef(")\n")); + std::cout << StringRef(buf.data(), buf.size()); } } // namespace blender::timeit diff --git a/source/blender/editors/interface/interface_template_bone_collection_tree.cc b/source/blender/editors/interface/interface_template_bone_collection_tree.cc index 38f28d97175..0ae7b26570c 100644 --- a/source/blender/editors/interface/interface_template_bone_collection_tree.cc +++ b/source/blender/editors/interface/interface_template_bone_collection_tree.cc @@ -131,8 +131,8 @@ class BoneCollectionDropTarget : public TreeViewItemDropTarget { const BoneCollection &drag_bcoll = drag_bone_collection->bcoll(); const BoneCollection &drop_bcoll = drop_bonecoll_.bcoll(); - std::string_view drag_name = drag_bcoll.name; - std::string_view drop_name = drop_bcoll.name; + const StringRef drag_name = drag_bcoll.name; + const StringRef drop_name = drop_bcoll.name; switch (drag_info.drop_location) { case DropLocation::Into: diff --git a/source/blender/editors/interface/interface_template_grease_pencil_layer_tree.cc b/source/blender/editors/interface/interface_template_grease_pencil_layer_tree.cc index 2a7d635525c..b585a77e3a9 100644 --- a/source/blender/editors/interface/interface_template_grease_pencil_layer_tree.cc +++ b/source/blender/editors/interface/interface_template_grease_pencil_layer_tree.cc @@ -60,8 +60,8 @@ class LayerNodeDropTarget : public TreeViewItemDropTarget { static_cast(drag_info.drag_data.poin); Layer &drag_layer = drag_grease_pencil->layer->wrap(); - std::string_view drag_name = drag_layer.name(); - std::string_view drop_name = drop_tree_node_.name(); + const StringRef drag_name = drag_layer.name(); + const StringRef drop_name = drop_tree_node_.name(); switch (drag_info.drop_location) { case DropLocation::Into: diff --git a/source/blender/editors/interface/interface_template_light_linking.cc b/source/blender/editors/interface/interface_template_light_linking.cc index 7a3cae871d5..625cd4cec82 100644 --- a/source/blender/editors/interface/interface_template_light_linking.cc +++ b/source/blender/editors/interface/interface_template_light_linking.cc @@ -133,7 +133,7 @@ class ReorderCollectionDropTarget : public TreeViewItemDropTarget { std::string drop_tooltip(const DragInfo &drag) const override { - const std::string_view drop_name = std::string_view(drop_id_.name + 2); + const StringRef drop_name = drop_id_.name + 2; switch (drag.drop_location) { case DropLocation::Into: diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc index 18bba522a8a..555fe12b36f 100644 --- a/source/blender/editors/space_file/asset_catalog_tree_view.cc +++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc @@ -406,9 +406,8 @@ std::string AssetCatalogDropTarget::drop_tooltip_asset_catalog(const wmDrag &dra BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); const AssetCatalog *src_catalog = get_drag_catalog(drag, get_asset_library()); - return fmt::format(TIP_("Move catalog {} into {}"), - std::string_view(src_catalog->path.name()), - std::string_view(catalog_item_.get_name())); + return fmt::format( + TIP_("Move catalog {} into {}"), src_catalog->path.name(), catalog_item_.get_name()); } std::string AssetCatalogDropTarget::drop_tooltip_asset_list(const wmDrag &drag) const @@ -623,7 +622,7 @@ std::string AssetCatalogTreeViewAllItem::DropTarget::drop_tooltip( drag_info.drag_data, *get_view().asset_library_); return fmt::format(TIP_("Move catalog {} to the top level of the tree"), - std::string_view(drag_catalog->path.name())); + drag_catalog->path.name()); } bool AssetCatalogTreeViewAllItem::DropTarget::on_drop(bContext * /*C*/, diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 2e37bfed227..53ef7219c7b 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2524,7 +2524,7 @@ static std::string named_attribute_tooltip(bContext * /*C*/, void *argN, const c for (const NameWithUsage &attribute : sorted_used_attribute) { const StringRefNull name = attribute.name; const geo_log::NamedAttributeUsage usage = attribute.usage; - ss << fmt::format(TIP_(" \u2022 \"{}\": "), std::string_view(name)); + ss << fmt::format(TIP_(" \u2022 \"{}\": "), name); Vector usages; if ((usage & geo_log::NamedAttributeUsage::Read) != geo_log::NamedAttributeUsage::None) { usages.append(TIP_("read")); diff --git a/source/blender/io/ply/exporter/ply_file_buffer.cc b/source/blender/io/ply/exporter/ply_file_buffer.cc index 332e9595246..3889f8a84cb 100644 --- a/source/blender/io/ply/exporter/ply_file_buffer.cc +++ b/source/blender/io/ply/exporter/ply_file_buffer.cc @@ -44,26 +44,23 @@ void FileBuffer::close_file() void FileBuffer::write_header_element(StringRef name, int count) { - write_fstring("element {} {}\n", std::string_view(name), count); + write_fstring("element {} {}\n", name, count); } void FileBuffer::write_header_scalar_property(StringRef dataType, StringRef name) { - write_fstring("property {} {}\n", std::string_view(dataType), std::string_view(name)); + write_fstring("property {} {}\n", dataType, name); } void FileBuffer::write_header_list_property(StringRef countType, StringRef dataType, StringRef name) { - write_fstring("property list {} {} {}\n", - std::string_view(countType), - std::string_view(dataType), - std::string_view(name)); + write_fstring("property list {} {} {}\n", countType, dataType, name); } void FileBuffer::write_string(StringRef s) { - write_fstring("{}\n", std::string_view(s)); + write_fstring("{}\n", s); } void FileBuffer::write_newline() diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh index ab81d4be416..a9b658a404c 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh @@ -111,11 +111,11 @@ class FormatHandler : NonCopyable, NonMovable { } void write_obj_usemtl(StringRef s) { - write_impl("usemtl {}\n", std::string_view(s)); + write_impl("usemtl {}\n", s); } void write_obj_mtllib(StringRef s) { - write_impl("mtllib {}\n", std::string_view(s)); + write_impl("mtllib {}\n", s); } void write_obj_smooth(int s) { @@ -123,11 +123,11 @@ class FormatHandler : NonCopyable, NonMovable { } void write_obj_group(StringRef s) { - write_impl("g {}\n", std::string_view(s)); + write_impl("g {}\n", s); } void write_obj_object(StringRef s) { - write_impl("o {}\n", std::string_view(s)); + write_impl("o {}\n", s); } void write_obj_edge(int a, int b) { @@ -172,7 +172,7 @@ class FormatHandler : NonCopyable, NonMovable { void write_mtl_newmtl(StringRef s) { - write_impl("newmtl {}\n", std::string_view(s)); + write_impl("newmtl {}\n", s); } void write_mtl_float(const char *type, float v) { @@ -189,12 +189,12 @@ class FormatHandler : NonCopyable, NonMovable { /* NOTE: options, if present, will have its own leading space. */ void write_mtl_map(const char *type, StringRef options, StringRef value) { - write_impl("{}{} {}\n", type, std::string_view(options), std::string_view(value)); + write_impl("{}{} {}\n", type, options, value); } void write_string(StringRef s) { - write_impl("{}\n", std::string_view(s)); + write_impl("{}\n", s); } private: diff --git a/source/blender/makesrna/intern/rna_path.cc b/source/blender/makesrna/intern/rna_path.cc index 28f52a2b7e1..512a766be39 100644 --- a/source/blender/makesrna/intern/rna_path.cc +++ b/source/blender/makesrna/intern/rna_path.cc @@ -978,7 +978,7 @@ static std::optional rna_prepend_real_ID_path(Main * /*bmain*/, if (!path.is_empty()) { if (real_id) { if (prefix[0]) { - return fmt::format("{}{}{}", prefix, path[0] == '[' ? "" : ".", std::string_view(path)); + return fmt::format("{}{}{}", prefix, path[0] == '[' ? "" : ".", path); } return path; } @@ -1105,11 +1105,11 @@ static std::string rna_path_from_ptr_to_property_index_ex(const PointerRNA *ptr, if (!path_prefix.is_empty()) { if (is_rna) { - return fmt::format("{}.{}{}", std::string_view(path_prefix), propname, index_str); + return fmt::format("{}.{}{}", path_prefix, propname, index_str); } char propname_esc[MAX_IDPROP_NAME * 2]; BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); - return fmt::format("{}[\"{}\"]{}", std::string_view(path_prefix), propname_esc, index_str); + return fmt::format("{}[\"{}\"]{}", path_prefix, propname_esc, index_str); } if (is_rna) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc index d3b418af6d5..1c7ae47d269 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc @@ -274,14 +274,14 @@ static void node_geo_exec(GeoNodeExecParams params) if (!mesh_attributes_eval.contains(uv_map_name)) { pass_through_input(); const std::string message = fmt::format(TIP_("Evaluated surface missing UV map: \"{}\""), - std::string_view(uv_map_name)); + uv_map_name); params.error_message_add(NodeWarningType::Error, message); return; } if (!mesh_attributes_orig.contains(uv_map_name)) { pass_through_input(); const std::string message = fmt::format(TIP_("Original surface missing UV map: \"{}\""), - std::string_view(uv_map_name)); + uv_map_name); params.error_message_add(NodeWarningType::Error, message); return; } diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc index 6a84cd76117..2f88e7bd5fd 100644 --- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc +++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc @@ -345,7 +345,7 @@ class LazyFunctionForGeometryNode : public LazyFunction { GField output_field{std::make_shared( std::move(attribute_id), *bsocket.typeinfo->base_cpp_type, - fmt::format(TIP_("{} node"), std::string_view(node_.label_or_name())))}; + fmt::format(TIP_("{} node"), node_.label_or_name()))}; void *r_value = params.get_output_data_ptr(lf_index); new (r_value) SocketValueVariant(std::move(output_field)); params.output_set(lf_index);