File: make_string.h

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-6~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,418,812 kB
  • sloc: cpp: 5,290,827; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,900; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,892; xml: 953; cs: 573; fortran: 539
file content (63 lines) | stat: -rw-r--r-- 2,268 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef SUPPORT_TEST_MAKE_STRING_H
#define SUPPORT_TEST_MAKE_STRING_H

#include "test_macros.h"

#if TEST_STD_VER < 11
#error This header requires C++11 or greater
#endif

#include <string>

#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
#define CHAR8_ONLY(x) x,
#else
#define CHAR8_ONLY(x)
#endif

#define MKSTR(Str)                                                             \
  {                                                                            \
    Str, TEST_CONCAT(L, Str),                                                  \
        CHAR8_ONLY(TEST_CONCAT(u8, Str)) TEST_CONCAT(u, Str),                  \
        TEST_CONCAT(U, Str)                                                    \
  }

struct MultiStringType {
  const char* s;
  const wchar_t* w;
#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
  const char8_t* u8;
#endif
  const char16_t* u16;
  const char32_t* u32;

  constexpr operator const char*() const { return s; }
  constexpr operator const wchar_t*() const { return w; }
#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
  constexpr operator const char8_t*() const { return u8; }
#endif
  constexpr operator const char16_t*() const { return u16; }
  constexpr operator const char32_t*() const { return u32; }
};

// Helper to convert a const char* string to a basic_string<CharT>.
// This helper is used in unit tests to make them generic. The input should be
// valid ASCII which means the input is also valid UTF-8.
#define MAKE_STRING(CharT, Str)                                                \
  std::basic_string<CharT> {                                                   \
    static_cast<const CharT*>(MultiStringType MKSTR(Str))                      \
  }

// Like MAKE_STRING but converts to a const CharT*.
#define MAKE_CSTRING(CharT, Str)                                               \
  static_cast<const CharT*>(MultiStringType MKSTR(Str))

#endif