Reason for revert: Fourth attempt to land. Waiting for https://codereview.webrtc.org/2845013003 to avoid conflicts on webrtc/modules/audio_coding:neteq_unittest_tools. Original issue's description: > Revert of Enable GN check for webrtc/base (patchset #13 id:240001 of https://codereview.webrtc.org/2717083002/ ) > > Reason for revert: > Breaks Chromium because in Chromium we import WebRTC with rtc_include_tests=false (https://bugs.chromium.org/p/chromium/issues/detail?id=713179#c6). > > Chromium uses webrtc/test/fuzzers and this CL adds test dependencies to neteq_rtc_fuzzer. > > Original issue's description: > > Enable GN check for webrtc/base > > > > It's not possible to enable it for the rtc_base_approved > > target but since a larger refactoring is ongoing for webrtc/base > > this CL doesn't attempt to fix that. > > > > Changes made: > > * Move webrtc/system_wrappers/include/stringize_macros.h into > > webrtc/base:rtc_base_approved_unittests (and corresponding > > unit test to rtc_base_approved_unittests). > > * Move md5digest.* from rtc_base_approved to rtc_base_test_utils target. > > * Move webrtc/system_wrappers/include/stringize_macros.h (+test) into > > webrtc/base. > > * Remove unused use include of webrtc/base/fileutils.h in > > webrtc/base/pathutils.cc > > > > BUG=webrtc:6828, webrtc:3806, webrtc:7480 > > NOTRY=True > > > > Review-Url: https://codereview.webrtc.org/2717083002 > > Cr-Commit-Position: refs/heads/master@{#17766} > > Committed:ed754e71ae> > TBR=perkj@webrtc.org,tommi@webrtc.org,nisse@webrtc.org,kjellander@webrtc.org > # Not skipping CQ checks because original CL landed more than 1 days ago. > BUG=webrtc:6828, webrtc:3806, webrtc:7480 > NOTRY=True > > Review-Url: https://codereview.webrtc.org/2838683002 > Cr-Commit-Position: refs/heads/master@{#17849} > Committed:11ed366c48TBR=perkj@webrtc.org,tommi@webrtc.org,nisse@webrtc.org,kjellander@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:6828, webrtc:3806, webrtc:7480 Review-Url: https://codereview.webrtc.org/2852663002 Cr-Commit-Position: refs/heads/master@{#17927}
190 lines
5.2 KiB
C++
190 lines
5.2 KiB
C++
/*
|
|
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#if defined(WEBRTC_WIN)
|
|
#include "webrtc/base/win32.h"
|
|
#include <shellapi.h>
|
|
#include <shlobj.h>
|
|
#include <tchar.h>
|
|
#endif // WEBRTC_WIN
|
|
|
|
#include "webrtc/base/checks.h"
|
|
#include "webrtc/base/logging.h"
|
|
#include "webrtc/base/pathutils.h"
|
|
#include "webrtc/base/stringutils.h"
|
|
|
|
namespace rtc {
|
|
|
|
static const char EMPTY_STR[] = "";
|
|
|
|
// EXT_DELIM separates a file basename from extension
|
|
const char EXT_DELIM = '.';
|
|
|
|
// FOLDER_DELIMS separate folder segments and the filename
|
|
const char* const FOLDER_DELIMS = "/\\";
|
|
|
|
// DEFAULT_FOLDER_DELIM is the preferred delimiter for this platform
|
|
#ifdef WEBRTC_WIN
|
|
const char DEFAULT_FOLDER_DELIM = '\\';
|
|
#else // !WEBRTC_WIN
|
|
const char DEFAULT_FOLDER_DELIM = '/';
|
|
#endif // !WEBRTC_WIN
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Pathname - parsing of pathnames into components, and vice versa
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool Pathname::IsFolderDelimiter(char ch) {
|
|
return (nullptr != ::strchr(FOLDER_DELIMS, ch));
|
|
}
|
|
|
|
char Pathname::DefaultFolderDelimiter() {
|
|
return DEFAULT_FOLDER_DELIM;
|
|
}
|
|
|
|
Pathname::Pathname()
|
|
: folder_delimiter_(DEFAULT_FOLDER_DELIM) {
|
|
}
|
|
|
|
Pathname::Pathname(const Pathname&) = default;
|
|
Pathname::Pathname(Pathname&&) = default;
|
|
|
|
Pathname::Pathname(const std::string& pathname)
|
|
: folder_delimiter_(DEFAULT_FOLDER_DELIM) {
|
|
SetPathname(pathname);
|
|
}
|
|
|
|
Pathname::Pathname(const std::string& folder, const std::string& filename)
|
|
: folder_delimiter_(DEFAULT_FOLDER_DELIM) {
|
|
SetPathname(folder, filename);
|
|
}
|
|
|
|
Pathname& Pathname::operator=(const Pathname&) = default;
|
|
Pathname& Pathname::operator=(Pathname&&) = default;
|
|
|
|
void Pathname::Normalize() {
|
|
for (size_t i=0; i<folder_.length(); ++i) {
|
|
if (IsFolderDelimiter(folder_[i])) {
|
|
folder_[i] = folder_delimiter_;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Pathname::clear() {
|
|
folder_.clear();
|
|
basename_.clear();
|
|
extension_.clear();
|
|
}
|
|
|
|
bool Pathname::empty() const {
|
|
return folder_.empty() && basename_.empty() && extension_.empty();
|
|
}
|
|
|
|
std::string Pathname::pathname() const {
|
|
std::string pathname(folder_);
|
|
pathname.append(basename_);
|
|
pathname.append(extension_);
|
|
if (pathname.empty()) {
|
|
// Instead of the empty pathname, return the current working directory.
|
|
pathname.push_back('.');
|
|
pathname.push_back(folder_delimiter_);
|
|
}
|
|
return pathname;
|
|
}
|
|
|
|
void Pathname::SetPathname(const std::string& pathname) {
|
|
std::string::size_type pos = pathname.find_last_of(FOLDER_DELIMS);
|
|
if (pos != std::string::npos) {
|
|
SetFolder(pathname.substr(0, pos + 1));
|
|
SetFilename(pathname.substr(pos + 1));
|
|
} else {
|
|
SetFolder(EMPTY_STR);
|
|
SetFilename(pathname);
|
|
}
|
|
}
|
|
|
|
void Pathname::SetPathname(const std::string& folder,
|
|
const std::string& filename) {
|
|
SetFolder(folder);
|
|
SetFilename(filename);
|
|
}
|
|
|
|
std::string Pathname::folder() const {
|
|
return folder_;
|
|
}
|
|
|
|
std::string Pathname::parent_folder() const {
|
|
std::string::size_type pos = std::string::npos;
|
|
if (folder_.size() >= 2) {
|
|
pos = folder_.find_last_of(FOLDER_DELIMS, folder_.length() - 2);
|
|
}
|
|
if (pos != std::string::npos) {
|
|
return folder_.substr(0, pos + 1);
|
|
} else {
|
|
return EMPTY_STR;
|
|
}
|
|
}
|
|
|
|
void Pathname::SetFolder(const std::string& folder) {
|
|
folder_.assign(folder);
|
|
// Ensure folder ends in a path delimiter
|
|
if (!folder_.empty() && !IsFolderDelimiter(folder_[folder_.length()-1])) {
|
|
folder_.push_back(folder_delimiter_);
|
|
}
|
|
}
|
|
|
|
void Pathname::AppendFolder(const std::string& folder) {
|
|
folder_.append(folder);
|
|
// Ensure folder ends in a path delimiter
|
|
if (!folder_.empty() && !IsFolderDelimiter(folder_[folder_.length()-1])) {
|
|
folder_.push_back(folder_delimiter_);
|
|
}
|
|
}
|
|
|
|
bool Pathname::SetBasename(const std::string& basename) {
|
|
if(basename.find_first_of(FOLDER_DELIMS) != std::string::npos) {
|
|
return false;
|
|
}
|
|
basename_.assign(basename);
|
|
return true;
|
|
}
|
|
|
|
bool Pathname::SetExtension(const std::string& extension) {
|
|
if (extension.find_first_of(FOLDER_DELIMS) != std::string::npos ||
|
|
extension.find_first_of(EXT_DELIM, 1) != std::string::npos) {
|
|
return false;
|
|
}
|
|
extension_.assign(extension);
|
|
// Ensure extension begins with the extension delimiter
|
|
if (!extension_.empty() && (extension_[0] != EXT_DELIM)) {
|
|
extension_.insert(extension_.begin(), EXT_DELIM);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
std::string Pathname::filename() const {
|
|
std::string filename(basename_);
|
|
filename.append(extension_);
|
|
return filename;
|
|
}
|
|
|
|
bool Pathname::SetFilename(const std::string& filename) {
|
|
std::string::size_type pos = filename.rfind(EXT_DELIM);
|
|
if ((pos == std::string::npos) || (pos == 0)) {
|
|
return SetExtension(EMPTY_STR) && SetBasename(filename);
|
|
} else {
|
|
return SetExtension(filename.substr(pos)) && SetBasename(filename.substr(0, pos));
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
} // namespace rtc
|