1 //===-- main.c --------------------------------------------------*- C++ -*-===// 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 #include <assert.h> 10 #include <string> 11 12 #define UASZ 64 13 14 template<class T, int N> 15 void copy_char_seq (T (&arr)[N], const T* src) 16 { 17 size_t src_len = std::char_traits<T>::length(src); 18 assert(src_len < N); 19 20 std::char_traits<T>::copy(arr, src, src_len); 21 arr[src_len] = 0; 22 } 23 24 int main (int argc, char const *argv[]) 25 { 26 char16_t as16[UASZ]; 27 char32_t as32[UASZ]; 28 auto cs16_zero = (char16_t)0; 29 auto cs32_zero = (char32_t)0; 30 auto cs16 = u"hello world ྒྙྐ"; 31 auto cs32 = U"hello world ྒྙྐ"; 32 char16_t *s16 = (char16_t *)u"ﺸﺵۻ"; 33 char32_t *s32 = (char32_t *)U"ЕЙРГЖО"; 34 copy_char_seq(as16, s16); 35 copy_char_seq(as32, s32); 36 s32 = nullptr; // breakpoint1 37 s32 = (char32_t *)U"෴"; 38 s16 = (char16_t *)u"色ハ匂ヘト散リヌルヲ"; 39 copy_char_seq(as16, s16); 40 copy_char_seq(as32, s32); 41 s32 = nullptr; // breakpoint2 42 return 0; 43 } 44