1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef SUPPORT_TEST_MAKE_STRING_H 10 #define SUPPORT_TEST_MAKE_STRING_H 11 12 #include "test_macros.h" 13 14 #if TEST_STD_VER < 11 15 #error This header requires C++11 or greater 16 #endif 17 18 #include <string> 19 20 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 21 #define CHAR8_ONLY(x) x, 22 #else 23 #define CHAR8_ONLY(x) 24 #endif 25 26 #define MKSTR(Str) \ 27 { \ 28 Str, TEST_CONCAT(L, Str), \ 29 CHAR8_ONLY(TEST_CONCAT(u8, Str)) TEST_CONCAT(u, Str), \ 30 TEST_CONCAT(U, Str) \ 31 } 32 33 struct MultiStringType { 34 const char* s; 35 const wchar_t* w; 36 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 37 const char8_t* u8; 38 #endif 39 const char16_t* u16; 40 const char32_t* u32; 41 42 operator const char*() const { return s; } 43 operator const wchar_t*() const { return w; } 44 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 45 operator const char8_t*() const { return u8; } 46 #endif 47 operator const char16_t*() const { return u16; } 48 operator const char32_t*() const { return u32; } 49 }; 50 51 // Helper to convert a const char* string to a basic_string<CharT>. 52 // This helper is used in unit tests to make them generic. The input should be 53 // valid ASCII which means the input is also valid UTF-8. 54 #define MAKE_STRING(CharT, Str) \ 55 std::basic_string<CharT> { \ 56 static_cast<const CharT*>(MultiStringType MKSTR(Str)) \ 57 } 58 59 #endif 60