Sen API
Sen Libraries
Loading...
Searching...
No Matches
u8string_util.h
Go to the documentation of this file.
1// === u8string_util.h =================================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_CORE_BASE_U8STRING_UTIL_H
9#define SEN_CORE_BASE_U8STRING_UTIL_H
10
11// std
12#include <string>
13
14namespace sen::std_util
15{
16
17inline std::string fromU8string(const std::string& s) { return s; }
18
19inline std::string fromU8string(std::string&& s) { return std::move(s); }
20
21#if defined(__cpp_lib_char8_t)
22inline std::string fromU8string(const std::u8string& s) { return std::string(s.begin(), s.end()); }
23#endif
24
25inline const char* castToCharPtr(const char* cp) { return cp; }
26
27#if defined(__cpp_lib_char8_t)
28inline const char* castToCharPtr(const char8_t* cp)
29{
30 // Safe, as lvalues of type char may be used to access values of other types
31 return reinterpret_cast<const char*>(cp); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
32}
33
34#endif
35
36} // namespace sen::std_util
37
38#endif // SEN_CORE_BASE_U8STRING_UTIL_H
Definition bits.h:26
std::string fromU8string(const std::string &s)
Definition u8string_util.h:17
const char * castToCharPtr(const char *cp)
Definition u8string_util.h:25