summaryrefslogtreecommitdiff
path: root/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp
blob: 577b78e35fc1f98504b7b63e8324346b5de52c98 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <cstdlib>
#include <stdint.h>
#include <string>

template <typename T> struct CustomAlloc {
  using value_type = T;
  using pointer = value_type *;
  using const_pointer = const value_type *;
  using size_type = std::size_t;

  pointer allocate(size_type n) { return (T *)malloc(n * sizeof(T)); }

  void deallocate(pointer p, size_type) {
    if (p)
      free(p);
  }
};

using CustomString =
    std::basic_string<char, std::char_traits<char>, CustomAlloc<char>>;

using CustomWString =
    std::basic_string<wchar_t, std::char_traits<wchar_t>, CustomAlloc<wchar_t>>;

using CustomStringU16 = std::basic_string<char16_t, std::char_traits<char16_t>,
                                          CustomAlloc<char16_t>>;

using CustomStringU32 = std::basic_string<char32_t, std::char_traits<char32_t>,
                                          CustomAlloc<char32_t>>;

size_t touch_string(std::string &in_str) {
  return in_str.size(); // Break here to look at bad string
}

int main() {
  std::wstring wempty(L"");
  std::wstring s(L"hello world! מזל טוב!");
  std::wstring S(L"!!!!");
  const wchar_t *mazeltov = L"מזל טוב";
  std::string empty("");
  std::string q("hello world");
  std::string Q("quite a long std::strin with lots of info inside it");
  std::string overwritten_zero("abc");
  const_cast<char *>(overwritten_zero.data())[3] = 'd';
  std::string TheVeryLongOne(
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "9012345678901234567890123456789012345678901234567890someText123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "345678901234567890123456789012345678901234567890123456789012345678901234"
      "567890123456789012345678901234567890123456789012345678901234567890123456"
      "789012345678901234567890123456789012345678901234567890123456789012345678"
      "901234567890123456789012345678901234567890123456789012345678901234567890"
      "1234567890123456789012345678901234567890");
  std::string IHaveEmbeddedZeros("a\0b\0c\0d", 7);
  std::wstring IHaveEmbeddedZerosToo(
      L"hello world!\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監", 38);
  std::u16string u16_string(u"ß水氶");
  std::u16string u16_empty(u"");
  std::u32string u32_string(U"🍄🍅🍆🍌");
  std::u32string u32_empty(U"");
  std::string *null_str = nullptr;
  auto &rq = q;
  auto &rQ = Q;
  std::string *pq = &q;
  std::string *pQ = &Q;

  CustomString custom_str("hello!");
  CustomWString custom_wstr(L"hello!");
  CustomStringU16 custom_u16(u16_string.c_str());
  CustomStringU16 custom_u16_empty(u"");
  CustomStringU32 custom_u32(u32_string.c_str());
  CustomStringU32 custom_u32_empty(U"");

  S.assign(L"!!!!!"); // Set break point at this line.
  std::string *not_a_string = (std::string *)0x0;
  touch_string(*not_a_string);

  return 0;
}