From 4ffccc4f808eecfffa706eddb4ff0bab870a7803 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 25 Feb 2015 00:12:00 +0100 Subject: Fix (ICE-5833) - shorten paths when include file is not a canonical path --- cpp/src/Slice/Util.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'cpp/src/Slice/Util.cpp') diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp index 5be8bbde126..1961ef34e03 100644 --- a/cpp/src/Slice/Util.cpp +++ b/cpp/src/Slice/Util.cpp @@ -154,21 +154,32 @@ Slice::fullPath(const string& path) } string -Slice::changeInclude(const string& file, const vector& includePaths) +Slice::changeInclude(const string& path, const vector& includePaths) { // // Compare each include path against the included file and select // the path that produces the shortest relative filename. // - string result = file; - for(vector::const_iterator p = includePaths.begin(); p != includePaths.end(); ++p) + string result = path; + set paths; + paths.insert(path); + // + // if path is not a canonical path we also test with its canonical + // path + // + paths.insert(fullPath(path)); + + for(set::const_iterator i = paths.begin(); i != paths.end(); ++i) { - if(file.compare(0, p->length(), *p) == 0) + for(vector::const_iterator j = includePaths.begin(); j != includePaths.end(); ++j) { - string s = file.substr(p->length() + 1); // + 1 for the '/' - if(s.size() < result.size()) + if(i->compare(0, j->length(), *j) == 0) { - result = s; + string s = i->substr(j->length() + 1); // + 1 for the '/' + if(s.size() < result.size()) + { + result = s; + } } } } -- cgit v1.2.3