1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <string> 11 12 // basic_string<charT,traits,Allocator>& 13 // replace(size_type pos, size_type n1, const charT* s); 14 15 #include <stdio.h> 16 17 #include <string> 18 #include <stdexcept> 19 #include <algorithm> 20 #include <cassert> 21 22 #include "min_allocator.h" 23 24 template <class S> 25 void 26 test(S s, typename S::size_type pos, typename S::size_type n1, 27 const typename S::value_type* str, S expected) 28 { 29 typename S::size_type old_size = s.size(); 30 S s0 = s; 31 try 32 { 33 s.replace(pos, n1, str); 34 assert(s.__invariants()); 35 assert(pos <= old_size); 36 assert(s == expected); 37 typename S::size_type xlen = std::min(n1, old_size - pos); 38 typename S::size_type rlen = S::traits_type::length(str); 39 assert(s.size() == old_size - xlen + rlen); 40 } 41 catch (std::out_of_range&) 42 { 43 assert(pos > old_size); 44 assert(s == s0); 45 } 46 } 47 48 template <class S> 49 void test0() 50 { 51 test(S(""), 0, 0, "", S("")); 52 test(S(""), 0, 0, "12345", S("12345")); 53 test(S(""), 0, 0, "1234567890", S("1234567890")); 54 test(S(""), 0, 0, "12345678901234567890", S("12345678901234567890")); 55 test(S(""), 0, 1, "", S("")); 56 test(S(""), 0, 1, "12345", S("12345")); 57 test(S(""), 0, 1, "1234567890", S("1234567890")); 58 test(S(""), 0, 1, "12345678901234567890", S("12345678901234567890")); 59 test(S(""), 1, 0, "", S("can't happen")); 60 test(S(""), 1, 0, "12345", S("can't happen")); 61 test(S(""), 1, 0, "1234567890", S("can't happen")); 62 test(S(""), 1, 0, "12345678901234567890", S("can't happen")); 63 test(S("abcde"), 0, 0, "", S("abcde")); 64 test(S("abcde"), 0, 0, "12345", S("12345abcde")); 65 test(S("abcde"), 0, 0, "1234567890", S("1234567890abcde")); 66 test(S("abcde"), 0, 0, "12345678901234567890", S("12345678901234567890abcde")); 67 test(S("abcde"), 0, 1, "", S("bcde")); 68 test(S("abcde"), 0, 1, "12345", S("12345bcde")); 69 test(S("abcde"), 0, 1, "1234567890", S("1234567890bcde")); 70 test(S("abcde"), 0, 1, "12345678901234567890", S("12345678901234567890bcde")); 71 test(S("abcde"), 0, 2, "", S("cde")); 72 test(S("abcde"), 0, 2, "12345", S("12345cde")); 73 test(S("abcde"), 0, 2, "1234567890", S("1234567890cde")); 74 test(S("abcde"), 0, 2, "12345678901234567890", S("12345678901234567890cde")); 75 test(S("abcde"), 0, 4, "", S("e")); 76 test(S("abcde"), 0, 4, "12345", S("12345e")); 77 test(S("abcde"), 0, 4, "1234567890", S("1234567890e")); 78 test(S("abcde"), 0, 4, "12345678901234567890", S("12345678901234567890e")); 79 test(S("abcde"), 0, 5, "", S("")); 80 test(S("abcde"), 0, 5, "12345", S("12345")); 81 test(S("abcde"), 0, 5, "1234567890", S("1234567890")); 82 test(S("abcde"), 0, 5, "12345678901234567890", S("12345678901234567890")); 83 test(S("abcde"), 0, 6, "", S("")); 84 test(S("abcde"), 0, 6, "12345", S("12345")); 85 test(S("abcde"), 0, 6, "1234567890", S("1234567890")); 86 test(S("abcde"), 0, 6, "12345678901234567890", S("12345678901234567890")); 87 test(S("abcde"), 1, 0, "", S("abcde")); 88 test(S("abcde"), 1, 0, "12345", S("a12345bcde")); 89 test(S("abcde"), 1, 0, "1234567890", S("a1234567890bcde")); 90 test(S("abcde"), 1, 0, "12345678901234567890", S("a12345678901234567890bcde")); 91 test(S("abcde"), 1, 1, "", S("acde")); 92 test(S("abcde"), 1, 1, "12345", S("a12345cde")); 93 test(S("abcde"), 1, 1, "1234567890", S("a1234567890cde")); 94 test(S("abcde"), 1, 1, "12345678901234567890", S("a12345678901234567890cde")); 95 test(S("abcde"), 1, 2, "", S("ade")); 96 test(S("abcde"), 1, 2, "12345", S("a12345de")); 97 test(S("abcde"), 1, 2, "1234567890", S("a1234567890de")); 98 test(S("abcde"), 1, 2, "12345678901234567890", S("a12345678901234567890de")); 99 test(S("abcde"), 1, 3, "", S("ae")); 100 test(S("abcde"), 1, 3, "12345", S("a12345e")); 101 test(S("abcde"), 1, 3, "1234567890", S("a1234567890e")); 102 test(S("abcde"), 1, 3, "12345678901234567890", S("a12345678901234567890e")); 103 test(S("abcde"), 1, 4, "", S("a")); 104 test(S("abcde"), 1, 4, "12345", S("a12345")); 105 test(S("abcde"), 1, 4, "1234567890", S("a1234567890")); 106 test(S("abcde"), 1, 4, "12345678901234567890", S("a12345678901234567890")); 107 test(S("abcde"), 1, 5, "", S("a")); 108 test(S("abcde"), 1, 5, "12345", S("a12345")); 109 test(S("abcde"), 1, 5, "1234567890", S("a1234567890")); 110 test(S("abcde"), 1, 5, "12345678901234567890", S("a12345678901234567890")); 111 test(S("abcde"), 2, 0, "", S("abcde")); 112 test(S("abcde"), 2, 0, "12345", S("ab12345cde")); 113 test(S("abcde"), 2, 0, "1234567890", S("ab1234567890cde")); 114 test(S("abcde"), 2, 0, "12345678901234567890", S("ab12345678901234567890cde")); 115 test(S("abcde"), 2, 1, "", S("abde")); 116 test(S("abcde"), 2, 1, "12345", S("ab12345de")); 117 test(S("abcde"), 2, 1, "1234567890", S("ab1234567890de")); 118 test(S("abcde"), 2, 1, "12345678901234567890", S("ab12345678901234567890de")); 119 test(S("abcde"), 2, 2, "", S("abe")); 120 test(S("abcde"), 2, 2, "12345", S("ab12345e")); 121 test(S("abcde"), 2, 2, "1234567890", S("ab1234567890e")); 122 test(S("abcde"), 2, 2, "12345678901234567890", S("ab12345678901234567890e")); 123 test(S("abcde"), 2, 3, "", S("ab")); 124 test(S("abcde"), 2, 3, "12345", S("ab12345")); 125 test(S("abcde"), 2, 3, "1234567890", S("ab1234567890")); 126 test(S("abcde"), 2, 3, "12345678901234567890", S("ab12345678901234567890")); 127 test(S("abcde"), 2, 4, "", S("ab")); 128 test(S("abcde"), 2, 4, "12345", S("ab12345")); 129 test(S("abcde"), 2, 4, "1234567890", S("ab1234567890")); 130 test(S("abcde"), 2, 4, "12345678901234567890", S("ab12345678901234567890")); 131 test(S("abcde"), 4, 0, "", S("abcde")); 132 test(S("abcde"), 4, 0, "12345", S("abcd12345e")); 133 test(S("abcde"), 4, 0, "1234567890", S("abcd1234567890e")); 134 test(S("abcde"), 4, 0, "12345678901234567890", S("abcd12345678901234567890e")); 135 test(S("abcde"), 4, 1, "", S("abcd")); 136 test(S("abcde"), 4, 1, "12345", S("abcd12345")); 137 test(S("abcde"), 4, 1, "1234567890", S("abcd1234567890")); 138 test(S("abcde"), 4, 1, "12345678901234567890", S("abcd12345678901234567890")); 139 test(S("abcde"), 4, 2, "", S("abcd")); 140 test(S("abcde"), 4, 2, "12345", S("abcd12345")); 141 test(S("abcde"), 4, 2, "1234567890", S("abcd1234567890")); 142 test(S("abcde"), 4, 2, "12345678901234567890", S("abcd12345678901234567890")); 143 test(S("abcde"), 5, 0, "", S("abcde")); 144 test(S("abcde"), 5, 0, "12345", S("abcde12345")); 145 test(S("abcde"), 5, 0, "1234567890", S("abcde1234567890")); 146 test(S("abcde"), 5, 0, "12345678901234567890", S("abcde12345678901234567890")); 147 test(S("abcde"), 5, 1, "", S("abcde")); 148 test(S("abcde"), 5, 1, "12345", S("abcde12345")); 149 test(S("abcde"), 5, 1, "1234567890", S("abcde1234567890")); 150 test(S("abcde"), 5, 1, "12345678901234567890", S("abcde12345678901234567890")); 151 } 152 153 template <class S> 154 void test1() 155 { 156 test(S("abcde"), 6, 0, "", S("can't happen")); 157 test(S("abcde"), 6, 0, "12345", S("can't happen")); 158 test(S("abcde"), 6, 0, "1234567890", S("can't happen")); 159 test(S("abcde"), 6, 0, "12345678901234567890", S("can't happen")); 160 test(S("abcdefghij"), 0, 0, "", S("abcdefghij")); 161 test(S("abcdefghij"), 0, 0, "12345", S("12345abcdefghij")); 162 test(S("abcdefghij"), 0, 0, "1234567890", S("1234567890abcdefghij")); 163 test(S("abcdefghij"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghij")); 164 test(S("abcdefghij"), 0, 1, "", S("bcdefghij")); 165 test(S("abcdefghij"), 0, 1, "12345", S("12345bcdefghij")); 166 test(S("abcdefghij"), 0, 1, "1234567890", S("1234567890bcdefghij")); 167 test(S("abcdefghij"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghij")); 168 test(S("abcdefghij"), 0, 5, "", S("fghij")); 169 test(S("abcdefghij"), 0, 5, "12345", S("12345fghij")); 170 test(S("abcdefghij"), 0, 5, "1234567890", S("1234567890fghij")); 171 test(S("abcdefghij"), 0, 5, "12345678901234567890", S("12345678901234567890fghij")); 172 test(S("abcdefghij"), 0, 9, "", S("j")); 173 test(S("abcdefghij"), 0, 9, "12345", S("12345j")); 174 test(S("abcdefghij"), 0, 9, "1234567890", S("1234567890j")); 175 test(S("abcdefghij"), 0, 9, "12345678901234567890", S("12345678901234567890j")); 176 test(S("abcdefghij"), 0, 10, "", S("")); 177 test(S("abcdefghij"), 0, 10, "12345", S("12345")); 178 test(S("abcdefghij"), 0, 10, "1234567890", S("1234567890")); 179 test(S("abcdefghij"), 0, 10, "12345678901234567890", S("12345678901234567890")); 180 test(S("abcdefghij"), 0, 11, "", S("")); 181 test(S("abcdefghij"), 0, 11, "12345", S("12345")); 182 test(S("abcdefghij"), 0, 11, "1234567890", S("1234567890")); 183 test(S("abcdefghij"), 0, 11, "12345678901234567890", S("12345678901234567890")); 184 test(S("abcdefghij"), 1, 0, "", S("abcdefghij")); 185 test(S("abcdefghij"), 1, 0, "12345", S("a12345bcdefghij")); 186 test(S("abcdefghij"), 1, 0, "1234567890", S("a1234567890bcdefghij")); 187 test(S("abcdefghij"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghij")); 188 test(S("abcdefghij"), 1, 1, "", S("acdefghij")); 189 test(S("abcdefghij"), 1, 1, "12345", S("a12345cdefghij")); 190 test(S("abcdefghij"), 1, 1, "1234567890", S("a1234567890cdefghij")); 191 test(S("abcdefghij"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghij")); 192 test(S("abcdefghij"), 1, 4, "", S("afghij")); 193 test(S("abcdefghij"), 1, 4, "12345", S("a12345fghij")); 194 test(S("abcdefghij"), 1, 4, "1234567890", S("a1234567890fghij")); 195 test(S("abcdefghij"), 1, 4, "12345678901234567890", S("a12345678901234567890fghij")); 196 test(S("abcdefghij"), 1, 8, "", S("aj")); 197 test(S("abcdefghij"), 1, 8, "12345", S("a12345j")); 198 test(S("abcdefghij"), 1, 8, "1234567890", S("a1234567890j")); 199 test(S("abcdefghij"), 1, 8, "12345678901234567890", S("a12345678901234567890j")); 200 test(S("abcdefghij"), 1, 9, "", S("a")); 201 test(S("abcdefghij"), 1, 9, "12345", S("a12345")); 202 test(S("abcdefghij"), 1, 9, "1234567890", S("a1234567890")); 203 test(S("abcdefghij"), 1, 9, "12345678901234567890", S("a12345678901234567890")); 204 test(S("abcdefghij"), 1, 10, "", S("a")); 205 test(S("abcdefghij"), 1, 10, "12345", S("a12345")); 206 test(S("abcdefghij"), 1, 10, "1234567890", S("a1234567890")); 207 test(S("abcdefghij"), 1, 10, "12345678901234567890", S("a12345678901234567890")); 208 test(S("abcdefghij"), 5, 0, "", S("abcdefghij")); 209 test(S("abcdefghij"), 5, 0, "12345", S("abcde12345fghij")); 210 test(S("abcdefghij"), 5, 0, "1234567890", S("abcde1234567890fghij")); 211 test(S("abcdefghij"), 5, 0, "12345678901234567890", S("abcde12345678901234567890fghij")); 212 test(S("abcdefghij"), 5, 1, "", S("abcdeghij")); 213 test(S("abcdefghij"), 5, 1, "12345", S("abcde12345ghij")); 214 test(S("abcdefghij"), 5, 1, "1234567890", S("abcde1234567890ghij")); 215 test(S("abcdefghij"), 5, 1, "12345678901234567890", S("abcde12345678901234567890ghij")); 216 test(S("abcdefghij"), 5, 2, "", S("abcdehij")); 217 test(S("abcdefghij"), 5, 2, "12345", S("abcde12345hij")); 218 test(S("abcdefghij"), 5, 2, "1234567890", S("abcde1234567890hij")); 219 test(S("abcdefghij"), 5, 2, "12345678901234567890", S("abcde12345678901234567890hij")); 220 test(S("abcdefghij"), 5, 4, "", S("abcdej")); 221 test(S("abcdefghij"), 5, 4, "12345", S("abcde12345j")); 222 test(S("abcdefghij"), 5, 4, "1234567890", S("abcde1234567890j")); 223 test(S("abcdefghij"), 5, 4, "12345678901234567890", S("abcde12345678901234567890j")); 224 test(S("abcdefghij"), 5, 5, "", S("abcde")); 225 test(S("abcdefghij"), 5, 5, "12345", S("abcde12345")); 226 test(S("abcdefghij"), 5, 5, "1234567890", S("abcde1234567890")); 227 test(S("abcdefghij"), 5, 5, "12345678901234567890", S("abcde12345678901234567890")); 228 test(S("abcdefghij"), 5, 6, "", S("abcde")); 229 test(S("abcdefghij"), 5, 6, "12345", S("abcde12345")); 230 test(S("abcdefghij"), 5, 6, "1234567890", S("abcde1234567890")); 231 test(S("abcdefghij"), 5, 6, "12345678901234567890", S("abcde12345678901234567890")); 232 test(S("abcdefghij"), 9, 0, "", S("abcdefghij")); 233 test(S("abcdefghij"), 9, 0, "12345", S("abcdefghi12345j")); 234 test(S("abcdefghij"), 9, 0, "1234567890", S("abcdefghi1234567890j")); 235 test(S("abcdefghij"), 9, 0, "12345678901234567890", S("abcdefghi12345678901234567890j")); 236 test(S("abcdefghij"), 9, 1, "", S("abcdefghi")); 237 test(S("abcdefghij"), 9, 1, "12345", S("abcdefghi12345")); 238 test(S("abcdefghij"), 9, 1, "1234567890", S("abcdefghi1234567890")); 239 test(S("abcdefghij"), 9, 1, "12345678901234567890", S("abcdefghi12345678901234567890")); 240 test(S("abcdefghij"), 9, 2, "", S("abcdefghi")); 241 test(S("abcdefghij"), 9, 2, "12345", S("abcdefghi12345")); 242 test(S("abcdefghij"), 9, 2, "1234567890", S("abcdefghi1234567890")); 243 test(S("abcdefghij"), 9, 2, "12345678901234567890", S("abcdefghi12345678901234567890")); 244 test(S("abcdefghij"), 10, 0, "", S("abcdefghij")); 245 test(S("abcdefghij"), 10, 0, "12345", S("abcdefghij12345")); 246 test(S("abcdefghij"), 10, 0, "1234567890", S("abcdefghij1234567890")); 247 test(S("abcdefghij"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890")); 248 test(S("abcdefghij"), 10, 1, "", S("abcdefghij")); 249 test(S("abcdefghij"), 10, 1, "12345", S("abcdefghij12345")); 250 test(S("abcdefghij"), 10, 1, "1234567890", S("abcdefghij1234567890")); 251 test(S("abcdefghij"), 10, 1, "12345678901234567890", S("abcdefghij12345678901234567890")); 252 test(S("abcdefghij"), 11, 0, "", S("can't happen")); 253 test(S("abcdefghij"), 11, 0, "12345", S("can't happen")); 254 test(S("abcdefghij"), 11, 0, "1234567890", S("can't happen")); 255 test(S("abcdefghij"), 11, 0, "12345678901234567890", S("can't happen")); 256 } 257 258 template <class S> 259 void test2() 260 { 261 test(S("abcdefghijklmnopqrst"), 0, 0, "", S("abcdefghijklmnopqrst")); 262 test(S("abcdefghijklmnopqrst"), 0, 0, "12345", S("12345abcdefghijklmnopqrst")); 263 test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", S("1234567890abcdefghijklmnopqrst")); 264 test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst")); 265 test(S("abcdefghijklmnopqrst"), 0, 1, "", S("bcdefghijklmnopqrst")); 266 test(S("abcdefghijklmnopqrst"), 0, 1, "12345", S("12345bcdefghijklmnopqrst")); 267 test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", S("1234567890bcdefghijklmnopqrst")); 268 test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghijklmnopqrst")); 269 test(S("abcdefghijklmnopqrst"), 0, 10, "", S("klmnopqrst")); 270 test(S("abcdefghijklmnopqrst"), 0, 10, "12345", S("12345klmnopqrst")); 271 test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", S("1234567890klmnopqrst")); 272 test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", S("12345678901234567890klmnopqrst")); 273 test(S("abcdefghijklmnopqrst"), 0, 19, "", S("t")); 274 test(S("abcdefghijklmnopqrst"), 0, 19, "12345", S("12345t")); 275 test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", S("1234567890t")); 276 test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", S("12345678901234567890t")); 277 test(S("abcdefghijklmnopqrst"), 0, 20, "", S("")); 278 test(S("abcdefghijklmnopqrst"), 0, 20, "12345", S("12345")); 279 test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", S("1234567890")); 280 test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", S("12345678901234567890")); 281 test(S("abcdefghijklmnopqrst"), 0, 21, "", S("")); 282 test(S("abcdefghijklmnopqrst"), 0, 21, "12345", S("12345")); 283 test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", S("1234567890")); 284 test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", S("12345678901234567890")); 285 test(S("abcdefghijklmnopqrst"), 1, 0, "", S("abcdefghijklmnopqrst")); 286 test(S("abcdefghijklmnopqrst"), 1, 0, "12345", S("a12345bcdefghijklmnopqrst")); 287 test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", S("a1234567890bcdefghijklmnopqrst")); 288 test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst")); 289 test(S("abcdefghijklmnopqrst"), 1, 1, "", S("acdefghijklmnopqrst")); 290 test(S("abcdefghijklmnopqrst"), 1, 1, "12345", S("a12345cdefghijklmnopqrst")); 291 test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", S("a1234567890cdefghijklmnopqrst")); 292 test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghijklmnopqrst")); 293 test(S("abcdefghijklmnopqrst"), 1, 9, "", S("aklmnopqrst")); 294 test(S("abcdefghijklmnopqrst"), 1, 9, "12345", S("a12345klmnopqrst")); 295 test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", S("a1234567890klmnopqrst")); 296 test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", S("a12345678901234567890klmnopqrst")); 297 test(S("abcdefghijklmnopqrst"), 1, 18, "", S("at")); 298 test(S("abcdefghijklmnopqrst"), 1, 18, "12345", S("a12345t")); 299 test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", S("a1234567890t")); 300 test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", S("a12345678901234567890t")); 301 test(S("abcdefghijklmnopqrst"), 1, 19, "", S("a")); 302 test(S("abcdefghijklmnopqrst"), 1, 19, "12345", S("a12345")); 303 test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", S("a1234567890")); 304 test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", S("a12345678901234567890")); 305 test(S("abcdefghijklmnopqrst"), 1, 20, "", S("a")); 306 test(S("abcdefghijklmnopqrst"), 1, 20, "12345", S("a12345")); 307 test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", S("a1234567890")); 308 test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", S("a12345678901234567890")); 309 test(S("abcdefghijklmnopqrst"), 10, 0, "", S("abcdefghijklmnopqrst")); 310 test(S("abcdefghijklmnopqrst"), 10, 0, "12345", S("abcdefghij12345klmnopqrst")); 311 test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", S("abcdefghij1234567890klmnopqrst")); 312 test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst")); 313 test(S("abcdefghijklmnopqrst"), 10, 1, "", S("abcdefghijlmnopqrst")); 314 test(S("abcdefghijklmnopqrst"), 10, 1, "12345", S("abcdefghij12345lmnopqrst")); 315 test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", S("abcdefghij1234567890lmnopqrst")); 316 test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", S("abcdefghij12345678901234567890lmnopqrst")); 317 test(S("abcdefghijklmnopqrst"), 10, 5, "", S("abcdefghijpqrst")); 318 test(S("abcdefghijklmnopqrst"), 10, 5, "12345", S("abcdefghij12345pqrst")); 319 test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", S("abcdefghij1234567890pqrst")); 320 test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", S("abcdefghij12345678901234567890pqrst")); 321 test(S("abcdefghijklmnopqrst"), 10, 9, "", S("abcdefghijt")); 322 test(S("abcdefghijklmnopqrst"), 10, 9, "12345", S("abcdefghij12345t")); 323 test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", S("abcdefghij1234567890t")); 324 test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", S("abcdefghij12345678901234567890t")); 325 test(S("abcdefghijklmnopqrst"), 10, 10, "", S("abcdefghij")); 326 test(S("abcdefghijklmnopqrst"), 10, 10, "12345", S("abcdefghij12345")); 327 test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", S("abcdefghij1234567890")); 328 test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", S("abcdefghij12345678901234567890")); 329 test(S("abcdefghijklmnopqrst"), 10, 11, "", S("abcdefghij")); 330 test(S("abcdefghijklmnopqrst"), 10, 11, "12345", S("abcdefghij12345")); 331 test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", S("abcdefghij1234567890")); 332 test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", S("abcdefghij12345678901234567890")); 333 test(S("abcdefghijklmnopqrst"), 19, 0, "", S("abcdefghijklmnopqrst")); 334 test(S("abcdefghijklmnopqrst"), 19, 0, "12345", S("abcdefghijklmnopqrs12345t")); 335 test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", S("abcdefghijklmnopqrs1234567890t")); 336 test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t")); 337 test(S("abcdefghijklmnopqrst"), 19, 1, "", S("abcdefghijklmnopqrs")); 338 test(S("abcdefghijklmnopqrst"), 19, 1, "12345", S("abcdefghijklmnopqrs12345")); 339 test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", S("abcdefghijklmnopqrs1234567890")); 340 test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890")); 341 test(S("abcdefghijklmnopqrst"), 19, 2, "", S("abcdefghijklmnopqrs")); 342 test(S("abcdefghijklmnopqrst"), 19, 2, "12345", S("abcdefghijklmnopqrs12345")); 343 test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", S("abcdefghijklmnopqrs1234567890")); 344 test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890")); 345 test(S("abcdefghijklmnopqrst"), 20, 0, "", S("abcdefghijklmnopqrst")); 346 test(S("abcdefghijklmnopqrst"), 20, 0, "12345", S("abcdefghijklmnopqrst12345")); 347 test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", S("abcdefghijklmnopqrst1234567890")); 348 test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890")); 349 test(S("abcdefghijklmnopqrst"), 20, 1, "", S("abcdefghijklmnopqrst")); 350 test(S("abcdefghijklmnopqrst"), 20, 1, "12345", S("abcdefghijklmnopqrst12345")); 351 test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", S("abcdefghijklmnopqrst1234567890")); 352 test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890")); 353 test(S("abcdefghijklmnopqrst"), 21, 0, "", S("can't happen")); 354 test(S("abcdefghijklmnopqrst"), 21, 0, "12345", S("can't happen")); 355 test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", S("can't happen")); 356 test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", S("can't happen")); 357 } 358 359 int main() 360 { 361 { 362 typedef std::string S; 363 test0<S>(); 364 test1<S>(); 365 test2<S>(); 366 } 367 #if __cplusplus >= 201103L 368 { 369 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 370 test0<S>(); 371 test1<S>(); 372 test2<S>(); 373 } 374 #endif 375 } 376