1aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Copyright 2008, Google Inc. 2aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// All rights reserved. 3aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// 4aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Redistribution and use in source and binary forms, with or without 5aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// modification, are permitted provided that the following conditions are 6aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// met: 7aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// 8aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// * Redistributions of source code must retain the above copyright 9aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// notice, this list of conditions and the following disclaimer. 10aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// * Redistributions in binary form must reproduce the above 11aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// copyright notice, this list of conditions and the following disclaimer 12aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// in the documentation and/or other materials provided with the 13aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// distribution. 14aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// * Neither the name of Google Inc. nor the names of its 15aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// contributors may be used to endorse or promote products derived from 16aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// this software without specific prior written permission. 17aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// 18aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// 30aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Author: keith.ray@gmail.com (Keith Ray) 31aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// 32aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Google Test filepath utilities 33aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// 34aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// This header file declares classes and functions used internally by 35aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Google Test. They are subject to change without notice. 36aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// 37aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// This file is #included in <gtest/internal/gtest-internal.h>. 38aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Do not include this header file separately! 39aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 40aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 41aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 42aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 43aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#include "gtest/internal/gtest-string.h" 44aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 45aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchternamespace testing { 46aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchternamespace internal { 47aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 48aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// FilePath - a class for file and directory pathname manipulation which 49aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// handles platform-specific conventions (like the pathname separator). 50aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Used for helper functions for naming files in a directory for xml output. 51aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Except for Set methods, all methods are const or static, which provides an 52aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// "immutable value object" -- useful for peace of mind. 53aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// A FilePath with a value ending in a path separator ("like/this/") represents 54aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// a directory, otherwise it is assumed to represent a file. In either case, 55aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// it may or may not represent an actual file or directory in the file system. 56aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// Names are NOT checked for syntax correctness -- no checking for illegal 57aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter// characters, malformed paths, etc. 58aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 59aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchterclass GTEST_API_ FilePath { 60aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter public: 61aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter FilePath() : pathname_("") { } 62aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } 63aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 64aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter explicit FilePath(const std::string& pathname) : pathname_(pathname) { 65aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter Normalize(); 66aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter } 67aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 68aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter FilePath& operator=(const FilePath& rhs) { 69aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter Set(rhs); 70aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter return *this; 71aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter } 72aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 73aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter void Set(const FilePath& rhs) { 74aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter pathname_ = rhs.pathname_; 75aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter } 76aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 77aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const std::string& string() const { return pathname_; } 78aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const char* c_str() const { return pathname_.c_str(); } 79aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 80aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns the current working directory, or "" if unsuccessful. 81aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter static FilePath GetCurrentDir(); 82aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 83aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Given directory = "dir", base_name = "test", number = 0, 84aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // extension = "xml", returns "dir/test.xml". If number is greater 85aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // than zero (e.g., 12), returns "dir/test_12.xml". 86aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // On Windows platform, uses \ as the separator rather than /. 87aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter static FilePath MakeFileName(const FilePath& directory, 88aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const FilePath& base_name, 89aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter int number, 90aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const char* extension); 91aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 92aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Given directory = "dir", relative_path = "test.xml", 93aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // returns "dir/test.xml". 94aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // On Windows, uses \ as the separator rather than /. 95aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter static FilePath ConcatPaths(const FilePath& directory, 96aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const FilePath& relative_path); 97aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 98aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns a pathname for a file that does not currently exist. The pathname 99aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // will be directory/base_name.extension or 100aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // directory/base_name_<number>.extension if directory/base_name.extension 101aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // already exists. The number will be incremented until a pathname is found 102aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // that does not already exist. 103aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'. 104aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // There could be a race condition if two or more processes are calling this 105aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // function at the same time -- they could both pick the same filename. 106aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter static FilePath GenerateUniqueFileName(const FilePath& directory, 107aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const FilePath& base_name, 108aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const char* extension); 109aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 110aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns true iff the path is "". 111aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool IsEmpty() const { return pathname_.empty(); } 112aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 113aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // If input name has a trailing separator character, removes it and returns 114aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // the name, otherwise return the name string unmodified. 115aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // On Windows platform, uses \ as the separator, other platforms use /. 116aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter FilePath RemoveTrailingPathSeparator() const; 117aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 118aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns a copy of the FilePath with the directory part removed. 119aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Example: FilePath("path/to/file").RemoveDirectoryName() returns 120aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // FilePath("file"). If there is no directory part ("just_a_file"), it returns 121aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // the FilePath unmodified. If there is no file part ("just_a_dir/") it 122aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // returns an empty FilePath (""). 123aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // On Windows platform, '\' is the path separator, otherwise it is '/'. 124aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter FilePath RemoveDirectoryName() const; 125aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 126aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // RemoveFileName returns the directory path with the filename removed. 127aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/". 128aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // If the FilePath is "a_file" or "/a_file", RemoveFileName returns 129aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does 130aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // not have a file, like "just/a/dir/", it returns the FilePath unmodified. 131aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // On Windows platform, '\' is the path separator, otherwise it is '/'. 132aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter FilePath RemoveFileName() const; 133aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 134aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns a copy of the FilePath with the case-insensitive extension removed. 135aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns 136aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // FilePath("dir/file"). If a case-insensitive extension is not 137aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // found, returns a copy of the original FilePath. 138aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter FilePath RemoveExtension(const char* extension) const; 139aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 140aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Creates directories so that path exists. Returns true if successful or if 141aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // the directories already exist; returns false if unable to create 142aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // directories for any reason. Will also return false if the FilePath does 143aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // not represent a directory (that is, it doesn't end with a path separator). 144aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool CreateDirectoriesRecursively() const; 145aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 146aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Create the directory so that path exists. Returns true if successful or 147aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // if the directory already exists; returns false if unable to create the 148aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // directory for any reason, including if the parent directory does not 149aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // exist. Not named "CreateDirectory" because that's a macro on Windows. 150aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool CreateFolder() const; 151aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 152aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns true if FilePath describes something in the file-system, 153aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // either a file, directory, or whatever, and that something exists. 154aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool FileOrDirectoryExists() const; 155aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 156aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns true if pathname describes a directory in the file-system 157aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // that exists. 158aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool DirectoryExists() const; 159aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 160aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns true if FilePath ends with a path separator, which indicates that 161aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // it is intended to represent a directory. Returns false otherwise. 162aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // This does NOT check that a directory (or file) actually exists. 163aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool IsDirectory() const; 164aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 165aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns true if pathname describes a root directory. (Windows has one 166aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // root directory per disk drive.) 167aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool IsRootDirectory() const; 168aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 169aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns true if pathname describes an absolute path. 170aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter bool IsAbsolutePath() const; 171aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 172aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter private: 173aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Replaces multiple consecutive separators with a single separator. 174aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // For example, "bar///foo" becomes "bar/foo". Does not eliminate other 175aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // redundancies that might be in a pathname involving "." or "..". 176aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // 177aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // A pathname with multiple consecutive separators may occur either through 178aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // user error or as a result of some scripts or APIs that generate a pathname 179aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // with a trailing separator. On other platforms the same API or script 180aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // may NOT generate a pathname with a trailing "/". Then elsewhere that 181aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // pathname may have another "/" and pathname components added to it, 182aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // without checking for the separator already being there. 183aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // The script language and operating system may allow paths like "foo//bar" 184aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // but some of the functions in FilePath will not handle that correctly. In 185aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // particular, RemoveTrailingPathSeparator() only removes one separator, and 186aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // it is called in CreateDirectoriesRecursively() assuming that it will change 187aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // a pathname from directory syntax (trailing separator) to filename syntax. 188aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // 189aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // On Windows this method also replaces the alternate path separator '/' with 190aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // the primary path separator '\\', so that for example "bar\\/\\foo" becomes 191aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // "bar\\foo". 192aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 193aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter void Normalize(); 194aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 195aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // Returns a pointer to the last occurence of a valid path separator in 196aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // the FilePath. On Windows, for example, both '/' and '\' are valid path 197aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter // separators. Returns NULL if no path separator was found. 198aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter const char* FindLastPathSeparator() const; 199aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 200aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter std::string pathname_; 201aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter}; // class FilePath 202aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 203aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter} // namespace internal 204aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter} // namespace testing 205aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter 206aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 207