iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
file_path.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
2// Copyright (c) 2025 Contributors to the Eclipse Foundation
3//
4// See the NOTICE file(s) distributed with this work for additional
5// information regarding copyright ownership.
6//
7// This program and the accompanying materials are made available under the
8// terms of the Apache Software License 2.0 which is available at
9// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
10// which is available at https://opensource.org/licenses/MIT.
11//
12// SPDX-License-Identifier: Apache-2.0 OR MIT
13
14#ifndef IOX2_BB_FILE_PATH_HPP
15#define IOX2_BB_FILE_PATH_HPP
16
20
21namespace iox2 {
22namespace bb {
23namespace platform {
24#ifdef _WIN32
25constexpr uint64_t IOX2_MAX_PATH_LENGTH = 255U;
26#else
27constexpr uint64_t IOX2_MAX_PATH_LENGTH = 1023U;
28#endif
29} // namespace platform
30
31namespace detail {
33 -> bool;
35 -> bool;
36} // namespace detail
37
41class FilePath : public SemanticString<FilePath,
42 platform::IOX2_MAX_PATH_LENGTH,
43 detail::file_path_does_contain_invalid_content,
44 detail::file_path_does_contain_invalid_characters> {
49 using Parent::Parent;
50};
51
52namespace detail {
53inline auto
55 -> bool {
56 // NOLINTNEXTLINE(readability-identifier-length)
57 for (const char c : value.unchecked_access()) {
58 const bool is_small_letter { ASCII_A <= c && c <= ASCII_Z };
59 const bool is_capital_letter { ASCII_CAPITAL_A <= c && c <= ASCII_CAPITAL_Z };
60 const bool is_number { ASCII_0 <= c && c <= ASCII_9 };
61 const bool is_special_character { c == ASCII_DASH || c == ASCII_DOT || c == ASCII_COLON
62 || c == ASCII_UNDERSCORE };
63
64 const bool is_path_separator { [&]() -> bool {
65 // NOLINTNEXTLINE(readability-use-anyofallof) not yet supported in all compilers
66 for (const auto separator : platform::IOX2_PATH_SEPARATORS) {
67 if (c == separator) {
68 return true;
69 }
70 }
71 return false;
72 }() };
73
74 if ((!is_small_letter && !is_capital_letter) && (!is_number && !is_special_character) && !is_path_separator) {
75 return true;
76 }
77 }
78
79 return false;
80}
81
82inline auto
86} // namespace detail
87} // namespace bb
88} // namespace iox2
89
90#endif // IOX2_BB_FILE_PATH_HPP
Represents a path to a file. It is not allowed to end with a path separator since this would then be ...
Definition file_path.hpp:44
The SemanticString is a string which has an inner syntax and restrictions to valid content....
constexpr char ASCII_UNDERSCORE
auto is_valid_path_to_file(const bb::StaticString< StringCapacity > &name) noexcept -> bool
verifies if the given string is a valid path to a file
auto file_path_does_contain_invalid_content(const bb::StaticString< platform::IOX2_MAX_PATH_LENGTH > &value) noexcept -> bool
Definition file_path.hpp:83
auto file_path_does_contain_invalid_characters(const bb::StaticString< platform::IOX2_MAX_PATH_LENGTH > &value) noexcept -> bool
Definition file_path.hpp:54
constexpr uint64_t IOX2_MAX_PATH_LENGTH
Definition file_path.hpp:27
constexpr const char IOX2_PATH_SEPARATORS[IOX2_NUMBER_OF_PATH_SEPARATORS]