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

Side by Side Diff: webrtc/base/pathutils.cc

Issue 2745073004: Delete unused Pathname methods. (Closed)
Patch Set: Add back Pathname::clear, it's used in the windows code. Created 3 years, 9 months 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
« no previous file with comments | « webrtc/base/pathutils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 Pathname::Pathname(const std::string& folder, const std::string& filename) 65 Pathname::Pathname(const std::string& folder, const std::string& filename)
66 : folder_delimiter_(DEFAULT_FOLDER_DELIM) { 66 : folder_delimiter_(DEFAULT_FOLDER_DELIM) {
67 SetPathname(folder, filename); 67 SetPathname(folder, filename);
68 } 68 }
69 69
70 Pathname& Pathname::operator=(const Pathname&) = default; 70 Pathname& Pathname::operator=(const Pathname&) = default;
71 Pathname& Pathname::operator=(Pathname&&) = default; 71 Pathname& Pathname::operator=(Pathname&&) = default;
72 72
73 void Pathname::SetFolderDelimiter(char delimiter) {
74 RTC_DCHECK(IsFolderDelimiter(delimiter));
75 folder_delimiter_ = delimiter;
76 }
77
78 void Pathname::Normalize() { 73 void Pathname::Normalize() {
79 for (size_t i=0; i<folder_.length(); ++i) { 74 for (size_t i=0; i<folder_.length(); ++i) {
80 if (IsFolderDelimiter(folder_[i])) { 75 if (IsFolderDelimiter(folder_[i])) {
81 folder_[i] = folder_delimiter_; 76 folder_[i] = folder_delimiter_;
82 } 77 }
83 } 78 }
84 } 79 }
85 80
86 void Pathname::clear() { 81 void Pathname::clear() {
87 folder_.clear(); 82 folder_.clear();
(...skipping 27 matching lines...) Expand all
115 SetFilename(pathname); 110 SetFilename(pathname);
116 } 111 }
117 } 112 }
118 113
119 void Pathname::SetPathname(const std::string& folder, 114 void Pathname::SetPathname(const std::string& folder,
120 const std::string& filename) { 115 const std::string& filename) {
121 SetFolder(folder); 116 SetFolder(folder);
122 SetFilename(filename); 117 SetFilename(filename);
123 } 118 }
124 119
125 void Pathname::AppendPathname(const std::string& pathname) {
126 std::string full_pathname(folder_);
127 full_pathname.append(pathname);
128 SetPathname(full_pathname);
129 }
130
131 std::string Pathname::folder() const { 120 std::string Pathname::folder() const {
132 return folder_; 121 return folder_;
133 } 122 }
134 123
135 std::string Pathname::folder_name() const {
136 std::string::size_type pos = std::string::npos;
137 if (folder_.size() >= 2) {
138 pos = folder_.find_last_of(FOLDER_DELIMS, folder_.length() - 2);
139 }
140 if (pos != std::string::npos) {
141 return folder_.substr(pos + 1);
142 } else {
143 return folder_;
144 }
145 }
146
147 std::string Pathname::parent_folder() const { 124 std::string Pathname::parent_folder() const {
148 std::string::size_type pos = std::string::npos; 125 std::string::size_type pos = std::string::npos;
149 if (folder_.size() >= 2) { 126 if (folder_.size() >= 2) {
150 pos = folder_.find_last_of(FOLDER_DELIMS, folder_.length() - 2); 127 pos = folder_.find_last_of(FOLDER_DELIMS, folder_.length() - 2);
151 } 128 }
152 if (pos != std::string::npos) { 129 if (pos != std::string::npos) {
153 return folder_.substr(0, pos + 1); 130 return folder_.substr(0, pos + 1);
154 } else { 131 } else {
155 return EMPTY_STR; 132 return EMPTY_STR;
156 } 133 }
157 } 134 }
158 135
159 void Pathname::SetFolder(const std::string& folder) { 136 void Pathname::SetFolder(const std::string& folder) {
160 folder_.assign(folder); 137 folder_.assign(folder);
161 // Ensure folder ends in a path delimiter 138 // Ensure folder ends in a path delimiter
162 if (!folder_.empty() && !IsFolderDelimiter(folder_[folder_.length()-1])) { 139 if (!folder_.empty() && !IsFolderDelimiter(folder_[folder_.length()-1])) {
163 folder_.push_back(folder_delimiter_); 140 folder_.push_back(folder_delimiter_);
164 } 141 }
165 } 142 }
166 143
167 void Pathname::AppendFolder(const std::string& folder) { 144 void Pathname::AppendFolder(const std::string& folder) {
168 folder_.append(folder); 145 folder_.append(folder);
169 // Ensure folder ends in a path delimiter 146 // Ensure folder ends in a path delimiter
170 if (!folder_.empty() && !IsFolderDelimiter(folder_[folder_.length()-1])) { 147 if (!folder_.empty() && !IsFolderDelimiter(folder_[folder_.length()-1])) {
171 folder_.push_back(folder_delimiter_); 148 folder_.push_back(folder_delimiter_);
172 } 149 }
173 } 150 }
174 151
175 std::string Pathname::basename() const {
176 return basename_;
177 }
178
179 bool Pathname::SetBasename(const std::string& basename) { 152 bool Pathname::SetBasename(const std::string& basename) {
180 if(basename.find_first_of(FOLDER_DELIMS) != std::string::npos) { 153 if(basename.find_first_of(FOLDER_DELIMS) != std::string::npos) {
181 return false; 154 return false;
182 } 155 }
183 basename_.assign(basename); 156 basename_.assign(basename);
184 return true; 157 return true;
185 } 158 }
186 159
187 std::string Pathname::extension() const {
188 return extension_;
189 }
190
191 bool Pathname::SetExtension(const std::string& extension) { 160 bool Pathname::SetExtension(const std::string& extension) {
192 if (extension.find_first_of(FOLDER_DELIMS) != std::string::npos || 161 if (extension.find_first_of(FOLDER_DELIMS) != std::string::npos ||
193 extension.find_first_of(EXT_DELIM, 1) != std::string::npos) { 162 extension.find_first_of(EXT_DELIM, 1) != std::string::npos) {
194 return false; 163 return false;
195 } 164 }
196 extension_.assign(extension); 165 extension_.assign(extension);
197 // Ensure extension begins with the extension delimiter 166 // Ensure extension begins with the extension delimiter
198 if (!extension_.empty() && (extension_[0] != EXT_DELIM)) { 167 if (!extension_.empty() && (extension_[0] != EXT_DELIM)) {
199 extension_.insert(extension_.begin(), EXT_DELIM); 168 extension_.insert(extension_.begin(), EXT_DELIM);
200 } 169 }
201 return true; 170 return true;
202 } 171 }
203 172
204 std::string Pathname::filename() const { 173 std::string Pathname::filename() const {
205 std::string filename(basename_); 174 std::string filename(basename_);
206 filename.append(extension_); 175 filename.append(extension_);
207 return filename; 176 return filename;
208 } 177 }
209 178
210 bool Pathname::SetFilename(const std::string& filename) { 179 bool Pathname::SetFilename(const std::string& filename) {
211 std::string::size_type pos = filename.rfind(EXT_DELIM); 180 std::string::size_type pos = filename.rfind(EXT_DELIM);
212 if ((pos == std::string::npos) || (pos == 0)) { 181 if ((pos == std::string::npos) || (pos == 0)) {
213 return SetExtension(EMPTY_STR) && SetBasename(filename); 182 return SetExtension(EMPTY_STR) && SetBasename(filename);
214 } else { 183 } else {
215 return SetExtension(filename.substr(pos)) && SetBasename(filename.substr(0, pos)); 184 return SetExtension(filename.substr(pos)) && SetBasename(filename.substr(0, pos));
216 } 185 }
217 } 186 }
218 187
219 #if defined(WEBRTC_WIN)
220 bool Pathname::GetDrive(char* drive, uint32_t bytes) const {
221 return GetDrive(drive, bytes, folder_);
222 }
223
224 // static
225 bool Pathname::GetDrive(char* drive,
226 uint32_t bytes,
227 const std::string& pathname) {
228 // need at lease 4 bytes to save c:
229 if (bytes < 4 || pathname.size() < 3) {
230 return false;
231 }
232
233 memcpy(drive, pathname.c_str(), 3);
234 drive[3] = 0;
235 // sanity checking
236 return (isalpha(drive[0]) &&
237 drive[1] == ':' &&
238 drive[2] == '\\');
239 }
240 #endif
241
242 /////////////////////////////////////////////////////////////////////////////// 188 ///////////////////////////////////////////////////////////////////////////////
243 189
244 } // namespace rtc 190 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/pathutils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698