Home | History | Annotate | Download | only in lib
      1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/stream_executor/lib/path.h"
     17 #include "tensorflow/stream_executor/lib/strcat.h"
     18 
     19 namespace perftools {
     20 namespace gputools {
     21 namespace port {
     22 namespace internal {
     23 
     24 static bool IsAbsolutePath(port::StringPiece path) {
     25   return !path.empty() && path[0] == '/';
     26 }
     27 
     28 // For an array of paths of length count, append them all together,
     29 // ensuring that the proper path separators are inserted between them.
     30 string JoinPathImpl(std::initializer_list<port::StringPiece> paths) {
     31   string result;
     32 
     33   for (port::StringPiece path : paths) {
     34     if (path.empty()) continue;
     35 
     36     if (result.empty()) {
     37       result = path.ToString();
     38       continue;
     39     }
     40 
     41     if (result[result.size() - 1] == '/') {
     42       if (IsAbsolutePath(path)) {
     43         StrAppend(&result, path.substr(1));
     44       } else {
     45         StrAppend(&result, path);
     46       }
     47     } else {
     48       if (IsAbsolutePath(path)) {
     49         StrAppend(&result, path);
     50       } else {
     51         StrAppend(&result, "/", path);
     52       }
     53     }
     54   }
     55 
     56   return result;
     57 }
     58 
     59 }  // namespace internal
     60 }  // namespace port
     61 }  // namespace gputools
     62 }  // namespace perftools
     63