iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
string_internal.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 Contributors to the Eclipse Foundation
2//
3// See the NOTICE file(s) distributed with this work for additional
4// information regarding copyright ownership.
5//
6// This program and the accompanying materials are made available under the
7// terms of the Apache Software License 2.0 which is available at
8// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9// which is available at https://opensource.org/licenses/MIT.
10//
11// SPDX-License-Identifier: Apache-2.0 OR MIT
12
13#ifndef IOX2_INCLUDE_GUARD_BB_DETAIL_STRING_INTERNAL_HPP
14#define IOX2_INCLUDE_GUARD_BB_DETAIL_STRING_INTERNAL_HPP
15
16#include <cstdint>
17#include <cstring>
18
19namespace iox2 {
20namespace bb {
21template <uint64_t>
22class StaticString;
23
24namespace detail {
25template <uint64_t N>
26// C array not used here, it is a type alias for easier access
27// NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
28using CharArray = char[N];
29
30template <uint64_t N>
31auto get_size(const StaticString<N>& data) -> uint64_t {
32 return data.size();
33}
34
35template <uint64_t N>
36auto get_size(const CharArray<N>& data) -> uint64_t {
37 return strnlen(&data[0], N);
38}
39
40template <uint64_t N>
41auto get_data(const StaticString<N>& data) -> const char* {
42 return data.unchecked_access().c_str();
43}
44
45template <uint64_t N>
46auto get_data(const CharArray<N>& data) -> const char* {
47 return &data[0];
48}
49} // namespace detail
50} // namespace bb
51} // namespace iox2
52
53#endif // IOX2_INCLUDE_GUARD_BB_DETAIL_STRING_INTERNAL_HPP
auto get_size(const StaticString< N > &data) -> uint64_t
auto get_data(const StaticString< N > &data) -> const char *