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

Side by Side Diff: tools/gn/source_file.cc

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang warning Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "tools/gn/source_file.h" 5 #include "tools/gn/source_file.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "tools/gn/filesystem_utils.h" 9 #include "tools/gn/filesystem_utils.h"
10 #include "tools/gn/source_dir.h" 10 #include "tools/gn/source_dir.h"
11 11
12 SourceFile::SourceFile() { 12 SourceFile::SourceFile() {
13 } 13 }
14 14
15 SourceFile::SourceFile(const base::StringPiece& p) 15 SourceFile::SourceFile(const base::StringPiece& p)
16 : value_(p.data(), p.size()) { 16 : value_(p.data(), p.size()) {
17 DCHECK(!value_.empty()); 17 DCHECK(!value_.empty());
18 DCHECK(value_[0] == '/'); 18 DCHECK(value_[0] == '/');
19 DCHECK(!EndsWithSlash(value_)); 19 DCHECK(!EndsWithSlash(value_));
20 } 20 }
21 21
22 SourceFile::SourceFile(SwapIn, std::string* value) {
23 value_.swap(*value);
24 DCHECK(!value_.empty());
25 DCHECK(value_[0] == '/');
26 DCHECK(!EndsWithSlash(value_));
27 }
28
22 SourceFile::~SourceFile() { 29 SourceFile::~SourceFile() {
23 } 30 }
24 31
25 std::string SourceFile::GetName() const { 32 std::string SourceFile::GetName() const {
26 if (is_null()) 33 if (is_null())
27 return std::string(); 34 return std::string();
28 35
29 DCHECK(value_.find('/') != std::string::npos); 36 DCHECK(value_.find('/') != std::string::npos);
30 size_t last_slash = value_.rfind('/'); 37 size_t last_slash = value_.rfind('/');
31 return std::string(&value_[last_slash + 1], 38 return std::string(&value_[last_slash + 1],
(...skipping 21 matching lines...) Expand all
53 } else { 60 } else {
54 converted.assign(value_); 61 converted.assign(value_);
55 } 62 }
56 return base::FilePath(UTF8ToFilePath(converted)); 63 return base::FilePath(UTF8ToFilePath(converted));
57 } 64 }
58 65
59 converted.assign(&value_[2], value_.size() - 2); 66 converted.assign(&value_[2], value_.size() - 2);
60 return source_root.Append(UTF8ToFilePath(converted)) 67 return source_root.Append(UTF8ToFilePath(converted))
61 .NormalizePathSeparatorsTo('/'); 68 .NormalizePathSeparatorsTo('/');
62 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698