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