brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 9e62406 Raw
103 lines · c
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H11#define TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H12 13#include <cstddef>14#include <iterator>15 16#include <filesystem>17#include "make_string.h"18namespace fs = std::filesystem;19 20// Testing the allocation behavior of the code_cvt functions requires21// *knowing* that the allocation was not done by "path::__str_".22// This hack forces path to allocate enough memory.23inline void PathReserve(fs::path& p, std::size_t N) {24  auto const& native_ref = p.native();25  const_cast<fs::path::string_type&>(native_ref).reserve(N);26}27 28inline bool PathEq(fs::path const& LHS, fs::path const& RHS) {29  return LHS.native() == RHS.native();30}31 32inline bool PathEqIgnoreSep(fs::path LHS, fs::path RHS) {33  LHS.make_preferred();34  RHS.make_preferred();35  return LHS.native() == RHS.native();36}37 38template <class Iter>39Iter IterEnd(Iter B) {40  using VT = typename std::iterator_traits<Iter>::value_type;41  for (; *B != VT{}; ++B)42    ;43  return B;44}45 46template <class CharT>47const CharT* StrEnd(CharT const* P) {48    return IterEnd(P);49}50 51template <class CharT>52std::size_t StrLen(CharT const* P) {53    return StrEnd(P) - P;54}55 56const MultiStringType PathList[] = {57        MKSTR(""),58        MKSTR(" "),59        MKSTR("//"),60        MKSTR("."),61        MKSTR(".."),62        MKSTR("foo"),63        MKSTR("/"),64        MKSTR("/foo"),65        MKSTR("foo/"),66        MKSTR("/foo/"),67        MKSTR("foo/bar"),68        MKSTR("/foo/bar"),69        MKSTR("//net"),70        MKSTR("//net/foo"),71        MKSTR("///foo///"),72        MKSTR("///foo///bar"),73        MKSTR("/."),74        MKSTR("./"),75        MKSTR("/.."),76        MKSTR("../"),77        MKSTR("foo/."),78        MKSTR("foo/.."),79        MKSTR("foo/./"),80        MKSTR("foo/./bar"),81        MKSTR("foo/../"),82        MKSTR("foo/../bar"),83        MKSTR("c:"),84        MKSTR("c:/"),85        MKSTR("c:foo"),86        MKSTR("c:/foo"),87        MKSTR("c:foo/"),88        MKSTR("c:/foo/"),89        MKSTR("c:/foo/bar"),90        MKSTR("prn:"),91        MKSTR("c:\\"),92        MKSTR("c:\\foo"),93        MKSTR("c:foo\\"),94        MKSTR("c:\\foo\\"),95        MKSTR("c:\\foo/"),96        MKSTR("c:/foo\\bar"),97        MKSTR("//"),98        MKSTR("/finally/we/need/one/really/really/really/really/really/really/really/long/string")99};100const unsigned PathListSize = sizeof(PathList) / sizeof(MultiStringType);101 102#endif // TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H103