1 /*
2  *  This file is part of RawTherapee.
3  *
4  *
5  *  RawTherapee is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  RawTherapee is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
17  */
18 
19 #include <glibmm/miscutils.h>
20 
21 #include "pathutils.h"
22 
23 
removeExtension(const Glib::ustring & filename)24 Glib::ustring removeExtension (const Glib::ustring& filename)
25 {
26 
27     Glib::ustring bname = Glib::path_get_basename(filename);
28     size_t lastdot = bname.find_last_of ('.');
29     size_t lastwhitespace = bname.find_last_of (" \t\f\v\n\r");
30 
31     if (lastdot != bname.npos && (lastwhitespace == bname.npos || lastdot > lastwhitespace)) {
32         return filename.substr (0, filename.size() - (bname.size() - lastdot));
33     } else {
34         return filename;
35     }
36 }
37 
getExtension(const Glib::ustring & filename)38 Glib::ustring getExtension (const Glib::ustring& filename)
39 {
40 
41     Glib::ustring bname = Glib::path_get_basename(filename);
42     size_t lastdot = bname.find_last_of ('.');
43     size_t lastwhitespace = bname.find_last_of (" \t\f\v\n\r");
44 
45     if (lastdot != bname.npos && (lastwhitespace == bname.npos || lastdot > lastwhitespace)) {
46         return filename.substr (filename.size() - (bname.size() - lastdot) + 1, filename.npos);
47     } else {
48         return "";
49     }
50 }
51