Use filename_extension() and filename_sans_extension().
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sun, 14 Oct 2007 22:14:47 +0000 (22:14 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sun, 14 Oct 2007 22:14:47 +0000 (22:14 +0000)
git-svn-id: http://svn.voria.com/code@929 1f10aa63-cdf2-0310-b900-c93c546f37ac

12 files changed:
synfig-core/trunk/src/modules/mod_bmp/trgt_bmp.cpp
synfig-core/trunk/src/modules/mod_imagemagick/trgt_imagemagick.cpp
synfig-core/trunk/src/modules/mod_jpeg/trgt_jpeg.cpp
synfig-core/trunk/src/modules/mod_openexr/trgt_openexr.cpp
synfig-core/trunk/src/modules/mod_png/trgt_png.cpp
synfig-core/trunk/src/modules/mod_ppm/trgt_ppm.cpp
synfig-core/trunk/src/synfig/importer.cpp
synfig-core/trunk/src/synfig/savecanvas.cpp
synfig-studio/trunk/src/gtkmm/canvasview.cpp
synfig-studio/trunk/src/gtkmm/instance.cpp
synfig-studio/trunk/src/gtkmm/render.cpp
synfig-studio/trunk/src/synfigapp/canvasinterface.cpp

index ee9f7c7..cb51db2 100644 (file)
@@ -175,12 +175,9 @@ bmp::start_frame(synfig::ProgressCallback *callback)
        rowspan=4*((w*(channels(pf)*8)+31)/32);
        if(multi_image)
        {
-               String
-                       newfilename(filename),
-                       ext(find(filename.begin(),filename.end(),'.'),filename.end());
-               newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
-
-               newfilename+=etl::strprintf("%04d",imagecount)+ext;
+               String newfilename(filename_sans_extension(filename) +
+                                                  etl::strprintf("%04d",imagecount) +
+                                                  filename_extension(filename));
                file=fopen(newfilename.c_str(),"wb");
                if(callback)callback->task(newfilename+_(" (animated)"));
        }
index 0d0cdff..123640b 100644 (file)
@@ -80,8 +80,7 @@ imagemagick_trgt::~imagemagick_trgt()
 bool
 imagemagick_trgt::set_rend_desc(RendDesc *given_desc)
 {
-       String  ext(find(filename.begin(),filename.end(),'.')+1,filename.end());
-       if(ext=="xpm")
+       if(filename_extension(filename) == ".xpm")
                pf=PF_RGB;
        else
                pf=PF_RGB|PF_A;
index fc6557e..013a99a 100644 (file)
@@ -109,12 +109,9 @@ jpeg_trgt::start_frame(synfig::ProgressCallback *callback)
        }
        else if(multi_image)
        {
-               String
-                       newfilename(filename),
-                       ext(find(filename.begin(),filename.end(),'.'),filename.end());
-               newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
-
-               newfilename+=etl::strprintf("%04d",imagecount)+ext;
+               String newfilename(filename_sans_extension(filename) +
+                                                  etl::strprintf("%04d",imagecount) +
+                                                  filename_extension(filename));
                file=fopen(newfilename.c_str(),"wb");
                if(callback)callback->task(newfilename);
        }
index 9142b1d..3cb0a46 100644 (file)
@@ -113,14 +113,10 @@ exr_trgt::start_frame(synfig::ProgressCallback *cb)
                delete exr_file;
        if(multi_image)
        {
-               String
-                       newfilename(filename),
-                       ext(find(filename.begin(),filename.end(),'.'),filename.end());
-               newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
-
-               newfilename+=etl::strprintf("%04d",imagecount)+ext;
-               frame_name=newfilename;
-               if(cb)cb->task(newfilename);
+               frame_name = (filename_sans_extension(filename) +
+                                         etl::strprintf("%04d",imagecount) +
+                                         filename_extension(filename));
+               if(cb)cb->task(frame_name);
        }
        else
        {
index 09c2152..dcaa538 100644 (file)
@@ -140,12 +140,9 @@ png_trgt::start_frame(synfig::ProgressCallback *callback)
        }
        else if(multi_image)
        {
-               String
-                       newfilename(filename),
-                       ext(find(filename.begin(),filename.end(),'.'),filename.end());
-               newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
-
-               newfilename+=etl::strprintf("%04d",imagecount)+ext;
+               String newfilename(filename_sans_extension(filename) +
+                                                  etl::strprintf("%04d",imagecount) +
+                                                  filename_extension(filename));
                file=fopen(newfilename.c_str(),"wb");
                if(callback)callback->task(newfilename);
        }
index 6484152..effe64d 100644 (file)
@@ -103,12 +103,9 @@ ppm::start_frame(synfig::ProgressCallback *callback)
        }
        else if(multi_image)
        {
-               String
-                       newfilename(filename),
-                       ext(find(filename.begin(),filename.end(),'.'),filename.end());
-               newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
-
-               newfilename+=etl::strprintf("%04d",imagecount)+ext;
+               String newfilename(filename_sans_extension(filename) +
+                                                  etl::strprintf("%04d",imagecount) +
+                                                  filename_extension(filename));
                file=SmartFILE(fopen(newfilename.c_str(),"wb"));
                if(callback)callback->task(newfilename);
        }
