diff options
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 70abbe1405d..4cee654b64c 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -49,6 +49,11 @@ Slice::changeInclude(const string& orig, const vector<string>& includePaths) string file = normalizePath(orig); string::size_type pos; + // + // Compare each include path against the included file and select + // the path that produces the shortest relative filename. + // + string result = file; for(vector<string>::const_iterator p = includePaths.begin(); p != includePaths.end(); ++p) { string includePath = normalizePath(*p); @@ -56,19 +61,19 @@ Slice::changeInclude(const string& orig, const vector<string>& includePaths) if(file.compare(0, includePath.length(), includePath) == 0) { string s = file.substr(includePath.length()); - if(s.size() < file.size()) + if(s.size() < result.size()) { - file = s; + result = s; } } } - if((pos = file.rfind('.')) != string::npos) + if((pos = result.rfind('.')) != string::npos) { - file.erase(pos); + result.erase(pos); } - return file; + return result; } void |