Code

Fix for delete[] and binary comment
[inkscape.git] / src / extension / internal / svg.cpp
index e6d02b62dbf5db759328d644dcaa2135267f4398..ab9c59830f99df36bf2cf958884af4ec25c25e5d 100644 (file)
@@ -20,6 +20,7 @@
 #include "file.h"
 #include "extension/system.h"
 #include "extension/output.h"
+#include <vector>
 
 #ifdef WITH_GNOME_VFS
 # include <libgnomevfs/gnome-vfs.h>
@@ -29,6 +30,8 @@ namespace Inkscape {
 namespace Extension {
 namespace Internal {
 
+#include "clear-n_.h"
+
 /**
     \return   None
     \brief    What would an SVG editor be without loading/saving SVG
@@ -49,13 +52,13 @@ Svg::init(void)
     /* SVG in */
     ext = Inkscape::Extension::build_from_mem(
         "<inkscape-extension>\n"
-            "<name>SVG Input</name>\n"
+            "<name>" N_("SVG Input") "</name>\n"
             "<id>" SP_MODULE_KEY_INPUT_SVG "</id>\n"
             "<input>\n"
                 "<extension>.svg</extension>\n"
                 "<mimetype>image/x-svg</mimetype>\n"
-                "<filetypename>Scalable Vector Graphic (*.svg)</filetypename>\n"
-                "<filetypetooltip>Inkscape native file format and W3C standard</filetypetooltip>\n"
+                "<filetypename>" N_("Scalable Vector Graphic (*.svg)") "</filetypename>\n"
+                "<filetypetooltip>" N_("Inkscape native file format and W3C standard") "</filetypetooltip>\n"
                 "<output_extension>" SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "</output_extension>\n"
             "</input>\n"
         "</inkscape-extension>", new Svg());
@@ -63,13 +66,13 @@ Svg::init(void)
     /* SVG out Inkscape */
     ext = Inkscape::Extension::build_from_mem(
         "<inkscape-extension>\n"
-            "<name>SVG Output Inkscape</name>\n"
+            "<name>" N_("SVG Output Inkscape") "</name>\n"
             "<id>" SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "</id>\n"
             "<output>\n"
                 "<extension>.svg</extension>\n"
                 "<mimetype>image/x-svg</mimetype>\n"
-                "<filetypename>Inkscape SVG (*.svg)</filetypename>\n"
-                "<filetypetooltip>SVG format with Inkscape extensions</filetypetooltip>\n"
+                "<filetypename>" N_("Inkscape SVG (*.svg)") "</filetypename>\n"
+                "<filetypetooltip>" N_("SVG format with Inkscape extensions") "</filetypetooltip>\n"
                 "<dataloss>FALSE</dataloss>\n"
             "</output>\n"
         "</inkscape-extension>", new Svg());
@@ -77,13 +80,13 @@ Svg::init(void)
     /* SVG out */
     ext = Inkscape::Extension::build_from_mem(
         "<inkscape-extension>\n"
-            "<name>SVG Output</name>\n"
+            "<name>" N_("SVG Output") "</name>\n"
             "<id>" SP_MODULE_KEY_OUTPUT_SVG "</id>\n"
             "<output>\n"
                 "<extension>.svg</extension>\n"
                 "<mimetype>image/x-svg</mimetype>\n"
-                "<filetypename>Plain SVG (*.svg)</filetypename>\n"
-                "<filetypetooltip>Scalable Vector Graphics format as defined by the W3C</filetypetooltip>\n"
+                "<filetypename>" N_("Plain SVG (*.svg)") "</filetypename>\n"
+                "<filetypetooltip>" N_("Scalable Vector Graphics format as defined by the W3C") "</filetypetooltip>\n"
             "</output>\n"
         "</inkscape-extension>", new Svg());
 
@@ -104,9 +107,6 @@ _load_uri (const gchar *uri)
 {
     GnomeVFSHandle   *handle = NULL;
     GnomeVFSFileSize  bytes_read;
-    gchar             buffer[BUF_SIZE] = "";
-    gchar            *doc = NULL;
-    gchar            *new_doc = NULL;
 
         gsize bytesRead = 0;
         gsize bytesWritten = 0;
@@ -123,20 +123,14 @@ _load_uri (const gchar *uri)
         g_warning(gnome_vfs_result_to_string(result));
     }
 
+    std::vector<gchar> doc;
     while (result == GNOME_VFS_OK) {
+        gchar buffer[BUF_SIZE];
         result = gnome_vfs_read (handle, buffer, BUF_SIZE, &bytes_read);
-        buffer[bytes_read] = '\0';
-
-        if (doc == NULL) {
-            doc = g_strndup(buffer, bytes_read);
-        } else {
-            new_doc = g_strconcat(doc, buffer, NULL);
-            g_free(doc);
-            doc = new_doc;
-        }
+        doc.insert(doc.end(), buffer, buffer+bytes_read);
     }
 
-    return doc;
+    return g_strndup(&doc[0], doc.size());
 }
 #endif