From 99b75ef1bb279e2314516f922f05696263d5bd27 Mon Sep 17 00:00:00 2001 From: dooglus Date: Sun, 14 Oct 2007 22:14:47 +0000 Subject: [PATCH] Use filename_extension() and filename_sans_extension(). git-svn-id: http://svn.voria.com/code@929 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/modules/mod_bmp/trgt_bmp.cpp | 9 +++------ .../trunk/src/modules/mod_imagemagick/trgt_imagemagick.cpp | 3 +-- synfig-core/trunk/src/modules/mod_jpeg/trgt_jpeg.cpp | 9 +++------ synfig-core/trunk/src/modules/mod_openexr/trgt_openexr.cpp | 12 ++++-------- synfig-core/trunk/src/modules/mod_png/trgt_png.cpp | 9 +++------ synfig-core/trunk/src/modules/mod_ppm/trgt_ppm.cpp | 9 +++------ synfig-core/trunk/src/synfig/importer.cpp | 5 +++-- synfig-core/trunk/src/synfig/savecanvas.cpp | 2 +- synfig-studio/trunk/src/gtkmm/canvasview.cpp | 4 ++-- synfig-studio/trunk/src/gtkmm/instance.cpp | 9 +++------ synfig-studio/trunk/src/gtkmm/render.cpp | 10 +++------- synfig-studio/trunk/src/synfigapp/canvasinterface.cpp | 6 +++--- 12 files changed, 32 insertions(+), 55 deletions(-) diff --git a/synfig-core/trunk/src/modules/mod_bmp/trgt_bmp.cpp b/synfig-core/trunk/src/modules/mod_bmp/trgt_bmp.cpp index ee9f7c7..cb51db2 100644 --- a/synfig-core/trunk/src/modules/mod_bmp/trgt_bmp.cpp +++ b/synfig-core/trunk/src/modules/mod_bmp/trgt_bmp.cpp @@ -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)")); } diff --git a/synfig-core/trunk/src/modules/mod_imagemagick/trgt_imagemagick.cpp b/synfig-core/trunk/src/modules/mod_imagemagick/trgt_imagemagick.cpp index 0d0cdff..123640b 100644 --- a/synfig-core/trunk/src/modules/mod_imagemagick/trgt_imagemagick.cpp +++ b/synfig-core/trunk/src/modules/mod_imagemagick/trgt_imagemagick.cpp @@ -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; diff --git a/synfig-core/trunk/src/modules/mod_jpeg/trgt_jpeg.cpp b/synfig-core/trunk/src/modules/mod_jpeg/trgt_jpeg.cpp index fc6557e..013a99a 100644 --- a/synfig-core/trunk/src/modules/mod_jpeg/trgt_jpeg.cpp +++ b/synfig-core/trunk/src/modules/mod_jpeg/trgt_jpeg.cpp @@ -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); } diff --git a/synfig-core/trunk/src/modules/mod_openexr/trgt_openexr.cpp b/synfig-core/trunk/src/modules/mod_openexr/trgt_openexr.cpp index 9142b1d..3cb0a46 100644 --- a/synfig-core/trunk/src/modules/mod_openexr/trgt_openexr.cpp +++ b/synfig-core/trunk/src/modules/mod_openexr/trgt_openexr.cpp @@ -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 { diff --git a/synfig-core/trunk/src/modules/mod_png/trgt_png.cpp b/synfig-core/trunk/src/modules/mod_png/trgt_png.cpp index 09c2152..dcaa538 100644 --- a/synfig-core/trunk/src/modules/mod_png/trgt_png.cpp +++ b/synfig-core/trunk/src/modules/mod_png/trgt_png.cpp @@ -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); } diff --git a/synfig-core/trunk/src/modules/mod_ppm/trgt_ppm.cpp b/synfig-core/trunk/src/modules/mod_ppm/trgt_ppm.cpp index 6484152..effe64d 100644 --- a/synfig-core/trunk/src/modules/mod_ppm/trgt_ppm.cpp +++ b/synfig-core/trunk/src/modules/mod_ppm/trgt_ppm.cpp @@ -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); } diff --git a/synfig-core/trunk/src/synfig/importer.cpp b/synfig-core/trunk/src/synfig/importer.cpp index 524eea3..120079f 100644 --- a/synfig-core/trunk/src/synfig/importer.cpp +++ b/synfig-core/trunk/src/synfig/importer.cpp @@ -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); diff --git a/synfig-core/trunk/src/synfig/savecanvas.cpp b/synfig-core/trunk/src/synfig/savecanvas.cpp index 4f37a25..8ccb099 100644 --- a/synfig-core/trunk/src/synfig/savecanvas.cpp +++ b/synfig-core/trunk/src/synfig/savecanvas.cpp @@ -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); diff --git a/synfig-studio/trunk/src/gtkmm/canvasview.cpp b/synfig-studio/trunk/src/gtkmm/canvasview.cpp index b6e093e..87c58a5 100644 --- a/synfig-studio/trunk/src/gtkmm/canvasview.cpp +++ b/synfig-studio/trunk/src/gtkmm/canvasview.cpp @@ -3137,8 +3137,8 @@ CanvasView::on_drop_drag_data_received(const Glib::RefPtr& 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") diff --git a/synfig-studio/trunk/src/gtkmm/instance.cpp b/synfig-studio/trunk/src/gtkmm/instance.cpp index 839b55e..4b6dda5 100644 --- a/synfig-studio/trunk/src/gtkmm/instance.cpp +++ b/synfig-studio/trunk/src/gtkmm/instance.cpp @@ -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(...) { diff --git a/synfig-studio/trunk/src/gtkmm/render.cpp b/synfig-studio/trunk/src/gtkmm/render.cpp index 5e397d1..1ee95c3 100644 --- a/synfig-studio/trunk/src/gtkmm/render.cpp +++ b/synfig-studio/trunk/src/gtkmm/render.cpp @@ -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 () to the filename etl::handle 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 diff --git a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp index 1d8a820..d4e8068 100644 --- a/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp +++ b/synfig-studio/trunk/src/synfigapp/canvasinterface.cpp @@ -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 -- 2.7.4