diff options
| author | Jan Lingscheid <jan.linscheid@auticon.de> | 2017-09-12 12:38:29 +0000 |
|---|---|---|
| committer | Jan Lingscheid <jan.lingscheid@auticon.de> | 2017-09-21 05:46:27 +0000 |
| commit | 7c5cc63b4d74331cb5ba71faea2d4c1ac8dcae66 (patch) | |
| tree | 6b4a4923b3c176d9e3cd03ff22892b8a5ba9d802 /src | |
| parent | Remove usage of GString in sp-style-elem.cpp (diff) | |
| download | inkscape-7c5cc63b4d74331cb5ba71faea2d4c1ac8dcae66.tar.gz inkscape-7c5cc63b4d74331cb5ba71faea2d4c1ac8dcae66.zip | |
Remove usage of GString in sp-object.cpp
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp-object.cpp | 17 | ||||
| -rw-r--r-- | src/sp-object.h | 2 |
2 files changed, 10 insertions, 9 deletions
diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 9f15935ac..fc222f701 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1540,7 +1540,10 @@ char * SPObject::getTitleOrDesc(gchar const *svg_tagname) const char *result = NULL; SPObject *elem = findFirstChild(svg_tagname); if ( elem ) { - result = elem->textualContent(); + //This string copy could be avoided by changing + //the return type of SPObject::getTitleOrDesc + //to std::unique_ptr<Glib::ustring> + result = g_strdup(elem->textualContent().c_str()); } return result; } @@ -1625,24 +1628,22 @@ SPObject* SPObject::findFirstChild(gchar const *tagname) const return nullptr; } -char* SPObject::textualContent() const +Glib::ustring SPObject::textualContent() const { - GString* text = g_string_new(""); + Glib::ustring text; for (auto& child: children) { Inkscape::XML::NodeType child_type = child.repr->type(); if (child_type == Inkscape::XML::ELEMENT_NODE) { - char* new_string = child.textualContent(); - g_string_append(text, new_string); - g_free(new_string); + text += child.textualContent(); } else if (child_type == Inkscape::XML::TEXT_NODE) { - g_string_append(text, child.repr->content()); + text += child.repr->content(); } } - return g_string_free(text, FALSE); + return text; } // For debugging: Print SP tree structure. diff --git a/src/sp-object.h b/src/sp-object.h index d145e966b..08e69f771 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -803,7 +803,7 @@ private: * content except the tags). * Must not be used on anything except elements. */ - char * textualContent() const; + Glib::ustring textualContent() const; /* Real handlers of repr signals */ |
