X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Ffile-name.cc;h=bb07ebccd0f03576bedd90f0e206158d9bcf4955;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=21fec4e4b1a8a8a5a054edef2f32ae3175a9c566;hpb=785c8ae021ddb22677291aa9ed7bc815d97fdd27;p=lilypond.git diff --git a/flower/file-name.cc b/flower/file-name.cc index 21fec4e4b1..bb07ebccd0 100644 --- a/flower/file-name.cc +++ b/flower/file-name.cc @@ -3,7 +3,7 @@ source file of the Flower Library - (c) 1997--2006 Han-Wen Nienhuys + (c) 1997--2008 Han-Wen Nienhuys Jan Nieuwenhuizen */ @@ -12,6 +12,7 @@ #include #include #include +#include using namespace std; @@ -60,8 +61,8 @@ static /* avoid warning */ string slashify (string file_name) { - replace_all (file_name, '\\', '/'); - replace_all (file_name, string ("//"), "/"); + replace_all (&file_name, '\\', '/'); + replace_all (&file_name, string ("//"), "/"); return file_name; } @@ -177,3 +178,26 @@ File_name::is_absolute () const return (dir_.length () && dir_[0] == DIRSEP) || root_.length (); } + + +File_name +File_name::canonicalized () const +{ + File_name c = *this; + + replace_all (&c.dir_, string ("//"), string ("/")); + + vector components = string_split (c.dir_, '/'); + vector new_components; + + for (vsize i = 0; i < components.size (); i++) + { + if (components[i] == "..") + new_components.pop_back (); + else + new_components.push_back (components[i]); + } + + c.dir_ = string_join (new_components, "/"); + return c; +}