Cleanup: avoid constructing std::string from nullptr
This probably never in practice in these cases. Constructing a `std::string` from nullptr is invalid. Starting with C++23, the `nullptr_t` is even explicitly deleted.
This commit is contained in:
@@ -1958,7 +1958,7 @@ void BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src)
|
||||
std::optional<std::string> BKE_keyblock_curval_rnapath_get(const Key *key, const KeyBlock *kb)
|
||||
{
|
||||
if (ELEM(nullptr, key, kb)) {
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
PointerRNA ptr = RNA_pointer_create((ID *)&key->id, &RNA_ShapeKey, (KeyBlock *)kb);
|
||||
PropertyRNA *prop = RNA_struct_find_property(&ptr, "value");
|
||||
|
||||
@@ -231,14 +231,15 @@ static const char *node_socket_get_translation_context(const bNodeSocket &socket
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
blender::StringRefNull translation_context = socket.runtime->declaration->translation_context;
|
||||
const std::optional<std::string> &translation_context =
|
||||
socket.runtime->declaration->translation_context;
|
||||
|
||||
/* Default context. */
|
||||
if (translation_context.is_empty()) {
|
||||
if (!translation_context.has_value()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return translation_context.data();
|
||||
return translation_context->c_str();
|
||||
}
|
||||
|
||||
static void node_socket_add_tooltip_in_node_editor(const bNodeSocket &sock, uiLayout &layout);
|
||||
|
||||
@@ -173,7 +173,7 @@ class SocketDeclaration : public ItemDeclaration {
|
||||
std::string short_label;
|
||||
std::string identifier;
|
||||
std::string description;
|
||||
std::string translation_context;
|
||||
std::optional<std::string> translation_context;
|
||||
/** Defined by whether the socket is part of the node's input or
|
||||
* output socket declaration list. Included here for convenience. */
|
||||
eNodeSocketInOut in_out;
|
||||
@@ -284,7 +284,8 @@ class BaseSocketDeclarationBuilder {
|
||||
|
||||
BaseSocketDeclarationBuilder &description(std::string value = "");
|
||||
|
||||
BaseSocketDeclarationBuilder &translation_context(std::string value = BLT_I18NCONTEXT_DEFAULT);
|
||||
BaseSocketDeclarationBuilder &translation_context(
|
||||
std::optional<std::string> value = std::nullopt);
|
||||
|
||||
BaseSocketDeclarationBuilder &no_muted_links(bool value = true);
|
||||
|
||||
@@ -437,7 +438,7 @@ class PanelDeclaration : public ItemDeclaration {
|
||||
int identifier;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string translation_context;
|
||||
std::optional<std::string> translation_context;
|
||||
bool default_collapsed = false;
|
||||
Vector<ItemDeclaration *> items;
|
||||
/** Index in the list of panels on the node. */
|
||||
|
||||
@@ -586,7 +586,8 @@ BaseSocketDeclarationBuilder &BaseSocketDeclarationBuilder::description(std::str
|
||||
return *this;
|
||||
}
|
||||
|
||||
BaseSocketDeclarationBuilder &BaseSocketDeclarationBuilder::translation_context(std::string value)
|
||||
BaseSocketDeclarationBuilder &BaseSocketDeclarationBuilder::translation_context(
|
||||
std::optional<std::string> value)
|
||||
{
|
||||
decl_base_->translation_context = std::move(value);
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user