aboutsummaryrefslogtreecommitdiff
path: root/strutil.cc
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-29 16:32:45 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-29 16:32:45 +0900
commit1310834a240dca89fb06b4fe8dfccbdf97c83144 (patch)
treebeee02bffdd41dbd051f68a14739af7261282c94 /strutil.cc
parentf772b17d24ed25314dff5e30ac548ed19b9c265a (diff)
downloadkati-1310834a240dca89fb06b4fe8dfccbdf97c83144.tar.gz
[C++] Fix abspath
Diffstat (limited to 'strutil.cc')
-rw-r--r--strutil.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/strutil.cc b/strutil.cc
index 80b5de9..7931e73 100644
--- a/strutil.cc
+++ b/strutil.cc
@@ -298,9 +298,9 @@ void AbsPath(StringPiece s, string* o) {
size_t j = 1;
size_t prev_start = 1;
- for (size_t i = 1; i < o->size(); i++) {
- char c= (*o)[i];
- if (c != '/') {
+ for (size_t i = 1; i <= o->size(); i++) {
+ char c = (*o)[i];
+ if (c != '/' && c != 0) {
(*o)[j] = c;
j++;
continue;
@@ -318,11 +318,15 @@ void AbsPath(StringPiece s, string* o) {
j++;
}
} else if (!prev_dir.empty()) {
- (*o)[j] = c;
- j++;
+ if (c) {
+ (*o)[j] = c;
+ j++;
+ }
}
prev_start = j;
}
+ if (j > 1 && (*o)[j-1] == '/')
+ j--;
o->resize(j);
}