index 524eea3..120079f 100644 (file)
@@ -97,13 +97,14 @@ Importer::open(const String &filename)
                return (*__open_importers)[filename];
        }
 
-       if(find(filename.begin(),filename.end(),'.')==filename.end())
+       if(filename_extension(filename) == "")
        {
                synfig::error(_("Importer::open(): Couldn't find extension"));
                return 0;
        }
 
-       String ext=string(filename.begin()+filename.find_last_of('.')+1,filename.end());
+       String ext(filename_extension(filename));
+       if (ext.size()) ext = ext.substr(1); // skip initial '.'
        std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
 
 
index 4f37a25..8ccb099 100644 (file)
@@ -752,7 +752,7 @@ synfig::save_canvas(const String &filename, Canvas::ConstHandle canvas)
 
        synfig::String tmp_filename(filename+".TMP");
 
-       if (String(filename.begin() + filename.find_last_of('.')+1, filename.end()) == "sifz")
+       if (filename_extension(filename) == ".sifz")
                xmlSetCompressMode(9);
        else
                xmlSetCompressMode(0);
index b6e093e..87c58a5 100644 (file)
@@ -3137,8 +3137,8 @@ CanvasView::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& con
                                // Strip the "file://" part from the filename
                                filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
 
-                               String ext;
-                               try{ext=(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));}catch(...){continue;}
+                               String ext(filename_extension(filename));
+                               if (ext.size()) ext = ext.substr(1); // skip initial '.'
 
                                // If this is a SIF file, then we need to do things slightly differently
                                if(ext=="sketch")
index 839b55e..4b6dda5 100644 (file)
@@ -264,18 +264,15 @@ studio::Instance::dialog_save_as()
                if(find(filename.begin(),filename.end(),'*')!=filename.end())
                        continue;
 
-               std::string base = basename(filename);
-               if(find(base.begin(),base.end(),'.')==base.end())
+               if (filename_extension(filename) == "")
                        filename+=".sifz";
 
                try
                {
-                       String ext(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));
-                       if(ext!="sif" && ext!="sifz" && !App::dialog_yes_no(_("Unknown extension"),
+                       String ext(filename_extension(filename));
+                       if(ext!=".sif" && ext!=".sifz" && !App::dialog_yes_no(_("Unknown extension"),
                                _("You have given the file name an extension\nwhich I do not recognise. Are you sure this is what you want?")))
-                       {
                                continue;
-                       }
                }
                catch(...)
                {
index 5e397d1..1ee95c3 100644 (file)
@@ -190,12 +190,7 @@ RenderSettings::~RenderSettings()
 void
 RenderSettings::set_entry_filename()
 {
-       String filename(canvas_interface_->get_canvas()->get_file_name());
-
-       // if the basename of the filename has an extension, remove it
-       String base = basename(filename);
-       if(find(base.begin(),base.end(),'.')!=base.end())
-               filename = String(filename.begin(), filename.begin()+filename.find_last_of('.'));
+       String filename(filename_sans_extension(canvas_interface_->get_canvas()->get_file_name()));
 
        // if this isn't the root canvas, append (<canvasname>) to the filename
        etl::handle<synfig::Canvas> canvas = canvas_interface_->get_canvas();
@@ -255,7 +250,8 @@ RenderSettings::on_render_pressed()
        {
                try
                {
-                       String ext=String(find(filename.begin(),filename.end(),'.')+1,filename.end());
+                       String ext(filename_extension(filename));
+                       if (ext.size()) ext=ext.substr(1); // skip initial '.'
                        if(Target::ext_book().count(ext))
                                target_name=Target::ext_book()[ext];
                        else
index 1d8a820..d4e8068 100644 (file)
@@ -477,14 +477,14 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/)
 
        synfig::info("Attempting to import "+filename);
 
-
-       if(find(filename.begin(),filename.end(),'.')==filename.end())
+       if (filename_extension(filename) == "")
        {
                get_ui_interface()->error("Filename must have an extension!");
                return false;
        }
 
-       String ext(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));
+       String ext(filename_extension(filename));
+       if (ext.size()) ext = ext.substr(1); // skip initial '.'
        std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
 
        // If this is a SIF file, then we need to do things slightly differently