Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:31:43

0001 //
0002 //  Copyright 2019 The Abseil Authors.
0003 //
0004 // Licensed under the Apache License, Version 2.0 (the "License");
0005 // you may not use this file except in compliance with the License.
0006 // You may obtain a copy of the License at
0007 //
0008 //      https://www.apache.org/licenses/LICENSE-2.0
0009 //
0010 // Unless required by applicable law or agreed to in writing, software
0011 // distributed under the License is distributed on an "AS IS" BASIS,
0012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013 // See the License for the specific language governing permissions and
0014 // limitations under the License.
0015 
0016 #ifndef ABSL_FLAGS_INTERNAL_PATH_UTIL_H_
0017 #define ABSL_FLAGS_INTERNAL_PATH_UTIL_H_
0018 
0019 #include "absl/base/config.h"
0020 #include "absl/strings/string_view.h"
0021 
0022 namespace absl {
0023 ABSL_NAMESPACE_BEGIN
0024 namespace flags_internal {
0025 
0026 // A portable interface that returns the basename of the filename passed as an
0027 // argument. It is similar to basename(3)
0028 // <https://linux.die.net/man/3/basename>.
0029 // For example:
0030 //     flags_internal::Basename("a/b/prog/file.cc")
0031 // returns "file.cc"
0032 //     flags_internal::Basename("file.cc")
0033 // returns "file.cc"
0034 inline absl::string_view Basename(absl::string_view filename) {
0035   auto last_slash_pos = filename.find_last_of("/\\");
0036 
0037   return last_slash_pos == absl::string_view::npos
0038              ? filename
0039              : filename.substr(last_slash_pos + 1);
0040 }
0041 
0042 // A portable interface that returns the directory name of the filename
0043 // passed as an argument, including the trailing slash.
0044 // Returns the empty string if a slash is not found in the input file name.
0045 // For example:
0046 //      flags_internal::Package("a/b/prog/file.cc")
0047 // returns "a/b/prog/"
0048 //      flags_internal::Package("file.cc")
0049 // returns ""
0050 inline absl::string_view Package(absl::string_view filename) {
0051   auto last_slash_pos = filename.find_last_of("/\\");
0052 
0053   return last_slash_pos == absl::string_view::npos
0054              ? absl::string_view()
0055              : filename.substr(0, last_slash_pos + 1);
0056 }
0057 
0058 }  // namespace flags_internal
0059 ABSL_NAMESPACE_END
0060 }  // namespace absl
0061 
0062 #endif  // ABSL_FLAGS_INTERNAL_PATH_UTIL_H_