Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/sync/util/path_helpers.h

Issue 340055: String cleanup in sync code (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/util/compat_file_win.cc ('k') | chrome/browser/sync/util/path_helpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_ 5 #ifndef CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_
6 #define CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_ 6 #define CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <string> 10 #include <string>
11 11
12 #include "chrome/browser/sync/util/compat_file.h" 12 #include "base/file_path.h"
13 #include "chrome/browser/sync/util/sync_types.h" 13 #include "chrome/browser/sync/util/sync_types.h"
14 14
15 extern const char kPathSeparator[];
16
15 template <typename StringType> 17 template <typename StringType>
16 class PathSegmentIterator : public std::iterator<std::forward_iterator_tag, 18 class PathSegmentIterator : public std::iterator<std::forward_iterator_tag,
17 StringType> { 19 StringType> {
18 public: 20 public:
19 explicit PathSegmentIterator(const StringType& path) : 21 explicit PathSegmentIterator(const StringType& path) :
20 path_(path), segment_begin_(0), segment_end_(0) { 22 path_(path), segment_begin_(0), segment_end_(0) {
21 ++(*this); 23 ++(*this);
22 } 24 }
23 25
24 PathSegmentIterator() : segment_begin_(0), segment_end_(0) { } 26 PathSegmentIterator() : segment_begin_(0), segment_end_(0) { }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return !(*this == i); 61 return !(*this == i);
60 } 62 }
61 63
62 protected: 64 protected:
63 StringType path_; 65 StringType path_;
64 typename StringType::size_type segment_begin_; 66 typename StringType::size_type segment_begin_;
65 typename StringType::size_type segment_end_; 67 typename StringType::size_type segment_end_;
66 StringType value_; 68 StringType value_;
67 }; 69 };
68 70
69 // NOTE: The functions (Strip)LastPathSegment always return values without a
70 // trailing slash.
71 PathString LastPathSegment(const PathString& path);
72 std::string LastPathSegment(const std::string& path);
73 PathString AppendSlash(const PathString& path);
74 PathString GetFullPath(const PathString& path);
75 PathString ExpandTilde(const PathString& path);
76
77 inline bool HasSuffixPathString(const PathString& str,
78 const PathString& suffix) {
79 return str.find(suffix, str.size() - suffix.size()) != PathString::npos;
80 }
81
82 inline PathString StripSuffixPathString(const PathString& str,
83 const PathString& suffix) {
84 PathString ret(str);
85 if (HasSuffixPathString(str, suffix)) {
86 ret.resize(str.size() - suffix.size());
87 }
88 return ret;
89 }
90
91 // Returns a string with length or fewer elements, careful to not truncate a
92 // string mid-surrogate pair.
93 PathString TruncatePathString(const PathString& original, int length);
94
95 // Makes a path component legal for your OS, but doesn't handle collisions 71 // Makes a path component legal for your OS, but doesn't handle collisions
96 // with other files in the same directory. it can do this by removing 72 // with other files in the same directory. it can do this by removing
97 // illegal characters and adding ~1 before the first '.' in the filename. 73 // illegal characters and adding ~1 before the first '.' in the filename.
98 // returns PSTR("") if the name is fine as-is 74 // returns PSTR("") if the name is fine as-is
99 // on mac/linux we let names stay unicode normalization form C in the system 75 // on mac/linux we let names stay unicode normalization form C in the system
100 // and convert to another normal form in fuse handlers. but, if a '/' is in 76 // and convert to another normal form in fuse handlers. but, if a '/' is in
101 // a filename, we handle it here. 77 // a filename, we handle it here.
102 PathString MakePathComponentOSLegal(const PathString& component); 78 PathString MakePathComponentOSLegal(const PathString& component);
103 79
104 #endif // CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_ 80 #endif // CHROME_BROWSER_SYNC_UTIL_PATH_HELPERS_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/compat_file_win.cc ('k') | chrome/browser/sync/util/path_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698