1 //===----------------------------------------------------------------------===//
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 // <string>
10 
11 // template <class T>
12 //    basic_string& replace(size_type pos1, size_type n1, const T& t,
13 //                          size_type pos2, size_type n=npos);
14 //
15 //  Mostly we're testing string_view here
16 
17 #include <string>
18 #include <stdexcept>
19 #include <algorithm>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "min_allocator.h"
24 
25 template <class S, class SV>
26 void
test(S s,typename S::size_type pos1,typename S::size_type n1,SV sv,typename S::size_type pos2,typename S::size_type n2,S expected)27 test(S s, typename S::size_type pos1, typename S::size_type n1,
28      SV sv, typename S::size_type pos2, typename S::size_type n2,
29      S expected)
30 {
31     typedef typename S::size_type SizeT;
32     static_assert((!std::is_same<S, SV>::value), "");
33 
34     // String and string_view may not always share the same size type,
35     // but both types should have the same size (ex. int vs long)
36     static_assert(sizeof(SizeT) == sizeof(typename SV::size_type), "");
37 
38     const SizeT old_size = s.size();
39     S s0 = s;
40     if (pos1 <= old_size && pos2 <= sv.size())
41     {
42         s.replace(pos1, n1, sv, pos2, n2);
43         LIBCPP_ASSERT(s.__invariants());
44         assert(s == expected);
45         SizeT xlen = std::min<SizeT>(n1, old_size - pos1);
46         SizeT rlen = std::min<SizeT>(n2, sv.size() - pos2);
47         assert(s.size() == old_size - xlen + rlen);
48     }
49 #ifndef TEST_HAS_NO_EXCEPTIONS
50     else
51     {
52         try
53         {
54             s.replace(pos1, n1, sv, pos2, n2);
55             assert(false);
56         }
57         catch (std::out_of_range&)
58         {
59             assert(pos1 > old_size || pos2 > sv.size());
60             assert(s == s0);
61         }
62     }
63 #endif
64 }
65 
66 template <class S, class SV>
67 void
test_npos(S s,typename S::size_type pos1,typename S::size_type n1,SV sv,typename S::size_type pos2,S expected)68 test_npos(S s, typename S::size_type pos1, typename S::size_type n1,
69           SV sv, typename S::size_type pos2,
70           S expected)
71 {
72     typedef typename S::size_type SizeT;
73     static_assert((!std::is_same<S, SV>::value), "");
74     const SizeT old_size = s.size();
75     S s0 = s;
76     if (pos1 <= old_size && pos2 <= sv.size())
77     {
78         s.replace(pos1, n1, sv, pos2);
79         LIBCPP_ASSERT(s.__invariants());
80         assert(s == expected);
81         SizeT xlen = std::min<SizeT>(n1, old_size - pos1);
82         SizeT rlen = std::min<SizeT>(S::npos, sv.size() - pos2);
83         assert(s.size() == old_size - xlen + rlen);
84     }
85 #ifndef TEST_HAS_NO_EXCEPTIONS
86     else
87     {
88         try
89         {
90             s.replace(pos1, n1, sv, pos2);
91             assert(false);
92         }
93         catch (std::out_of_range&)
94         {
95             assert(pos1 > old_size || pos2 > sv.size());
96             assert(s == s0);
97         }
98     }
99 #endif
100 }
101 
102 
103 template <class S, class SV>
test0()104 void test0()
105 {
106     test(S(""), 0, 0, SV(""), 0, 0, S(""));
107     test(S(""), 0, 0, SV(""), 0, 1, S(""));
108     test(S(""), 0, 0, SV(""), 1, 0, S("can't happen"));
109     test(S(""), 0, 0, SV("12345"), 0, 0, S(""));
110     test(S(""), 0, 0, SV("12345"), 0, 1, S("1"));
111     test(S(""), 0, 0, SV("12345"), 0, 2, S("12"));
112     test(S(""), 0, 0, SV("12345"), 0, 4, S("1234"));
113     test(S(""), 0, 0, SV("12345"), 0, 5, S("12345"));
114     test(S(""), 0, 0, SV("12345"), 0, 6, S("12345"));
115     test(S(""), 0, 0, SV("12345"), 1, 0, S(""));
116     test(S(""), 0, 0, SV("12345"), 1, 1, S("2"));
117     test(S(""), 0, 0, SV("12345"), 1, 2, S("23"));
118     test(S(""), 0, 0, SV("12345"), 1, 3, S("234"));
119     test(S(""), 0, 0, SV("12345"), 1, 4, S("2345"));
120     test(S(""), 0, 0, SV("12345"), 1, 5, S("2345"));
121     test(S(""), 0, 0, SV("12345"), 2, 0, S(""));
122     test(S(""), 0, 0, SV("12345"), 2, 1, S("3"));
123     test(S(""), 0, 0, SV("12345"), 2, 2, S("34"));
124     test(S(""), 0, 0, SV("12345"), 2, 3, S("345"));
125     test(S(""), 0, 0, SV("12345"), 2, 4, S("345"));
126     test(S(""), 0, 0, SV("12345"), 4, 0, S(""));
127     test(S(""), 0, 0, SV("12345"), 4, 1, S("5"));
128     test(S(""), 0, 0, SV("12345"), 4, 2, S("5"));
129     test(S(""), 0, 0, SV("12345"), 5, 0, S(""));
130     test(S(""), 0, 0, SV("12345"), 5, 1, S(""));
131     test(S(""), 0, 0, SV("12345"), 6, 0, S("can't happen"));
132     test(S(""), 0, 0, SV("1234567890"), 0, 0, S(""));
133     test(S(""), 0, 0, SV("1234567890"), 0, 1, S("1"));
134     test(S(""), 0, 0, SV("1234567890"), 0, 5, S("12345"));
135     test(S(""), 0, 0, SV("1234567890"), 0, 9, S("123456789"));
136     test(S(""), 0, 0, SV("1234567890"), 0, 10, S("1234567890"));
137     test(S(""), 0, 0, SV("1234567890"), 0, 11, S("1234567890"));
138     test(S(""), 0, 0, SV("1234567890"), 1, 0, S(""));
139     test(S(""), 0, 0, SV("1234567890"), 1, 1, S("2"));
140     test(S(""), 0, 0, SV("1234567890"), 1, 4, S("2345"));
141     test(S(""), 0, 0, SV("1234567890"), 1, 8, S("23456789"));
142     test(S(""), 0, 0, SV("1234567890"), 1, 9, S("234567890"));
143     test(S(""), 0, 0, SV("1234567890"), 1, 10, S("234567890"));
144     test(S(""), 0, 0, SV("1234567890"), 5, 0, S(""));
145     test(S(""), 0, 0, SV("1234567890"), 5, 1, S("6"));
146     test(S(""), 0, 0, SV("1234567890"), 5, 2, S("67"));
147     test(S(""), 0, 0, SV("1234567890"), 5, 4, S("6789"));
148     test(S(""), 0, 0, SV("1234567890"), 5, 5, S("67890"));
149     test(S(""), 0, 0, SV("1234567890"), 5, 6, S("67890"));
150     test(S(""), 0, 0, SV("1234567890"), 9, 0, S(""));
151     test(S(""), 0, 0, SV("1234567890"), 9, 1, S("0"));
152     test(S(""), 0, 0, SV("1234567890"), 9, 2, S("0"));
153     test(S(""), 0, 0, SV("1234567890"), 10, 0, S(""));
154     test(S(""), 0, 0, SV("1234567890"), 10, 1, S(""));
155     test(S(""), 0, 0, SV("1234567890"), 11, 0, S("can't happen"));
156     test(S(""), 0, 0, SV("12345678901234567890"), 0, 0, S(""));
157     test(S(""), 0, 0, SV("12345678901234567890"), 0, 1, S("1"));
158     test(S(""), 0, 0, SV("12345678901234567890"), 0, 10, S("1234567890"));
159     test(S(""), 0, 0, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
160     test(S(""), 0, 0, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
161     test(S(""), 0, 0, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
162     test(S(""), 0, 0, SV("12345678901234567890"), 1, 0, S(""));
163     test(S(""), 0, 0, SV("12345678901234567890"), 1, 1, S("2"));
164     test(S(""), 0, 0, SV("12345678901234567890"), 1, 9, S("234567890"));
165     test(S(""), 0, 0, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
166     test(S(""), 0, 0, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
167     test(S(""), 0, 0, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
168     test(S(""), 0, 0, SV("12345678901234567890"), 10, 0, S(""));
169     test(S(""), 0, 0, SV("12345678901234567890"), 10, 1, S("1"));
170     test(S(""), 0, 0, SV("12345678901234567890"), 10, 5, S("12345"));
171     test(S(""), 0, 0, SV("12345678901234567890"), 10, 9, S("123456789"));
172     test(S(""), 0, 0, SV("12345678901234567890"), 10, 10, S("1234567890"));
173     test(S(""), 0, 0, SV("12345678901234567890"), 10, 11, S("1234567890"));
174     test(S(""), 0, 0, SV("12345678901234567890"), 19, 0, S(""));
175     test(S(""), 0, 0, SV("12345678901234567890"), 19, 1, S("0"));
176     test(S(""), 0, 0, SV("12345678901234567890"), 19, 2, S("0"));
177     test(S(""), 0, 0, SV("12345678901234567890"), 20, 0, S(""));
178     test(S(""), 0, 0, SV("12345678901234567890"), 20, 1, S(""));
179     test(S(""), 0, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
180     test(S(""), 0, 1, SV(""), 0, 0, S(""));
181     test(S(""), 0, 1, SV(""), 0, 1, S(""));
182     test(S(""), 0, 1, SV(""), 1, 0, S("can't happen"));
183     test(S(""), 0, 1, SV("12345"), 0, 0, S(""));
184     test(S(""), 0, 1, SV("12345"), 0, 1, S("1"));
185     test(S(""), 0, 1, SV("12345"), 0, 2, S("12"));
186     test(S(""), 0, 1, SV("12345"), 0, 4, S("1234"));
187     test(S(""), 0, 1, SV("12345"), 0, 5, S("12345"));
188     test(S(""), 0, 1, SV("12345"), 0, 6, S("12345"));
189     test(S(""), 0, 1, SV("12345"), 1, 0, S(""));
190     test(S(""), 0, 1, SV("12345"), 1, 1, S("2"));
191     test(S(""), 0, 1, SV("12345"), 1, 2, S("23"));
192     test(S(""), 0, 1, SV("12345"), 1, 3, S("234"));
193     test(S(""), 0, 1, SV("12345"), 1, 4, S("2345"));
194     test(S(""), 0, 1, SV("12345"), 1, 5, S("2345"));
195     test(S(""), 0, 1, SV("12345"), 2, 0, S(""));
196     test(S(""), 0, 1, SV("12345"), 2, 1, S("3"));
197     test(S(""), 0, 1, SV("12345"), 2, 2, S("34"));
198     test(S(""), 0, 1, SV("12345"), 2, 3, S("345"));
199     test(S(""), 0, 1, SV("12345"), 2, 4, S("345"));
200     test(S(""), 0, 1, SV("12345"), 4, 0, S(""));
201     test(S(""), 0, 1, SV("12345"), 4, 1, S("5"));
202     test(S(""), 0, 1, SV("12345"), 4, 2, S("5"));
203     test(S(""), 0, 1, SV("12345"), 5, 0, S(""));
204     test(S(""), 0, 1, SV("12345"), 5, 1, S(""));
205     test(S(""), 0, 1, SV("12345"), 6, 0, S("can't happen"));
206 }
207 
208 template <class S, class SV>
test1()209 void test1()
210 {
211     test(S(""), 0, 1, SV("1234567890"), 0, 0, S(""));
212     test(S(""), 0, 1, SV("1234567890"), 0, 1, S("1"));
213     test(S(""), 0, 1, SV("1234567890"), 0, 5, S("12345"));
214     test(S(""), 0, 1, SV("1234567890"), 0, 9, S("123456789"));
215     test(S(""), 0, 1, SV("1234567890"), 0, 10, S("1234567890"));
216     test(S(""), 0, 1, SV("1234567890"), 0, 11, S("1234567890"));
217     test(S(""), 0, 1, SV("1234567890"), 1, 0, S(""));
218     test(S(""), 0, 1, SV("1234567890"), 1, 1, S("2"));
219     test(S(""), 0, 1, SV("1234567890"), 1, 4, S("2345"));
220     test(S(""), 0, 1, SV("1234567890"), 1, 8, S("23456789"));
221     test(S(""), 0, 1, SV("1234567890"), 1, 9, S("234567890"));
222     test(S(""), 0, 1, SV("1234567890"), 1, 10, S("234567890"));
223     test(S(""), 0, 1, SV("1234567890"), 5, 0, S(""));
224     test(S(""), 0, 1, SV("1234567890"), 5, 1, S("6"));
225     test(S(""), 0, 1, SV("1234567890"), 5, 2, S("67"));
226     test(S(""), 0, 1, SV("1234567890"), 5, 4, S("6789"));
227     test(S(""), 0, 1, SV("1234567890"), 5, 5, S("67890"));
228     test(S(""), 0, 1, SV("1234567890"), 5, 6, S("67890"));
229     test(S(""), 0, 1, SV("1234567890"), 9, 0, S(""));
230     test(S(""), 0, 1, SV("1234567890"), 9, 1, S("0"));
231     test(S(""), 0, 1, SV("1234567890"), 9, 2, S("0"));
232     test(S(""), 0, 1, SV("1234567890"), 10, 0, S(""));
233     test(S(""), 0, 1, SV("1234567890"), 10, 1, S(""));
234     test(S(""), 0, 1, SV("1234567890"), 11, 0, S("can't happen"));
235     test(S(""), 0, 1, SV("12345678901234567890"), 0, 0, S(""));
236     test(S(""), 0, 1, SV("12345678901234567890"), 0, 1, S("1"));
237     test(S(""), 0, 1, SV("12345678901234567890"), 0, 10, S("1234567890"));
238     test(S(""), 0, 1, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
239     test(S(""), 0, 1, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
240     test(S(""), 0, 1, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
241     test(S(""), 0, 1, SV("12345678901234567890"), 1, 0, S(""));
242     test(S(""), 0, 1, SV("12345678901234567890"), 1, 1, S("2"));
243     test(S(""), 0, 1, SV("12345678901234567890"), 1, 9, S("234567890"));
244     test(S(""), 0, 1, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
245     test(S(""), 0, 1, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
246     test(S(""), 0, 1, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
247     test(S(""), 0, 1, SV("12345678901234567890"), 10, 0, S(""));
248     test(S(""), 0, 1, SV("12345678901234567890"), 10, 1, S("1"));
249     test(S(""), 0, 1, SV("12345678901234567890"), 10, 5, S("12345"));
250     test(S(""), 0, 1, SV("12345678901234567890"), 10, 9, S("123456789"));
251     test(S(""), 0, 1, SV("12345678901234567890"), 10, 10, S("1234567890"));
252     test(S(""), 0, 1, SV("12345678901234567890"), 10, 11, S("1234567890"));
253     test(S(""), 0, 1, SV("12345678901234567890"), 19, 0, S(""));
254     test(S(""), 0, 1, SV("12345678901234567890"), 19, 1, S("0"));
255     test(S(""), 0, 1, SV("12345678901234567890"), 19, 2, S("0"));
256     test(S(""), 0, 1, SV("12345678901234567890"), 20, 0, S(""));
257     test(S(""), 0, 1, SV("12345678901234567890"), 20, 1, S(""));
258     test(S(""), 0, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
259     test(S(""), 1, 0, SV(""), 0, 0, S("can't happen"));
260     test(S(""), 1, 0, SV(""), 0, 1, S("can't happen"));
261     test(S(""), 1, 0, SV(""), 1, 0, S("can't happen"));
262     test(S(""), 1, 0, SV("12345"), 0, 0, S("can't happen"));
263     test(S(""), 1, 0, SV("12345"), 0, 1, S("can't happen"));
264     test(S(""), 1, 0, SV("12345"), 0, 2, S("can't happen"));
265     test(S(""), 1, 0, SV("12345"), 0, 4, S("can't happen"));
266     test(S(""), 1, 0, SV("12345"), 0, 5, S("can't happen"));
267     test(S(""), 1, 0, SV("12345"), 0, 6, S("can't happen"));
268     test(S(""), 1, 0, SV("12345"), 1, 0, S("can't happen"));
269     test(S(""), 1, 0, SV("12345"), 1, 1, S("can't happen"));
270     test(S(""), 1, 0, SV("12345"), 1, 2, S("can't happen"));
271     test(S(""), 1, 0, SV("12345"), 1, 3, S("can't happen"));
272     test(S(""), 1, 0, SV("12345"), 1, 4, S("can't happen"));
273     test(S(""), 1, 0, SV("12345"), 1, 5, S("can't happen"));
274     test(S(""), 1, 0, SV("12345"), 2, 0, S("can't happen"));
275     test(S(""), 1, 0, SV("12345"), 2, 1, S("can't happen"));
276     test(S(""), 1, 0, SV("12345"), 2, 2, S("can't happen"));
277     test(S(""), 1, 0, SV("12345"), 2, 3, S("can't happen"));
278     test(S(""), 1, 0, SV("12345"), 2, 4, S("can't happen"));
279     test(S(""), 1, 0, SV("12345"), 4, 0, S("can't happen"));
280     test(S(""), 1, 0, SV("12345"), 4, 1, S("can't happen"));
281     test(S(""), 1, 0, SV("12345"), 4, 2, S("can't happen"));
282     test(S(""), 1, 0, SV("12345"), 5, 0, S("can't happen"));
283     test(S(""), 1, 0, SV("12345"), 5, 1, S("can't happen"));
284     test(S(""), 1, 0, SV("12345"), 6, 0, S("can't happen"));
285     test(S(""), 1, 0, SV("1234567890"), 0, 0, S("can't happen"));
286     test(S(""), 1, 0, SV("1234567890"), 0, 1, S("can't happen"));
287     test(S(""), 1, 0, SV("1234567890"), 0, 5, S("can't happen"));
288     test(S(""), 1, 0, SV("1234567890"), 0, 9, S("can't happen"));
289     test(S(""), 1, 0, SV("1234567890"), 0, 10, S("can't happen"));
290     test(S(""), 1, 0, SV("1234567890"), 0, 11, S("can't happen"));
291     test(S(""), 1, 0, SV("1234567890"), 1, 0, S("can't happen"));
292     test(S(""), 1, 0, SV("1234567890"), 1, 1, S("can't happen"));
293     test(S(""), 1, 0, SV("1234567890"), 1, 4, S("can't happen"));
294     test(S(""), 1, 0, SV("1234567890"), 1, 8, S("can't happen"));
295     test(S(""), 1, 0, SV("1234567890"), 1, 9, S("can't happen"));
296     test(S(""), 1, 0, SV("1234567890"), 1, 10, S("can't happen"));
297     test(S(""), 1, 0, SV("1234567890"), 5, 0, S("can't happen"));
298     test(S(""), 1, 0, SV("1234567890"), 5, 1, S("can't happen"));
299     test(S(""), 1, 0, SV("1234567890"), 5, 2, S("can't happen"));
300     test(S(""), 1, 0, SV("1234567890"), 5, 4, S("can't happen"));
301     test(S(""), 1, 0, SV("1234567890"), 5, 5, S("can't happen"));
302     test(S(""), 1, 0, SV("1234567890"), 5, 6, S("can't happen"));
303     test(S(""), 1, 0, SV("1234567890"), 9, 0, S("can't happen"));
304     test(S(""), 1, 0, SV("1234567890"), 9, 1, S("can't happen"));
305     test(S(""), 1, 0, SV("1234567890"), 9, 2, S("can't happen"));
306     test(S(""), 1, 0, SV("1234567890"), 10, 0, S("can't happen"));
307     test(S(""), 1, 0, SV("1234567890"), 10, 1, S("can't happen"));
308     test(S(""), 1, 0, SV("1234567890"), 11, 0, S("can't happen"));
309     test(S(""), 1, 0, SV("12345678901234567890"), 0, 0, S("can't happen"));
310     test(S(""), 1, 0, SV("12345678901234567890"), 0, 1, S("can't happen"));
311 }
312 
313 template <class S, class SV>
test2()314 void test2()
315 {
316     test(S(""), 1, 0, SV("12345678901234567890"), 0, 10, S("can't happen"));
317     test(S(""), 1, 0, SV("12345678901234567890"), 0, 19, S("can't happen"));
318     test(S(""), 1, 0, SV("12345678901234567890"), 0, 20, S("can't happen"));
319     test(S(""), 1, 0, SV("12345678901234567890"), 0, 21, S("can't happen"));
320     test(S(""), 1, 0, SV("12345678901234567890"), 1, 0, S("can't happen"));
321     test(S(""), 1, 0, SV("12345678901234567890"), 1, 1, S("can't happen"));
322     test(S(""), 1, 0, SV("12345678901234567890"), 1, 9, S("can't happen"));
323     test(S(""), 1, 0, SV("12345678901234567890"), 1, 18, S("can't happen"));
324     test(S(""), 1, 0, SV("12345678901234567890"), 1, 19, S("can't happen"));
325     test(S(""), 1, 0, SV("12345678901234567890"), 1, 20, S("can't happen"));
326     test(S(""), 1, 0, SV("12345678901234567890"), 10, 0, S("can't happen"));
327     test(S(""), 1, 0, SV("12345678901234567890"), 10, 1, S("can't happen"));
328     test(S(""), 1, 0, SV("12345678901234567890"), 10, 5, S("can't happen"));
329     test(S(""), 1, 0, SV("12345678901234567890"), 10, 9, S("can't happen"));
330     test(S(""), 1, 0, SV("12345678901234567890"), 10, 10, S("can't happen"));
331     test(S(""), 1, 0, SV("12345678901234567890"), 10, 11, S("can't happen"));
332     test(S(""), 1, 0, SV("12345678901234567890"), 19, 0, S("can't happen"));
333     test(S(""), 1, 0, SV("12345678901234567890"), 19, 1, S("can't happen"));
334     test(S(""), 1, 0, SV("12345678901234567890"), 19, 2, S("can't happen"));
335     test(S(""), 1, 0, SV("12345678901234567890"), 20, 0, S("can't happen"));
336     test(S(""), 1, 0, SV("12345678901234567890"), 20, 1, S("can't happen"));
337     test(S(""), 1, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
338     test(S("abcde"), 0, 0, SV(""), 0, 0, S("abcde"));
339     test(S("abcde"), 0, 0, SV(""), 0, 1, S("abcde"));
340     test(S("abcde"), 0, 0, SV(""), 1, 0, S("can't happen"));
341     test(S("abcde"), 0, 0, SV("12345"), 0, 0, S("abcde"));
342     test(S("abcde"), 0, 0, SV("12345"), 0, 1, S("1abcde"));
343     test(S("abcde"), 0, 0, SV("12345"), 0, 2, S("12abcde"));
344     test(S("abcde"), 0, 0, SV("12345"), 0, 4, S("1234abcde"));
345     test(S("abcde"), 0, 0, SV("12345"), 0, 5, S("12345abcde"));
346     test(S("abcde"), 0, 0, SV("12345"), 0, 6, S("12345abcde"));
347     test(S("abcde"), 0, 0, SV("12345"), 1, 0, S("abcde"));
348     test(S("abcde"), 0, 0, SV("12345"), 1, 1, S("2abcde"));
349     test(S("abcde"), 0, 0, SV("12345"), 1, 2, S("23abcde"));
350     test(S("abcde"), 0, 0, SV("12345"), 1, 3, S("234abcde"));
351     test(S("abcde"), 0, 0, SV("12345"), 1, 4, S("2345abcde"));
352     test(S("abcde"), 0, 0, SV("12345"), 1, 5, S("2345abcde"));
353     test(S("abcde"), 0, 0, SV("12345"), 2, 0, S("abcde"));
354     test(S("abcde"), 0, 0, SV("12345"), 2, 1, S("3abcde"));
355     test(S("abcde"), 0, 0, SV("12345"), 2, 2, S("34abcde"));
356     test(S("abcde"), 0, 0, SV("12345"), 2, 3, S("345abcde"));
357     test(S("abcde"), 0, 0, SV("12345"), 2, 4, S("345abcde"));
358     test(S("abcde"), 0, 0, SV("12345"), 4, 0, S("abcde"));
359     test(S("abcde"), 0, 0, SV("12345"), 4, 1, S("5abcde"));
360     test(S("abcde"), 0, 0, SV("12345"), 4, 2, S("5abcde"));
361     test(S("abcde"), 0, 0, SV("12345"), 5, 0, S("abcde"));
362     test(S("abcde"), 0, 0, SV("12345"), 5, 1, S("abcde"));
363     test(S("abcde"), 0, 0, SV("12345"), 6, 0, S("can't happen"));
364     test(S("abcde"), 0, 0, SV("1234567890"), 0, 0, S("abcde"));
365     test(S("abcde"), 0, 0, SV("1234567890"), 0, 1, S("1abcde"));
366     test(S("abcde"), 0, 0, SV("1234567890"), 0, 5, S("12345abcde"));
367     test(S("abcde"), 0, 0, SV("1234567890"), 0, 9, S("123456789abcde"));
368     test(S("abcde"), 0, 0, SV("1234567890"), 0, 10, S("1234567890abcde"));
369     test(S("abcde"), 0, 0, SV("1234567890"), 0, 11, S("1234567890abcde"));
370     test(S("abcde"), 0, 0, SV("1234567890"), 1, 0, S("abcde"));
371     test(S("abcde"), 0, 0, SV("1234567890"), 1, 1, S("2abcde"));
372     test(S("abcde"), 0, 0, SV("1234567890"), 1, 4, S("2345abcde"));
373     test(S("abcde"), 0, 0, SV("1234567890"), 1, 8, S("23456789abcde"));
374     test(S("abcde"), 0, 0, SV("1234567890"), 1, 9, S("234567890abcde"));
375     test(S("abcde"), 0, 0, SV("1234567890"), 1, 10, S("234567890abcde"));
376     test(S("abcde"), 0, 0, SV("1234567890"), 5, 0, S("abcde"));
377     test(S("abcde"), 0, 0, SV("1234567890"), 5, 1, S("6abcde"));
378     test(S("abcde"), 0, 0, SV("1234567890"), 5, 2, S("67abcde"));
379     test(S("abcde"), 0, 0, SV("1234567890"), 5, 4, S("6789abcde"));
380     test(S("abcde"), 0, 0, SV("1234567890"), 5, 5, S("67890abcde"));
381     test(S("abcde"), 0, 0, SV("1234567890"), 5, 6, S("67890abcde"));
382     test(S("abcde"), 0, 0, SV("1234567890"), 9, 0, S("abcde"));
383     test(S("abcde"), 0, 0, SV("1234567890"), 9, 1, S("0abcde"));
384     test(S("abcde"), 0, 0, SV("1234567890"), 9, 2, S("0abcde"));
385     test(S("abcde"), 0, 0, SV("1234567890"), 10, 0, S("abcde"));
386     test(S("abcde"), 0, 0, SV("1234567890"), 10, 1, S("abcde"));
387     test(S("abcde"), 0, 0, SV("1234567890"), 11, 0, S("can't happen"));
388     test(S("abcde"), 0, 0, SV("12345678901234567890"), 0, 0, S("abcde"));
389     test(S("abcde"), 0, 0, SV("12345678901234567890"), 0, 1, S("1abcde"));
390     test(S("abcde"), 0, 0, SV("12345678901234567890"), 0, 10, S("1234567890abcde"));
391     test(S("abcde"), 0, 0, SV("12345678901234567890"), 0, 19, S("1234567890123456789abcde"));
392     test(S("abcde"), 0, 0, SV("12345678901234567890"), 0, 20, S("12345678901234567890abcde"));
393     test(S("abcde"), 0, 0, SV("12345678901234567890"), 0, 21, S("12345678901234567890abcde"));
394     test(S("abcde"), 0, 0, SV("12345678901234567890"), 1, 0, S("abcde"));
395     test(S("abcde"), 0, 0, SV("12345678901234567890"), 1, 1, S("2abcde"));
396     test(S("abcde"), 0, 0, SV("12345678901234567890"), 1, 9, S("234567890abcde"));
397     test(S("abcde"), 0, 0, SV("12345678901234567890"), 1, 18, S("234567890123456789abcde"));
398     test(S("abcde"), 0, 0, SV("12345678901234567890"), 1, 19, S("2345678901234567890abcde"));
399     test(S("abcde"), 0, 0, SV("12345678901234567890"), 1, 20, S("2345678901234567890abcde"));
400     test(S("abcde"), 0, 0, SV("12345678901234567890"), 10, 0, S("abcde"));
401     test(S("abcde"), 0, 0, SV("12345678901234567890"), 10, 1, S("1abcde"));
402     test(S("abcde"), 0, 0, SV("12345678901234567890"), 10, 5, S("12345abcde"));
403     test(S("abcde"), 0, 0, SV("12345678901234567890"), 10, 9, S("123456789abcde"));
404     test(S("abcde"), 0, 0, SV("12345678901234567890"), 10, 10, S("1234567890abcde"));
405     test(S("abcde"), 0, 0, SV("12345678901234567890"), 10, 11, S("1234567890abcde"));
406     test(S("abcde"), 0, 0, SV("12345678901234567890"), 19, 0, S("abcde"));
407     test(S("abcde"), 0, 0, SV("12345678901234567890"), 19, 1, S("0abcde"));
408     test(S("abcde"), 0, 0, SV("12345678901234567890"), 19, 2, S("0abcde"));
409     test(S("abcde"), 0, 0, SV("12345678901234567890"), 20, 0, S("abcde"));
410     test(S("abcde"), 0, 0, SV("12345678901234567890"), 20, 1, S("abcde"));
411     test(S("abcde"), 0, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
412     test(S("abcde"), 0, 1, SV(""), 0, 0, S("bcde"));
413     test(S("abcde"), 0, 1, SV(""), 0, 1, S("bcde"));
414     test(S("abcde"), 0, 1, SV(""), 1, 0, S("can't happen"));
415     test(S("abcde"), 0, 1, SV("12345"), 0, 0, S("bcde"));
416 }
417 
418 template <class S, class SV>
test3()419 void test3()
420 {
421     test(S("abcde"), 0, 1, SV("12345"), 0, 1, S("1bcde"));
422     test(S("abcde"), 0, 1, SV("12345"), 0, 2, S("12bcde"));
423     test(S("abcde"), 0, 1, SV("12345"), 0, 4, S("1234bcde"));
424     test(S("abcde"), 0, 1, SV("12345"), 0, 5, S("12345bcde"));
425     test(S("abcde"), 0, 1, SV("12345"), 0, 6, S("12345bcde"));
426     test(S("abcde"), 0, 1, SV("12345"), 1, 0, S("bcde"));
427     test(S("abcde"), 0, 1, SV("12345"), 1, 1, S("2bcde"));
428     test(S("abcde"), 0, 1, SV("12345"), 1, 2, S("23bcde"));
429     test(S("abcde"), 0, 1, SV("12345"), 1, 3, S("234bcde"));
430     test(S("abcde"), 0, 1, SV("12345"), 1, 4, S("2345bcde"));
431     test(S("abcde"), 0, 1, SV("12345"), 1, 5, S("2345bcde"));
432     test(S("abcde"), 0, 1, SV("12345"), 2, 0, S("bcde"));
433     test(S("abcde"), 0, 1, SV("12345"), 2, 1, S("3bcde"));
434     test(S("abcde"), 0, 1, SV("12345"), 2, 2, S("34bcde"));
435     test(S("abcde"), 0, 1, SV("12345"), 2, 3, S("345bcde"));
436     test(S("abcde"), 0, 1, SV("12345"), 2, 4, S("345bcde"));
437     test(S("abcde"), 0, 1, SV("12345"), 4, 0, S("bcde"));
438     test(S("abcde"), 0, 1, SV("12345"), 4, 1, S("5bcde"));
439     test(S("abcde"), 0, 1, SV("12345"), 4, 2, S("5bcde"));
440     test(S("abcde"), 0, 1, SV("12345"), 5, 0, S("bcde"));
441     test(S("abcde"), 0, 1, SV("12345"), 5, 1, S("bcde"));
442     test(S("abcde"), 0, 1, SV("12345"), 6, 0, S("can't happen"));
443     test(S("abcde"), 0, 1, SV("1234567890"), 0, 0, S("bcde"));
444     test(S("abcde"), 0, 1, SV("1234567890"), 0, 1, S("1bcde"));
445     test(S("abcde"), 0, 1, SV("1234567890"), 0, 5, S("12345bcde"));
446     test(S("abcde"), 0, 1, SV("1234567890"), 0, 9, S("123456789bcde"));
447     test(S("abcde"), 0, 1, SV("1234567890"), 0, 10, S("1234567890bcde"));
448     test(S("abcde"), 0, 1, SV("1234567890"), 0, 11, S("1234567890bcde"));
449     test(S("abcde"), 0, 1, SV("1234567890"), 1, 0, S("bcde"));
450     test(S("abcde"), 0, 1, SV("1234567890"), 1, 1, S("2bcde"));
451     test(S("abcde"), 0, 1, SV("1234567890"), 1, 4, S("2345bcde"));
452     test(S("abcde"), 0, 1, SV("1234567890"), 1, 8, S("23456789bcde"));
453     test(S("abcde"), 0, 1, SV("1234567890"), 1, 9, S("234567890bcde"));
454     test(S("abcde"), 0, 1, SV("1234567890"), 1, 10, S("234567890bcde"));
455     test(S("abcde"), 0, 1, SV("1234567890"), 5, 0, S("bcde"));
456     test(S("abcde"), 0, 1, SV("1234567890"), 5, 1, S("6bcde"));
457     test(S("abcde"), 0, 1, SV("1234567890"), 5, 2, S("67bcde"));
458     test(S("abcde"), 0, 1, SV("1234567890"), 5, 4, S("6789bcde"));
459     test(S("abcde"), 0, 1, SV("1234567890"), 5, 5, S("67890bcde"));
460     test(S("abcde"), 0, 1, SV("1234567890"), 5, 6, S("67890bcde"));
461     test(S("abcde"), 0, 1, SV("1234567890"), 9, 0, S("bcde"));
462     test(S("abcde"), 0, 1, SV("1234567890"), 9, 1, S("0bcde"));
463     test(S("abcde"), 0, 1, SV("1234567890"), 9, 2, S("0bcde"));
464     test(S("abcde"), 0, 1, SV("1234567890"), 10, 0, S("bcde"));
465     test(S("abcde"), 0, 1, SV("1234567890"), 10, 1, S("bcde"));
466     test(S("abcde"), 0, 1, SV("1234567890"), 11, 0, S("can't happen"));
467     test(S("abcde"), 0, 1, SV("12345678901234567890"), 0, 0, S("bcde"));
468     test(S("abcde"), 0, 1, SV("12345678901234567890"), 0, 1, S("1bcde"));
469     test(S("abcde"), 0, 1, SV("12345678901234567890"), 0, 10, S("1234567890bcde"));
470     test(S("abcde"), 0, 1, SV("12345678901234567890"), 0, 19, S("1234567890123456789bcde"));
471     test(S("abcde"), 0, 1, SV("12345678901234567890"), 0, 20, S("12345678901234567890bcde"));
472     test(S("abcde"), 0, 1, SV("12345678901234567890"), 0, 21, S("12345678901234567890bcde"));
473     test(S("abcde"), 0, 1, SV("12345678901234567890"), 1, 0, S("bcde"));
474     test(S("abcde"), 0, 1, SV("12345678901234567890"), 1, 1, S("2bcde"));
475     test(S("abcde"), 0, 1, SV("12345678901234567890"), 1, 9, S("234567890bcde"));
476     test(S("abcde"), 0, 1, SV("12345678901234567890"), 1, 18, S("234567890123456789bcde"));
477     test(S("abcde"), 0, 1, SV("12345678901234567890"), 1, 19, S("2345678901234567890bcde"));
478     test(S("abcde"), 0, 1, SV("12345678901234567890"), 1, 20, S("2345678901234567890bcde"));
479     test(S("abcde"), 0, 1, SV("12345678901234567890"), 10, 0, S("bcde"));
480     test(S("abcde"), 0, 1, SV("12345678901234567890"), 10, 1, S("1bcde"));
481     test(S("abcde"), 0, 1, SV("12345678901234567890"), 10, 5, S("12345bcde"));
482     test(S("abcde"), 0, 1, SV("12345678901234567890"), 10, 9, S("123456789bcde"));
483     test(S("abcde"), 0, 1, SV("12345678901234567890"), 10, 10, S("1234567890bcde"));
484     test(S("abcde"), 0, 1, SV("12345678901234567890"), 10, 11, S("1234567890bcde"));
485     test(S("abcde"), 0, 1, SV("12345678901234567890"), 19, 0, S("bcde"));
486     test(S("abcde"), 0, 1, SV("12345678901234567890"), 19, 1, S("0bcde"));
487     test(S("abcde"), 0, 1, SV("12345678901234567890"), 19, 2, S("0bcde"));
488     test(S("abcde"), 0, 1, SV("12345678901234567890"), 20, 0, S("bcde"));
489     test(S("abcde"), 0, 1, SV("12345678901234567890"), 20, 1, S("bcde"));
490     test(S("abcde"), 0, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
491     test(S("abcde"), 0, 2, SV(""), 0, 0, S("cde"));
492     test(S("abcde"), 0, 2, SV(""), 0, 1, S("cde"));
493     test(S("abcde"), 0, 2, SV(""), 1, 0, S("can't happen"));
494     test(S("abcde"), 0, 2, SV("12345"), 0, 0, S("cde"));
495     test(S("abcde"), 0, 2, SV("12345"), 0, 1, S("1cde"));
496     test(S("abcde"), 0, 2, SV("12345"), 0, 2, S("12cde"));
497     test(S("abcde"), 0, 2, SV("12345"), 0, 4, S("1234cde"));
498     test(S("abcde"), 0, 2, SV("12345"), 0, 5, S("12345cde"));
499     test(S("abcde"), 0, 2, SV("12345"), 0, 6, S("12345cde"));
500     test(S("abcde"), 0, 2, SV("12345"), 1, 0, S("cde"));
501     test(S("abcde"), 0, 2, SV("12345"), 1, 1, S("2cde"));
502     test(S("abcde"), 0, 2, SV("12345"), 1, 2, S("23cde"));
503     test(S("abcde"), 0, 2, SV("12345"), 1, 3, S("234cde"));
504     test(S("abcde"), 0, 2, SV("12345"), 1, 4, S("2345cde"));
505     test(S("abcde"), 0, 2, SV("12345"), 1, 5, S("2345cde"));
506     test(S("abcde"), 0, 2, SV("12345"), 2, 0, S("cde"));
507     test(S("abcde"), 0, 2, SV("12345"), 2, 1, S("3cde"));
508     test(S("abcde"), 0, 2, SV("12345"), 2, 2, S("34cde"));
509     test(S("abcde"), 0, 2, SV("12345"), 2, 3, S("345cde"));
510     test(S("abcde"), 0, 2, SV("12345"), 2, 4, S("345cde"));
511     test(S("abcde"), 0, 2, SV("12345"), 4, 0, S("cde"));
512     test(S("abcde"), 0, 2, SV("12345"), 4, 1, S("5cde"));
513     test(S("abcde"), 0, 2, SV("12345"), 4, 2, S("5cde"));
514     test(S("abcde"), 0, 2, SV("12345"), 5, 0, S("cde"));
515     test(S("abcde"), 0, 2, SV("12345"), 5, 1, S("cde"));
516     test(S("abcde"), 0, 2, SV("12345"), 6, 0, S("can't happen"));
517     test(S("abcde"), 0, 2, SV("1234567890"), 0, 0, S("cde"));
518     test(S("abcde"), 0, 2, SV("1234567890"), 0, 1, S("1cde"));
519     test(S("abcde"), 0, 2, SV("1234567890"), 0, 5, S("12345cde"));
520     test(S("abcde"), 0, 2, SV("1234567890"), 0, 9, S("123456789cde"));
521 }
522 
523 template <class S, class SV>
test4()524 void test4()
525 {
526     test(S("abcde"), 0, 2, SV("1234567890"), 0, 10, S("1234567890cde"));
527     test(S("abcde"), 0, 2, SV("1234567890"), 0, 11, S("1234567890cde"));
528     test(S("abcde"), 0, 2, SV("1234567890"), 1, 0, S("cde"));
529     test(S("abcde"), 0, 2, SV("1234567890"), 1, 1, S("2cde"));
530     test(S("abcde"), 0, 2, SV("1234567890"), 1, 4, S("2345cde"));
531     test(S("abcde"), 0, 2, SV("1234567890"), 1, 8, S("23456789cde"));
532     test(S("abcde"), 0, 2, SV("1234567890"), 1, 9, S("234567890cde"));
533     test(S("abcde"), 0, 2, SV("1234567890"), 1, 10, S("234567890cde"));
534     test(S("abcde"), 0, 2, SV("1234567890"), 5, 0, S("cde"));
535     test(S("abcde"), 0, 2, SV("1234567890"), 5, 1, S("6cde"));
536     test(S("abcde"), 0, 2, SV("1234567890"), 5, 2, S("67cde"));
537     test(S("abcde"), 0, 2, SV("1234567890"), 5, 4, S("6789cde"));
538     test(S("abcde"), 0, 2, SV("1234567890"), 5, 5, S("67890cde"));
539     test(S("abcde"), 0, 2, SV("1234567890"), 5, 6, S("67890cde"));
540     test(S("abcde"), 0, 2, SV("1234567890"), 9, 0, S("cde"));
541     test(S("abcde"), 0, 2, SV("1234567890"), 9, 1, S("0cde"));
542     test(S("abcde"), 0, 2, SV("1234567890"), 9, 2, S("0cde"));
543     test(S("abcde"), 0, 2, SV("1234567890"), 10, 0, S("cde"));
544     test(S("abcde"), 0, 2, SV("1234567890"), 10, 1, S("cde"));
545     test(S("abcde"), 0, 2, SV("1234567890"), 11, 0, S("can't happen"));
546     test(S("abcde"), 0, 2, SV("12345678901234567890"), 0, 0, S("cde"));
547     test(S("abcde"), 0, 2, SV("12345678901234567890"), 0, 1, S("1cde"));
548     test(S("abcde"), 0, 2, SV("12345678901234567890"), 0, 10, S("1234567890cde"));
549     test(S("abcde"), 0, 2, SV("12345678901234567890"), 0, 19, S("1234567890123456789cde"));
550     test(S("abcde"), 0, 2, SV("12345678901234567890"), 0, 20, S("12345678901234567890cde"));
551     test(S("abcde"), 0, 2, SV("12345678901234567890"), 0, 21, S("12345678901234567890cde"));
552     test(S("abcde"), 0, 2, SV("12345678901234567890"), 1, 0, S("cde"));
553     test(S("abcde"), 0, 2, SV("12345678901234567890"), 1, 1, S("2cde"));
554     test(S("abcde"), 0, 2, SV("12345678901234567890"), 1, 9, S("234567890cde"));
555     test(S("abcde"), 0, 2, SV("12345678901234567890"), 1, 18, S("234567890123456789cde"));
556     test(S("abcde"), 0, 2, SV("12345678901234567890"), 1, 19, S("2345678901234567890cde"));
557     test(S("abcde"), 0, 2, SV("12345678901234567890"), 1, 20, S("2345678901234567890cde"));
558     test(S("abcde"), 0, 2, SV("12345678901234567890"), 10, 0, S("cde"));
559     test(S("abcde"), 0, 2, SV("12345678901234567890"), 10, 1, S("1cde"));
560     test(S("abcde"), 0, 2, SV("12345678901234567890"), 10, 5, S("12345cde"));
561     test(S("abcde"), 0, 2, SV("12345678901234567890"), 10, 9, S("123456789cde"));
562     test(S("abcde"), 0, 2, SV("12345678901234567890"), 10, 10, S("1234567890cde"));
563     test(S("abcde"), 0, 2, SV("12345678901234567890"), 10, 11, S("1234567890cde"));
564     test(S("abcde"), 0, 2, SV("12345678901234567890"), 19, 0, S("cde"));
565     test(S("abcde"), 0, 2, SV("12345678901234567890"), 19, 1, S("0cde"));
566     test(S("abcde"), 0, 2, SV("12345678901234567890"), 19, 2, S("0cde"));
567     test(S("abcde"), 0, 2, SV("12345678901234567890"), 20, 0, S("cde"));
568     test(S("abcde"), 0, 2, SV("12345678901234567890"), 20, 1, S("cde"));
569     test(S("abcde"), 0, 2, SV("12345678901234567890"), 21, 0, S("can't happen"));
570     test(S("abcde"), 0, 4, SV(""), 0, 0, S("e"));
571     test(S("abcde"), 0, 4, SV(""), 0, 1, S("e"));
572     test(S("abcde"), 0, 4, SV(""), 1, 0, S("can't happen"));
573     test(S("abcde"), 0, 4, SV("12345"), 0, 0, S("e"));
574     test(S("abcde"), 0, 4, SV("12345"), 0, 1, S("1e"));
575     test(S("abcde"), 0, 4, SV("12345"), 0, 2, S("12e"));
576     test(S("abcde"), 0, 4, SV("12345"), 0, 4, S("1234e"));
577     test(S("abcde"), 0, 4, SV("12345"), 0, 5, S("12345e"));
578     test(S("abcde"), 0, 4, SV("12345"), 0, 6, S("12345e"));
579     test(S("abcde"), 0, 4, SV("12345"), 1, 0, S("e"));
580     test(S("abcde"), 0, 4, SV("12345"), 1, 1, S("2e"));
581     test(S("abcde"), 0, 4, SV("12345"), 1, 2, S("23e"));
582     test(S("abcde"), 0, 4, SV("12345"), 1, 3, S("234e"));
583     test(S("abcde"), 0, 4, SV("12345"), 1, 4, S("2345e"));
584     test(S("abcde"), 0, 4, SV("12345"), 1, 5, S("2345e"));
585     test(S("abcde"), 0, 4, SV("12345"), 2, 0, S("e"));
586     test(S("abcde"), 0, 4, SV("12345"), 2, 1, S("3e"));
587     test(S("abcde"), 0, 4, SV("12345"), 2, 2, S("34e"));
588     test(S("abcde"), 0, 4, SV("12345"), 2, 3, S("345e"));
589     test(S("abcde"), 0, 4, SV("12345"), 2, 4, S("345e"));
590     test(S("abcde"), 0, 4, SV("12345"), 4, 0, S("e"));
591     test(S("abcde"), 0, 4, SV("12345"), 4, 1, S("5e"));
592     test(S("abcde"), 0, 4, SV("12345"), 4, 2, S("5e"));
593     test(S("abcde"), 0, 4, SV("12345"), 5, 0, S("e"));
594     test(S("abcde"), 0, 4, SV("12345"), 5, 1, S("e"));
595     test(S("abcde"), 0, 4, SV("12345"), 6, 0, S("can't happen"));
596     test(S("abcde"), 0, 4, SV("1234567890"), 0, 0, S("e"));
597     test(S("abcde"), 0, 4, SV("1234567890"), 0, 1, S("1e"));
598     test(S("abcde"), 0, 4, SV("1234567890"), 0, 5, S("12345e"));
599     test(S("abcde"), 0, 4, SV("1234567890"), 0, 9, S("123456789e"));
600     test(S("abcde"), 0, 4, SV("1234567890"), 0, 10, S("1234567890e"));
601     test(S("abcde"), 0, 4, SV("1234567890"), 0, 11, S("1234567890e"));
602     test(S("abcde"), 0, 4, SV("1234567890"), 1, 0, S("e"));
603     test(S("abcde"), 0, 4, SV("1234567890"), 1, 1, S("2e"));
604     test(S("abcde"), 0, 4, SV("1234567890"), 1, 4, S("2345e"));
605     test(S("abcde"), 0, 4, SV("1234567890"), 1, 8, S("23456789e"));
606     test(S("abcde"), 0, 4, SV("1234567890"), 1, 9, S("234567890e"));
607     test(S("abcde"), 0, 4, SV("1234567890"), 1, 10, S("234567890e"));
608     test(S("abcde"), 0, 4, SV("1234567890"), 5, 0, S("e"));
609     test(S("abcde"), 0, 4, SV("1234567890"), 5, 1, S("6e"));
610     test(S("abcde"), 0, 4, SV("1234567890"), 5, 2, S("67e"));
611     test(S("abcde"), 0, 4, SV("1234567890"), 5, 4, S("6789e"));
612     test(S("abcde"), 0, 4, SV("1234567890"), 5, 5, S("67890e"));
613     test(S("abcde"), 0, 4, SV("1234567890"), 5, 6, S("67890e"));
614     test(S("abcde"), 0, 4, SV("1234567890"), 9, 0, S("e"));
615     test(S("abcde"), 0, 4, SV("1234567890"), 9, 1, S("0e"));
616     test(S("abcde"), 0, 4, SV("1234567890"), 9, 2, S("0e"));
617     test(S("abcde"), 0, 4, SV("1234567890"), 10, 0, S("e"));
618     test(S("abcde"), 0, 4, SV("1234567890"), 10, 1, S("e"));
619     test(S("abcde"), 0, 4, SV("1234567890"), 11, 0, S("can't happen"));
620     test(S("abcde"), 0, 4, SV("12345678901234567890"), 0, 0, S("e"));
621     test(S("abcde"), 0, 4, SV("12345678901234567890"), 0, 1, S("1e"));
622     test(S("abcde"), 0, 4, SV("12345678901234567890"), 0, 10, S("1234567890e"));
623     test(S("abcde"), 0, 4, SV("12345678901234567890"), 0, 19, S("1234567890123456789e"));
624     test(S("abcde"), 0, 4, SV("12345678901234567890"), 0, 20, S("12345678901234567890e"));
625     test(S("abcde"), 0, 4, SV("12345678901234567890"), 0, 21, S("12345678901234567890e"));
626 }
627 
628 template <class S, class SV>
test5()629 void test5()
630 {
631     test(S("abcde"), 0, 4, SV("12345678901234567890"), 1, 0, S("e"));
632     test(S("abcde"), 0, 4, SV("12345678901234567890"), 1, 1, S("2e"));
633     test(S("abcde"), 0, 4, SV("12345678901234567890"), 1, 9, S("234567890e"));
634     test(S("abcde"), 0, 4, SV("12345678901234567890"), 1, 18, S("234567890123456789e"));
635     test(S("abcde"), 0, 4, SV("12345678901234567890"), 1, 19, S("2345678901234567890e"));
636     test(S("abcde"), 0, 4, SV("12345678901234567890"), 1, 20, S("2345678901234567890e"));
637     test(S("abcde"), 0, 4, SV("12345678901234567890"), 10, 0, S("e"));
638     test(S("abcde"), 0, 4, SV("12345678901234567890"), 10, 1, S("1e"));
639     test(S("abcde"), 0, 4, SV("12345678901234567890"), 10, 5, S("12345e"));
640     test(S("abcde"), 0, 4, SV("12345678901234567890"), 10, 9, S("123456789e"));
641     test(S("abcde"), 0, 4, SV("12345678901234567890"), 10, 10, S("1234567890e"));
642     test(S("abcde"), 0, 4, SV("12345678901234567890"), 10, 11, S("1234567890e"));
643     test(S("abcde"), 0, 4, SV("12345678901234567890"), 19, 0, S("e"));
644     test(S("abcde"), 0, 4, SV("12345678901234567890"), 19, 1, S("0e"));
645     test(S("abcde"), 0, 4, SV("12345678901234567890"), 19, 2, S("0e"));
646     test(S("abcde"), 0, 4, SV("12345678901234567890"), 20, 0, S("e"));
647     test(S("abcde"), 0, 4, SV("12345678901234567890"), 20, 1, S("e"));
648     test(S("abcde"), 0, 4, SV("12345678901234567890"), 21, 0, S("can't happen"));
649     test(S("abcde"), 0, 5, SV(""), 0, 0, S(""));
650     test(S("abcde"), 0, 5, SV(""), 0, 1, S(""));
651     test(S("abcde"), 0, 5, SV(""), 1, 0, S("can't happen"));
652     test(S("abcde"), 0, 5, SV("12345"), 0, 0, S(""));
653     test(S("abcde"), 0, 5, SV("12345"), 0, 1, S("1"));
654     test(S("abcde"), 0, 5, SV("12345"), 0, 2, S("12"));
655     test(S("abcde"), 0, 5, SV("12345"), 0, 4, S("1234"));
656     test(S("abcde"), 0, 5, SV("12345"), 0, 5, S("12345"));
657     test(S("abcde"), 0, 5, SV("12345"), 0, 6, S("12345"));
658     test(S("abcde"), 0, 5, SV("12345"), 1, 0, S(""));
659     test(S("abcde"), 0, 5, SV("12345"), 1, 1, S("2"));
660     test(S("abcde"), 0, 5, SV("12345"), 1, 2, S("23"));
661     test(S("abcde"), 0, 5, SV("12345"), 1, 3, S("234"));
662     test(S("abcde"), 0, 5, SV("12345"), 1, 4, S("2345"));
663     test(S("abcde"), 0, 5, SV("12345"), 1, 5, S("2345"));
664     test(S("abcde"), 0, 5, SV("12345"), 2, 0, S(""));
665     test(S("abcde"), 0, 5, SV("12345"), 2, 1, S("3"));
666     test(S("abcde"), 0, 5, SV("12345"), 2, 2, S("34"));
667     test(S("abcde"), 0, 5, SV("12345"), 2, 3, S("345"));
668     test(S("abcde"), 0, 5, SV("12345"), 2, 4, S("345"));
669     test(S("abcde"), 0, 5, SV("12345"), 4, 0, S(""));
670     test(S("abcde"), 0, 5, SV("12345"), 4, 1, S("5"));
671     test(S("abcde"), 0, 5, SV("12345"), 4, 2, S("5"));
672     test(S("abcde"), 0, 5, SV("12345"), 5, 0, S(""));
673     test(S("abcde"), 0, 5, SV("12345"), 5, 1, S(""));
674     test(S("abcde"), 0, 5, SV("12345"), 6, 0, S("can't happen"));
675     test(S("abcde"), 0, 5, SV("1234567890"), 0, 0, S(""));
676     test(S("abcde"), 0, 5, SV("1234567890"), 0, 1, S("1"));
677     test(S("abcde"), 0, 5, SV("1234567890"), 0, 5, S("12345"));
678     test(S("abcde"), 0, 5, SV("1234567890"), 0, 9, S("123456789"));
679     test(S("abcde"), 0, 5, SV("1234567890"), 0, 10, S("1234567890"));
680     test(S("abcde"), 0, 5, SV("1234567890"), 0, 11, S("1234567890"));
681     test(S("abcde"), 0, 5, SV("1234567890"), 1, 0, S(""));
682     test(S("abcde"), 0, 5, SV("1234567890"), 1, 1, S("2"));
683     test(S("abcde"), 0, 5, SV("1234567890"), 1, 4, S("2345"));
684     test(S("abcde"), 0, 5, SV("1234567890"), 1, 8, S("23456789"));
685     test(S("abcde"), 0, 5, SV("1234567890"), 1, 9, S("234567890"));
686     test(S("abcde"), 0, 5, SV("1234567890"), 1, 10, S("234567890"));
687     test(S("abcde"), 0, 5, SV("1234567890"), 5, 0, S(""));
688     test(S("abcde"), 0, 5, SV("1234567890"), 5, 1, S("6"));
689     test(S("abcde"), 0, 5, SV("1234567890"), 5, 2, S("67"));
690     test(S("abcde"), 0, 5, SV("1234567890"), 5, 4, S("6789"));
691     test(S("abcde"), 0, 5, SV("1234567890"), 5, 5, S("67890"));
692     test(S("abcde"), 0, 5, SV("1234567890"), 5, 6, S("67890"));
693     test(S("abcde"), 0, 5, SV("1234567890"), 9, 0, S(""));
694     test(S("abcde"), 0, 5, SV("1234567890"), 9, 1, S("0"));
695     test(S("abcde"), 0, 5, SV("1234567890"), 9, 2, S("0"));
696     test(S("abcde"), 0, 5, SV("1234567890"), 10, 0, S(""));
697     test(S("abcde"), 0, 5, SV("1234567890"), 10, 1, S(""));
698     test(S("abcde"), 0, 5, SV("1234567890"), 11, 0, S("can't happen"));
699     test(S("abcde"), 0, 5, SV("12345678901234567890"), 0, 0, S(""));
700     test(S("abcde"), 0, 5, SV("12345678901234567890"), 0, 1, S("1"));
701     test(S("abcde"), 0, 5, SV("12345678901234567890"), 0, 10, S("1234567890"));
702     test(S("abcde"), 0, 5, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
703     test(S("abcde"), 0, 5, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
704     test(S("abcde"), 0, 5, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
705     test(S("abcde"), 0, 5, SV("12345678901234567890"), 1, 0, S(""));
706     test(S("abcde"), 0, 5, SV("12345678901234567890"), 1, 1, S("2"));
707     test(S("abcde"), 0, 5, SV("12345678901234567890"), 1, 9, S("234567890"));
708     test(S("abcde"), 0, 5, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
709     test(S("abcde"), 0, 5, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
710     test(S("abcde"), 0, 5, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
711     test(S("abcde"), 0, 5, SV("12345678901234567890"), 10, 0, S(""));
712     test(S("abcde"), 0, 5, SV("12345678901234567890"), 10, 1, S("1"));
713     test(S("abcde"), 0, 5, SV("12345678901234567890"), 10, 5, S("12345"));
714     test(S("abcde"), 0, 5, SV("12345678901234567890"), 10, 9, S("123456789"));
715     test(S("abcde"), 0, 5, SV("12345678901234567890"), 10, 10, S("1234567890"));
716     test(S("abcde"), 0, 5, SV("12345678901234567890"), 10, 11, S("1234567890"));
717     test(S("abcde"), 0, 5, SV("12345678901234567890"), 19, 0, S(""));
718     test(S("abcde"), 0, 5, SV("12345678901234567890"), 19, 1, S("0"));
719     test(S("abcde"), 0, 5, SV("12345678901234567890"), 19, 2, S("0"));
720     test(S("abcde"), 0, 5, SV("12345678901234567890"), 20, 0, S(""));
721     test(S("abcde"), 0, 5, SV("12345678901234567890"), 20, 1, S(""));
722     test(S("abcde"), 0, 5, SV("12345678901234567890"), 21, 0, S("can't happen"));
723     test(S("abcde"), 0, 6, SV(""), 0, 0, S(""));
724     test(S("abcde"), 0, 6, SV(""), 0, 1, S(""));
725     test(S("abcde"), 0, 6, SV(""), 1, 0, S("can't happen"));
726     test(S("abcde"), 0, 6, SV("12345"), 0, 0, S(""));
727     test(S("abcde"), 0, 6, SV("12345"), 0, 1, S("1"));
728     test(S("abcde"), 0, 6, SV("12345"), 0, 2, S("12"));
729     test(S("abcde"), 0, 6, SV("12345"), 0, 4, S("1234"));
730     test(S("abcde"), 0, 6, SV("12345"), 0, 5, S("12345"));
731 }
732 
733 template <class S, class SV>
test6()734 void test6()
735 {
736     test(S("abcde"), 0, 6, SV("12345"), 0, 6, S("12345"));
737     test(S("abcde"), 0, 6, SV("12345"), 1, 0, S(""));
738     test(S("abcde"), 0, 6, SV("12345"), 1, 1, S("2"));
739     test(S("abcde"), 0, 6, SV("12345"), 1, 2, S("23"));
740     test(S("abcde"), 0, 6, SV("12345"), 1, 3, S("234"));
741     test(S("abcde"), 0, 6, SV("12345"), 1, 4, S("2345"));
742     test(S("abcde"), 0, 6, SV("12345"), 1, 5, S("2345"));
743     test(S("abcde"), 0, 6, SV("12345"), 2, 0, S(""));
744     test(S("abcde"), 0, 6, SV("12345"), 2, 1, S("3"));
745     test(S("abcde"), 0, 6, SV("12345"), 2, 2, S("34"));
746     test(S("abcde"), 0, 6, SV("12345"), 2, 3, S("345"));
747     test(S("abcde"), 0, 6, SV("12345"), 2, 4, S("345"));
748     test(S("abcde"), 0, 6, SV("12345"), 4, 0, S(""));
749     test(S("abcde"), 0, 6, SV("12345"), 4, 1, S("5"));
750     test(S("abcde"), 0, 6, SV("12345"), 4, 2, S("5"));
751     test(S("abcde"), 0, 6, SV("12345"), 5, 0, S(""));
752     test(S("abcde"), 0, 6, SV("12345"), 5, 1, S(""));
753     test(S("abcde"), 0, 6, SV("12345"), 6, 0, S("can't happen"));
754     test(S("abcde"), 0, 6, SV("1234567890"), 0, 0, S(""));
755     test(S("abcde"), 0, 6, SV("1234567890"), 0, 1, S("1"));
756     test(S("abcde"), 0, 6, SV("1234567890"), 0, 5, S("12345"));
757     test(S("abcde"), 0, 6, SV("1234567890"), 0, 9, S("123456789"));
758     test(S("abcde"), 0, 6, SV("1234567890"), 0, 10, S("1234567890"));
759     test(S("abcde"), 0, 6, SV("1234567890"), 0, 11, S("1234567890"));
760     test(S("abcde"), 0, 6, SV("1234567890"), 1, 0, S(""));
761     test(S("abcde"), 0, 6, SV("1234567890"), 1, 1, S("2"));
762     test(S("abcde"), 0, 6, SV("1234567890"), 1, 4, S("2345"));
763     test(S("abcde"), 0, 6, SV("1234567890"), 1, 8, S("23456789"));
764     test(S("abcde"), 0, 6, SV("1234567890"), 1, 9, S("234567890"));
765     test(S("abcde"), 0, 6, SV("1234567890"), 1, 10, S("234567890"));
766     test(S("abcde"), 0, 6, SV("1234567890"), 5, 0, S(""));
767     test(S("abcde"), 0, 6, SV("1234567890"), 5, 1, S("6"));
768     test(S("abcde"), 0, 6, SV("1234567890"), 5, 2, S("67"));
769     test(S("abcde"), 0, 6, SV("1234567890"), 5, 4, S("6789"));
770     test(S("abcde"), 0, 6, SV("1234567890"), 5, 5, S("67890"));
771     test(S("abcde"), 0, 6, SV("1234567890"), 5, 6, S("67890"));
772     test(S("abcde"), 0, 6, SV("1234567890"), 9, 0, S(""));
773     test(S("abcde"), 0, 6, SV("1234567890"), 9, 1, S("0"));
774     test(S("abcde"), 0, 6, SV("1234567890"), 9, 2, S("0"));
775     test(S("abcde"), 0, 6, SV("1234567890"), 10, 0, S(""));
776     test(S("abcde"), 0, 6, SV("1234567890"), 10, 1, S(""));
777     test(S("abcde"), 0, 6, SV("1234567890"), 11, 0, S("can't happen"));
778     test(S("abcde"), 0, 6, SV("12345678901234567890"), 0, 0, S(""));
779     test(S("abcde"), 0, 6, SV("12345678901234567890"), 0, 1, S("1"));
780     test(S("abcde"), 0, 6, SV("12345678901234567890"), 0, 10, S("1234567890"));
781     test(S("abcde"), 0, 6, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
782     test(S("abcde"), 0, 6, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
783     test(S("abcde"), 0, 6, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
784     test(S("abcde"), 0, 6, SV("12345678901234567890"), 1, 0, S(""));
785     test(S("abcde"), 0, 6, SV("12345678901234567890"), 1, 1, S("2"));
786     test(S("abcde"), 0, 6, SV("12345678901234567890"), 1, 9, S("234567890"));
787     test(S("abcde"), 0, 6, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
788     test(S("abcde"), 0, 6, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
789     test(S("abcde"), 0, 6, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
790     test(S("abcde"), 0, 6, SV("12345678901234567890"), 10, 0, S(""));
791     test(S("abcde"), 0, 6, SV("12345678901234567890"), 10, 1, S("1"));
792     test(S("abcde"), 0, 6, SV("12345678901234567890"), 10, 5, S("12345"));
793     test(S("abcde"), 0, 6, SV("12345678901234567890"), 10, 9, S("123456789"));
794     test(S("abcde"), 0, 6, SV("12345678901234567890"), 10, 10, S("1234567890"));
795     test(S("abcde"), 0, 6, SV("12345678901234567890"), 10, 11, S("1234567890"));
796     test(S("abcde"), 0, 6, SV("12345678901234567890"), 19, 0, S(""));
797     test(S("abcde"), 0, 6, SV("12345678901234567890"), 19, 1, S("0"));
798     test(S("abcde"), 0, 6, SV("12345678901234567890"), 19, 2, S("0"));
799     test(S("abcde"), 0, 6, SV("12345678901234567890"), 20, 0, S(""));
800     test(S("abcde"), 0, 6, SV("12345678901234567890"), 20, 1, S(""));
801     test(S("abcde"), 0, 6, SV("12345678901234567890"), 21, 0, S("can't happen"));
802     test(S("abcde"), 1, 0, SV(""), 0, 0, S("abcde"));
803     test(S("abcde"), 1, 0, SV(""), 0, 1, S("abcde"));
804     test(S("abcde"), 1, 0, SV(""), 1, 0, S("can't happen"));
805     test(S("abcde"), 1, 0, SV("12345"), 0, 0, S("abcde"));
806     test(S("abcde"), 1, 0, SV("12345"), 0, 1, S("a1bcde"));
807     test(S("abcde"), 1, 0, SV("12345"), 0, 2, S("a12bcde"));
808     test(S("abcde"), 1, 0, SV("12345"), 0, 4, S("a1234bcde"));
809     test(S("abcde"), 1, 0, SV("12345"), 0, 5, S("a12345bcde"));
810     test(S("abcde"), 1, 0, SV("12345"), 0, 6, S("a12345bcde"));
811     test(S("abcde"), 1, 0, SV("12345"), 1, 0, S("abcde"));
812     test(S("abcde"), 1, 0, SV("12345"), 1, 1, S("a2bcde"));
813     test(S("abcde"), 1, 0, SV("12345"), 1, 2, S("a23bcde"));
814     test(S("abcde"), 1, 0, SV("12345"), 1, 3, S("a234bcde"));
815     test(S("abcde"), 1, 0, SV("12345"), 1, 4, S("a2345bcde"));
816     test(S("abcde"), 1, 0, SV("12345"), 1, 5, S("a2345bcde"));
817     test(S("abcde"), 1, 0, SV("12345"), 2, 0, S("abcde"));
818     test(S("abcde"), 1, 0, SV("12345"), 2, 1, S("a3bcde"));
819     test(S("abcde"), 1, 0, SV("12345"), 2, 2, S("a34bcde"));
820     test(S("abcde"), 1, 0, SV("12345"), 2, 3, S("a345bcde"));
821     test(S("abcde"), 1, 0, SV("12345"), 2, 4, S("a345bcde"));
822     test(S("abcde"), 1, 0, SV("12345"), 4, 0, S("abcde"));
823     test(S("abcde"), 1, 0, SV("12345"), 4, 1, S("a5bcde"));
824     test(S("abcde"), 1, 0, SV("12345"), 4, 2, S("a5bcde"));
825     test(S("abcde"), 1, 0, SV("12345"), 5, 0, S("abcde"));
826     test(S("abcde"), 1, 0, SV("12345"), 5, 1, S("abcde"));
827     test(S("abcde"), 1, 0, SV("12345"), 6, 0, S("can't happen"));
828     test(S("abcde"), 1, 0, SV("1234567890"), 0, 0, S("abcde"));
829     test(S("abcde"), 1, 0, SV("1234567890"), 0, 1, S("a1bcde"));
830     test(S("abcde"), 1, 0, SV("1234567890"), 0, 5, S("a12345bcde"));
831     test(S("abcde"), 1, 0, SV("1234567890"), 0, 9, S("a123456789bcde"));
832     test(S("abcde"), 1, 0, SV("1234567890"), 0, 10, S("a1234567890bcde"));
833     test(S("abcde"), 1, 0, SV("1234567890"), 0, 11, S("a1234567890bcde"));
834     test(S("abcde"), 1, 0, SV("1234567890"), 1, 0, S("abcde"));
835     test(S("abcde"), 1, 0, SV("1234567890"), 1, 1, S("a2bcde"));
836 }
837 
838 template <class S, class SV>
test7()839 void test7()
840 {
841     test(S("abcde"), 1, 0, SV("1234567890"), 1, 4, S("a2345bcde"));
842     test(S("abcde"), 1, 0, SV("1234567890"), 1, 8, S("a23456789bcde"));
843     test(S("abcde"), 1, 0, SV("1234567890"), 1, 9, S("a234567890bcde"));
844     test(S("abcde"), 1, 0, SV("1234567890"), 1, 10, S("a234567890bcde"));
845     test(S("abcde"), 1, 0, SV("1234567890"), 5, 0, S("abcde"));
846     test(S("abcde"), 1, 0, SV("1234567890"), 5, 1, S("a6bcde"));
847     test(S("abcde"), 1, 0, SV("1234567890"), 5, 2, S("a67bcde"));
848     test(S("abcde"), 1, 0, SV("1234567890"), 5, 4, S("a6789bcde"));
849     test(S("abcde"), 1, 0, SV("1234567890"), 5, 5, S("a67890bcde"));
850     test(S("abcde"), 1, 0, SV("1234567890"), 5, 6, S("a67890bcde"));
851     test(S("abcde"), 1, 0, SV("1234567890"), 9, 0, S("abcde"));
852     test(S("abcde"), 1, 0, SV("1234567890"), 9, 1, S("a0bcde"));
853     test(S("abcde"), 1, 0, SV("1234567890"), 9, 2, S("a0bcde"));
854     test(S("abcde"), 1, 0, SV("1234567890"), 10, 0, S("abcde"));
855     test(S("abcde"), 1, 0, SV("1234567890"), 10, 1, S("abcde"));
856     test(S("abcde"), 1, 0, SV("1234567890"), 11, 0, S("can't happen"));
857     test(S("abcde"), 1, 0, SV("12345678901234567890"), 0, 0, S("abcde"));
858     test(S("abcde"), 1, 0, SV("12345678901234567890"), 0, 1, S("a1bcde"));
859     test(S("abcde"), 1, 0, SV("12345678901234567890"), 0, 10, S("a1234567890bcde"));
860     test(S("abcde"), 1, 0, SV("12345678901234567890"), 0, 19, S("a1234567890123456789bcde"));
861     test(S("abcde"), 1, 0, SV("12345678901234567890"), 0, 20, S("a12345678901234567890bcde"));
862     test(S("abcde"), 1, 0, SV("12345678901234567890"), 0, 21, S("a12345678901234567890bcde"));
863     test(S("abcde"), 1, 0, SV("12345678901234567890"), 1, 0, S("abcde"));
864     test(S("abcde"), 1, 0, SV("12345678901234567890"), 1, 1, S("a2bcde"));
865     test(S("abcde"), 1, 0, SV("12345678901234567890"), 1, 9, S("a234567890bcde"));
866     test(S("abcde"), 1, 0, SV("12345678901234567890"), 1, 18, S("a234567890123456789bcde"));
867     test(S("abcde"), 1, 0, SV("12345678901234567890"), 1, 19, S("a2345678901234567890bcde"));
868     test(S("abcde"), 1, 0, SV("12345678901234567890"), 1, 20, S("a2345678901234567890bcde"));
869     test(S("abcde"), 1, 0, SV("12345678901234567890"), 10, 0, S("abcde"));
870     test(S("abcde"), 1, 0, SV("12345678901234567890"), 10, 1, S("a1bcde"));
871     test(S("abcde"), 1, 0, SV("12345678901234567890"), 10, 5, S("a12345bcde"));
872     test(S("abcde"), 1, 0, SV("12345678901234567890"), 10, 9, S("a123456789bcde"));
873     test(S("abcde"), 1, 0, SV("12345678901234567890"), 10, 10, S("a1234567890bcde"));
874     test(S("abcde"), 1, 0, SV("12345678901234567890"), 10, 11, S("a1234567890bcde"));
875     test(S("abcde"), 1, 0, SV("12345678901234567890"), 19, 0, S("abcde"));
876     test(S("abcde"), 1, 0, SV("12345678901234567890"), 19, 1, S("a0bcde"));
877     test(S("abcde"), 1, 0, SV("12345678901234567890"), 19, 2, S("a0bcde"));
878     test(S("abcde"), 1, 0, SV("12345678901234567890"), 20, 0, S("abcde"));
879     test(S("abcde"), 1, 0, SV("12345678901234567890"), 20, 1, S("abcde"));
880     test(S("abcde"), 1, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
881     test(S("abcde"), 1, 1, SV(""), 0, 0, S("acde"));
882     test(S("abcde"), 1, 1, SV(""), 0, 1, S("acde"));
883     test(S("abcde"), 1, 1, SV(""), 1, 0, S("can't happen"));
884     test(S("abcde"), 1, 1, SV("12345"), 0, 0, S("acde"));
885     test(S("abcde"), 1, 1, SV("12345"), 0, 1, S("a1cde"));
886     test(S("abcde"), 1, 1, SV("12345"), 0, 2, S("a12cde"));
887     test(S("abcde"), 1, 1, SV("12345"), 0, 4, S("a1234cde"));
888     test(S("abcde"), 1, 1, SV("12345"), 0, 5, S("a12345cde"));
889     test(S("abcde"), 1, 1, SV("12345"), 0, 6, S("a12345cde"));
890     test(S("abcde"), 1, 1, SV("12345"), 1, 0, S("acde"));
891     test(S("abcde"), 1, 1, SV("12345"), 1, 1, S("a2cde"));
892     test(S("abcde"), 1, 1, SV("12345"), 1, 2, S("a23cde"));
893     test(S("abcde"), 1, 1, SV("12345"), 1, 3, S("a234cde"));
894     test(S("abcde"), 1, 1, SV("12345"), 1, 4, S("a2345cde"));
895     test(S("abcde"), 1, 1, SV("12345"), 1, 5, S("a2345cde"));
896     test(S("abcde"), 1, 1, SV("12345"), 2, 0, S("acde"));
897     test(S("abcde"), 1, 1, SV("12345"), 2, 1, S("a3cde"));
898     test(S("abcde"), 1, 1, SV("12345"), 2, 2, S("a34cde"));
899     test(S("abcde"), 1, 1, SV("12345"), 2, 3, S("a345cde"));
900     test(S("abcde"), 1, 1, SV("12345"), 2, 4, S("a345cde"));
901     test(S("abcde"), 1, 1, SV("12345"), 4, 0, S("acde"));
902     test(S("abcde"), 1, 1, SV("12345"), 4, 1, S("a5cde"));
903     test(S("abcde"), 1, 1, SV("12345"), 4, 2, S("a5cde"));
904     test(S("abcde"), 1, 1, SV("12345"), 5, 0, S("acde"));
905     test(S("abcde"), 1, 1, SV("12345"), 5, 1, S("acde"));
906     test(S("abcde"), 1, 1, SV("12345"), 6, 0, S("can't happen"));
907     test(S("abcde"), 1, 1, SV("1234567890"), 0, 0, S("acde"));
908     test(S("abcde"), 1, 1, SV("1234567890"), 0, 1, S("a1cde"));
909     test(S("abcde"), 1, 1, SV("1234567890"), 0, 5, S("a12345cde"));
910     test(S("abcde"), 1, 1, SV("1234567890"), 0, 9, S("a123456789cde"));
911     test(S("abcde"), 1, 1, SV("1234567890"), 0, 10, S("a1234567890cde"));
912     test(S("abcde"), 1, 1, SV("1234567890"), 0, 11, S("a1234567890cde"));
913     test(S("abcde"), 1, 1, SV("1234567890"), 1, 0, S("acde"));
914     test(S("abcde"), 1, 1, SV("1234567890"), 1, 1, S("a2cde"));
915     test(S("abcde"), 1, 1, SV("1234567890"), 1, 4, S("a2345cde"));
916     test(S("abcde"), 1, 1, SV("1234567890"), 1, 8, S("a23456789cde"));
917     test(S("abcde"), 1, 1, SV("1234567890"), 1, 9, S("a234567890cde"));
918     test(S("abcde"), 1, 1, SV("1234567890"), 1, 10, S("a234567890cde"));
919     test(S("abcde"), 1, 1, SV("1234567890"), 5, 0, S("acde"));
920     test(S("abcde"), 1, 1, SV("1234567890"), 5, 1, S("a6cde"));
921     test(S("abcde"), 1, 1, SV("1234567890"), 5, 2, S("a67cde"));
922     test(S("abcde"), 1, 1, SV("1234567890"), 5, 4, S("a6789cde"));
923     test(S("abcde"), 1, 1, SV("1234567890"), 5, 5, S("a67890cde"));
924     test(S("abcde"), 1, 1, SV("1234567890"), 5, 6, S("a67890cde"));
925     test(S("abcde"), 1, 1, SV("1234567890"), 9, 0, S("acde"));
926     test(S("abcde"), 1, 1, SV("1234567890"), 9, 1, S("a0cde"));
927     test(S("abcde"), 1, 1, SV("1234567890"), 9, 2, S("a0cde"));
928     test(S("abcde"), 1, 1, SV("1234567890"), 10, 0, S("acde"));
929     test(S("abcde"), 1, 1, SV("1234567890"), 10, 1, S("acde"));
930     test(S("abcde"), 1, 1, SV("1234567890"), 11, 0, S("can't happen"));
931     test(S("abcde"), 1, 1, SV("12345678901234567890"), 0, 0, S("acde"));
932     test(S("abcde"), 1, 1, SV("12345678901234567890"), 0, 1, S("a1cde"));
933     test(S("abcde"), 1, 1, SV("12345678901234567890"), 0, 10, S("a1234567890cde"));
934     test(S("abcde"), 1, 1, SV("12345678901234567890"), 0, 19, S("a1234567890123456789cde"));
935     test(S("abcde"), 1, 1, SV("12345678901234567890"), 0, 20, S("a12345678901234567890cde"));
936     test(S("abcde"), 1, 1, SV("12345678901234567890"), 0, 21, S("a12345678901234567890cde"));
937     test(S("abcde"), 1, 1, SV("12345678901234567890"), 1, 0, S("acde"));
938     test(S("abcde"), 1, 1, SV("12345678901234567890"), 1, 1, S("a2cde"));
939     test(S("abcde"), 1, 1, SV("12345678901234567890"), 1, 9, S("a234567890cde"));
940     test(S("abcde"), 1, 1, SV("12345678901234567890"), 1, 18, S("a234567890123456789cde"));
941 }
942 
943 template <class S, class SV>
test8()944 void test8()
945 {
946     test(S("abcde"), 1, 1, SV("12345678901234567890"), 1, 19, S("a2345678901234567890cde"));
947     test(S("abcde"), 1, 1, SV("12345678901234567890"), 1, 20, S("a2345678901234567890cde"));
948     test(S("abcde"), 1, 1, SV("12345678901234567890"), 10, 0, S("acde"));
949     test(S("abcde"), 1, 1, SV("12345678901234567890"), 10, 1, S("a1cde"));
950     test(S("abcde"), 1, 1, SV("12345678901234567890"), 10, 5, S("a12345cde"));
951     test(S("abcde"), 1, 1, SV("12345678901234567890"), 10, 9, S("a123456789cde"));
952     test(S("abcde"), 1, 1, SV("12345678901234567890"), 10, 10, S("a1234567890cde"));
953     test(S("abcde"), 1, 1, SV("12345678901234567890"), 10, 11, S("a1234567890cde"));
954     test(S("abcde"), 1, 1, SV("12345678901234567890"), 19, 0, S("acde"));
955     test(S("abcde"), 1, 1, SV("12345678901234567890"), 19, 1, S("a0cde"));
956     test(S("abcde"), 1, 1, SV("12345678901234567890"), 19, 2, S("a0cde"));
957     test(S("abcde"), 1, 1, SV("12345678901234567890"), 20, 0, S("acde"));
958     test(S("abcde"), 1, 1, SV("12345678901234567890"), 20, 1, S("acde"));
959     test(S("abcde"), 1, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
960     test(S("abcde"), 1, 2, SV(""), 0, 0, S("ade"));
961     test(S("abcde"), 1, 2, SV(""), 0, 1, S("ade"));
962     test(S("abcde"), 1, 2, SV(""), 1, 0, S("can't happen"));
963     test(S("abcde"), 1, 2, SV("12345"), 0, 0, S("ade"));
964     test(S("abcde"), 1, 2, SV("12345"), 0, 1, S("a1de"));
965     test(S("abcde"), 1, 2, SV("12345"), 0, 2, S("a12de"));
966     test(S("abcde"), 1, 2, SV("12345"), 0, 4, S("a1234de"));
967     test(S("abcde"), 1, 2, SV("12345"), 0, 5, S("a12345de"));
968     test(S("abcde"), 1, 2, SV("12345"), 0, 6, S("a12345de"));
969     test(S("abcde"), 1, 2, SV("12345"), 1, 0, S("ade"));
970     test(S("abcde"), 1, 2, SV("12345"), 1, 1, S("a2de"));
971     test(S("abcde"), 1, 2, SV("12345"), 1, 2, S("a23de"));
972     test(S("abcde"), 1, 2, SV("12345"), 1, 3, S("a234de"));
973     test(S("abcde"), 1, 2, SV("12345"), 1, 4, S("a2345de"));
974     test(S("abcde"), 1, 2, SV("12345"), 1, 5, S("a2345de"));
975     test(S("abcde"), 1, 2, SV("12345"), 2, 0, S("ade"));
976     test(S("abcde"), 1, 2, SV("12345"), 2, 1, S("a3de"));
977     test(S("abcde"), 1, 2, SV("12345"), 2, 2, S("a34de"));
978     test(S("abcde"), 1, 2, SV("12345"), 2, 3, S("a345de"));
979     test(S("abcde"), 1, 2, SV("12345"), 2, 4, S("a345de"));
980     test(S("abcde"), 1, 2, SV("12345"), 4, 0, S("ade"));
981     test(S("abcde"), 1, 2, SV("12345"), 4, 1, S("a5de"));
982     test(S("abcde"), 1, 2, SV("12345"), 4, 2, S("a5de"));
983     test(S("abcde"), 1, 2, SV("12345"), 5, 0, S("ade"));
984     test(S("abcde"), 1, 2, SV("12345"), 5, 1, S("ade"));
985     test(S("abcde"), 1, 2, SV("12345"), 6, 0, S("can't happen"));
986     test(S("abcde"), 1, 2, SV("1234567890"), 0, 0, S("ade"));
987     test(S("abcde"), 1, 2, SV("1234567890"), 0, 1, S("a1de"));
988     test(S("abcde"), 1, 2, SV("1234567890"), 0, 5, S("a12345de"));
989     test(S("abcde"), 1, 2, SV("1234567890"), 0, 9, S("a123456789de"));
990     test(S("abcde"), 1, 2, SV("1234567890"), 0, 10, S("a1234567890de"));
991     test(S("abcde"), 1, 2, SV("1234567890"), 0, 11, S("a1234567890de"));
992     test(S("abcde"), 1, 2, SV("1234567890"), 1, 0, S("ade"));
993     test(S("abcde"), 1, 2, SV("1234567890"), 1, 1, S("a2de"));
994     test(S("abcde"), 1, 2, SV("1234567890"), 1, 4, S("a2345de"));
995     test(S("abcde"), 1, 2, SV("1234567890"), 1, 8, S("a23456789de"));
996     test(S("abcde"), 1, 2, SV("1234567890"), 1, 9, S("a234567890de"));
997     test(S("abcde"), 1, 2, SV("1234567890"), 1, 10, S("a234567890de"));
998     test(S("abcde"), 1, 2, SV("1234567890"), 5, 0, S("ade"));
999     test(S("abcde"), 1, 2, SV("1234567890"), 5, 1, S("a6de"));
1000     test(S("abcde"), 1, 2, SV("1234567890"), 5, 2, S("a67de"));
1001     test(S("abcde"), 1, 2, SV("1234567890"), 5, 4, S("a6789de"));
1002     test(S("abcde"), 1, 2, SV("1234567890"), 5, 5, S("a67890de"));
1003     test(S("abcde"), 1, 2, SV("1234567890"), 5, 6, S("a67890de"));
1004     test(S("abcde"), 1, 2, SV("1234567890"), 9, 0, S("ade"));
1005     test(S("abcde"), 1, 2, SV("1234567890"), 9, 1, S("a0de"));
1006     test(S("abcde"), 1, 2, SV("1234567890"), 9, 2, S("a0de"));
1007     test(S("abcde"), 1, 2, SV("1234567890"), 10, 0, S("ade"));
1008     test(S("abcde"), 1, 2, SV("1234567890"), 10, 1, S("ade"));
1009     test(S("abcde"), 1, 2, SV("1234567890"), 11, 0, S("can't happen"));
1010     test(S("abcde"), 1, 2, SV("12345678901234567890"), 0, 0, S("ade"));
1011     test(S("abcde"), 1, 2, SV("12345678901234567890"), 0, 1, S("a1de"));
1012     test(S("abcde"), 1, 2, SV("12345678901234567890"), 0, 10, S("a1234567890de"));
1013     test(S("abcde"), 1, 2, SV("12345678901234567890"), 0, 19, S("a1234567890123456789de"));
1014     test(S("abcde"), 1, 2, SV("12345678901234567890"), 0, 20, S("a12345678901234567890de"));
1015     test(S("abcde"), 1, 2, SV("12345678901234567890"), 0, 21, S("a12345678901234567890de"));
1016     test(S("abcde"), 1, 2, SV("12345678901234567890"), 1, 0, S("ade"));
1017     test(S("abcde"), 1, 2, SV("12345678901234567890"), 1, 1, S("a2de"));
1018     test(S("abcde"), 1, 2, SV("12345678901234567890"), 1, 9, S("a234567890de"));
1019     test(S("abcde"), 1, 2, SV("12345678901234567890"), 1, 18, S("a234567890123456789de"));
1020     test(S("abcde"), 1, 2, SV("12345678901234567890"), 1, 19, S("a2345678901234567890de"));
1021     test(S("abcde"), 1, 2, SV("12345678901234567890"), 1, 20, S("a2345678901234567890de"));
1022     test(S("abcde"), 1, 2, SV("12345678901234567890"), 10, 0, S("ade"));
1023     test(S("abcde"), 1, 2, SV("12345678901234567890"), 10, 1, S("a1de"));
1024     test(S("abcde"), 1, 2, SV("12345678901234567890"), 10, 5, S("a12345de"));
1025     test(S("abcde"), 1, 2, SV("12345678901234567890"), 10, 9, S("a123456789de"));
1026     test(S("abcde"), 1, 2, SV("12345678901234567890"), 10, 10, S("a1234567890de"));
1027     test(S("abcde"), 1, 2, SV("12345678901234567890"), 10, 11, S("a1234567890de"));
1028     test(S("abcde"), 1, 2, SV("12345678901234567890"), 19, 0, S("ade"));
1029     test(S("abcde"), 1, 2, SV("12345678901234567890"), 19, 1, S("a0de"));
1030     test(S("abcde"), 1, 2, SV("12345678901234567890"), 19, 2, S("a0de"));
1031     test(S("abcde"), 1, 2, SV("12345678901234567890"), 20, 0, S("ade"));
1032     test(S("abcde"), 1, 2, SV("12345678901234567890"), 20, 1, S("ade"));
1033     test(S("abcde"), 1, 2, SV("12345678901234567890"), 21, 0, S("can't happen"));
1034     test(S("abcde"), 1, 3, SV(""), 0, 0, S("ae"));
1035     test(S("abcde"), 1, 3, SV(""), 0, 1, S("ae"));
1036     test(S("abcde"), 1, 3, SV(""), 1, 0, S("can't happen"));
1037     test(S("abcde"), 1, 3, SV("12345"), 0, 0, S("ae"));
1038     test(S("abcde"), 1, 3, SV("12345"), 0, 1, S("a1e"));
1039     test(S("abcde"), 1, 3, SV("12345"), 0, 2, S("a12e"));
1040     test(S("abcde"), 1, 3, SV("12345"), 0, 4, S("a1234e"));
1041     test(S("abcde"), 1, 3, SV("12345"), 0, 5, S("a12345e"));
1042     test(S("abcde"), 1, 3, SV("12345"), 0, 6, S("a12345e"));
1043     test(S("abcde"), 1, 3, SV("12345"), 1, 0, S("ae"));
1044     test(S("abcde"), 1, 3, SV("12345"), 1, 1, S("a2e"));
1045     test(S("abcde"), 1, 3, SV("12345"), 1, 2, S("a23e"));
1046 }
1047 
1048 template <class S, class SV>
test9()1049 void test9()
1050 {
1051     test(S("abcde"), 1, 3, SV("12345"), 1, 3, S("a234e"));
1052     test(S("abcde"), 1, 3, SV("12345"), 1, 4, S("a2345e"));
1053     test(S("abcde"), 1, 3, SV("12345"), 1, 5, S("a2345e"));
1054     test(S("abcde"), 1, 3, SV("12345"), 2, 0, S("ae"));
1055     test(S("abcde"), 1, 3, SV("12345"), 2, 1, S("a3e"));
1056     test(S("abcde"), 1, 3, SV("12345"), 2, 2, S("a34e"));
1057     test(S("abcde"), 1, 3, SV("12345"), 2, 3, S("a345e"));
1058     test(S("abcde"), 1, 3, SV("12345"), 2, 4, S("a345e"));
1059     test(S("abcde"), 1, 3, SV("12345"), 4, 0, S("ae"));
1060     test(S("abcde"), 1, 3, SV("12345"), 4, 1, S("a5e"));
1061     test(S("abcde"), 1, 3, SV("12345"), 4, 2, S("a5e"));
1062     test(S("abcde"), 1, 3, SV("12345"), 5, 0, S("ae"));
1063     test(S("abcde"), 1, 3, SV("12345"), 5, 1, S("ae"));
1064     test(S("abcde"), 1, 3, SV("12345"), 6, 0, S("can't happen"));
1065     test(S("abcde"), 1, 3, SV("1234567890"), 0, 0, S("ae"));
1066     test(S("abcde"), 1, 3, SV("1234567890"), 0, 1, S("a1e"));
1067     test(S("abcde"), 1, 3, SV("1234567890"), 0, 5, S("a12345e"));
1068     test(S("abcde"), 1, 3, SV("1234567890"), 0, 9, S("a123456789e"));
1069     test(S("abcde"), 1, 3, SV("1234567890"), 0, 10, S("a1234567890e"));
1070     test(S("abcde"), 1, 3, SV("1234567890"), 0, 11, S("a1234567890e"));
1071     test(S("abcde"), 1, 3, SV("1234567890"), 1, 0, S("ae"));
1072     test(S("abcde"), 1, 3, SV("1234567890"), 1, 1, S("a2e"));
1073     test(S("abcde"), 1, 3, SV("1234567890"), 1, 4, S("a2345e"));
1074     test(S("abcde"), 1, 3, SV("1234567890"), 1, 8, S("a23456789e"));
1075     test(S("abcde"), 1, 3, SV("1234567890"), 1, 9, S("a234567890e"));
1076     test(S("abcde"), 1, 3, SV("1234567890"), 1, 10, S("a234567890e"));
1077     test(S("abcde"), 1, 3, SV("1234567890"), 5, 0, S("ae"));
1078     test(S("abcde"), 1, 3, SV("1234567890"), 5, 1, S("a6e"));
1079     test(S("abcde"), 1, 3, SV("1234567890"), 5, 2, S("a67e"));
1080     test(S("abcde"), 1, 3, SV("1234567890"), 5, 4, S("a6789e"));
1081     test(S("abcde"), 1, 3, SV("1234567890"), 5, 5, S("a67890e"));
1082     test(S("abcde"), 1, 3, SV("1234567890"), 5, 6, S("a67890e"));
1083     test(S("abcde"), 1, 3, SV("1234567890"), 9, 0, S("ae"));
1084     test(S("abcde"), 1, 3, SV("1234567890"), 9, 1, S("a0e"));
1085     test(S("abcde"), 1, 3, SV("1234567890"), 9, 2, S("a0e"));
1086     test(S("abcde"), 1, 3, SV("1234567890"), 10, 0, S("ae"));
1087     test(S("abcde"), 1, 3, SV("1234567890"), 10, 1, S("ae"));
1088     test(S("abcde"), 1, 3, SV("1234567890"), 11, 0, S("can't happen"));
1089     test(S("abcde"), 1, 3, SV("12345678901234567890"), 0, 0, S("ae"));
1090     test(S("abcde"), 1, 3, SV("12345678901234567890"), 0, 1, S("a1e"));
1091     test(S("abcde"), 1, 3, SV("12345678901234567890"), 0, 10, S("a1234567890e"));
1092     test(S("abcde"), 1, 3, SV("12345678901234567890"), 0, 19, S("a1234567890123456789e"));
1093     test(S("abcde"), 1, 3, SV("12345678901234567890"), 0, 20, S("a12345678901234567890e"));
1094     test(S("abcde"), 1, 3, SV("12345678901234567890"), 0, 21, S("a12345678901234567890e"));
1095     test(S("abcde"), 1, 3, SV("12345678901234567890"), 1, 0, S("ae"));
1096     test(S("abcde"), 1, 3, SV("12345678901234567890"), 1, 1, S("a2e"));
1097     test(S("abcde"), 1, 3, SV("12345678901234567890"), 1, 9, S("a234567890e"));
1098     test(S("abcde"), 1, 3, SV("12345678901234567890"), 1, 18, S("a234567890123456789e"));
1099     test(S("abcde"), 1, 3, SV("12345678901234567890"), 1, 19, S("a2345678901234567890e"));
1100     test(S("abcde"), 1, 3, SV("12345678901234567890"), 1, 20, S("a2345678901234567890e"));
1101     test(S("abcde"), 1, 3, SV("12345678901234567890"), 10, 0, S("ae"));
1102     test(S("abcde"), 1, 3, SV("12345678901234567890"), 10, 1, S("a1e"));
1103     test(S("abcde"), 1, 3, SV("12345678901234567890"), 10, 5, S("a12345e"));
1104     test(S("abcde"), 1, 3, SV("12345678901234567890"), 10, 9, S("a123456789e"));
1105     test(S("abcde"), 1, 3, SV("12345678901234567890"), 10, 10, S("a1234567890e"));
1106     test(S("abcde"), 1, 3, SV("12345678901234567890"), 10, 11, S("a1234567890e"));
1107     test(S("abcde"), 1, 3, SV("12345678901234567890"), 19, 0, S("ae"));
1108     test(S("abcde"), 1, 3, SV("12345678901234567890"), 19, 1, S("a0e"));
1109     test(S("abcde"), 1, 3, SV("12345678901234567890"), 19, 2, S("a0e"));
1110     test(S("abcde"), 1, 3, SV("12345678901234567890"), 20, 0, S("ae"));
1111     test(S("abcde"), 1, 3, SV("12345678901234567890"), 20, 1, S("ae"));
1112     test(S("abcde"), 1, 3, SV("12345678901234567890"), 21, 0, S("can't happen"));
1113     test(S("abcde"), 1, 4, SV(""), 0, 0, S("a"));
1114     test(S("abcde"), 1, 4, SV(""), 0, 1, S("a"));
1115     test(S("abcde"), 1, 4, SV(""), 1, 0, S("can't happen"));
1116     test(S("abcde"), 1, 4, SV("12345"), 0, 0, S("a"));
1117     test(S("abcde"), 1, 4, SV("12345"), 0, 1, S("a1"));
1118     test(S("abcde"), 1, 4, SV("12345"), 0, 2, S("a12"));
1119     test(S("abcde"), 1, 4, SV("12345"), 0, 4, S("a1234"));
1120     test(S("abcde"), 1, 4, SV("12345"), 0, 5, S("a12345"));
1121     test(S("abcde"), 1, 4, SV("12345"), 0, 6, S("a12345"));
1122     test(S("abcde"), 1, 4, SV("12345"), 1, 0, S("a"));
1123     test(S("abcde"), 1, 4, SV("12345"), 1, 1, S("a2"));
1124     test(S("abcde"), 1, 4, SV("12345"), 1, 2, S("a23"));
1125     test(S("abcde"), 1, 4, SV("12345"), 1, 3, S("a234"));
1126     test(S("abcde"), 1, 4, SV("12345"), 1, 4, S("a2345"));
1127     test(S("abcde"), 1, 4, SV("12345"), 1, 5, S("a2345"));
1128     test(S("abcde"), 1, 4, SV("12345"), 2, 0, S("a"));
1129     test(S("abcde"), 1, 4, SV("12345"), 2, 1, S("a3"));
1130     test(S("abcde"), 1, 4, SV("12345"), 2, 2, S("a34"));
1131     test(S("abcde"), 1, 4, SV("12345"), 2, 3, S("a345"));
1132     test(S("abcde"), 1, 4, SV("12345"), 2, 4, S("a345"));
1133     test(S("abcde"), 1, 4, SV("12345"), 4, 0, S("a"));
1134     test(S("abcde"), 1, 4, SV("12345"), 4, 1, S("a5"));
1135     test(S("abcde"), 1, 4, SV("12345"), 4, 2, S("a5"));
1136     test(S("abcde"), 1, 4, SV("12345"), 5, 0, S("a"));
1137     test(S("abcde"), 1, 4, SV("12345"), 5, 1, S("a"));
1138     test(S("abcde"), 1, 4, SV("12345"), 6, 0, S("can't happen"));
1139     test(S("abcde"), 1, 4, SV("1234567890"), 0, 0, S("a"));
1140     test(S("abcde"), 1, 4, SV("1234567890"), 0, 1, S("a1"));
1141     test(S("abcde"), 1, 4, SV("1234567890"), 0, 5, S("a12345"));
1142     test(S("abcde"), 1, 4, SV("1234567890"), 0, 9, S("a123456789"));
1143     test(S("abcde"), 1, 4, SV("1234567890"), 0, 10, S("a1234567890"));
1144     test(S("abcde"), 1, 4, SV("1234567890"), 0, 11, S("a1234567890"));
1145     test(S("abcde"), 1, 4, SV("1234567890"), 1, 0, S("a"));
1146     test(S("abcde"), 1, 4, SV("1234567890"), 1, 1, S("a2"));
1147     test(S("abcde"), 1, 4, SV("1234567890"), 1, 4, S("a2345"));
1148     test(S("abcde"), 1, 4, SV("1234567890"), 1, 8, S("a23456789"));
1149     test(S("abcde"), 1, 4, SV("1234567890"), 1, 9, S("a234567890"));
1150     test(S("abcde"), 1, 4, SV("1234567890"), 1, 10, S("a234567890"));
1151 }
1152 
1153 template <class S, class SV>
test10()1154 void test10()
1155 {
1156     test(S("abcde"), 1, 4, SV("1234567890"), 5, 0, S("a"));
1157     test(S("abcde"), 1, 4, SV("1234567890"), 5, 1, S("a6"));
1158     test(S("abcde"), 1, 4, SV("1234567890"), 5, 2, S("a67"));
1159     test(S("abcde"), 1, 4, SV("1234567890"), 5, 4, S("a6789"));
1160     test(S("abcde"), 1, 4, SV("1234567890"), 5, 5, S("a67890"));
1161     test(S("abcde"), 1, 4, SV("1234567890"), 5, 6, S("a67890"));
1162     test(S("abcde"), 1, 4, SV("1234567890"), 9, 0, S("a"));
1163     test(S("abcde"), 1, 4, SV("1234567890"), 9, 1, S("a0"));
1164     test(S("abcde"), 1, 4, SV("1234567890"), 9, 2, S("a0"));
1165     test(S("abcde"), 1, 4, SV("1234567890"), 10, 0, S("a"));
1166     test(S("abcde"), 1, 4, SV("1234567890"), 10, 1, S("a"));
1167     test(S("abcde"), 1, 4, SV("1234567890"), 11, 0, S("can't happen"));
1168     test(S("abcde"), 1, 4, SV("12345678901234567890"), 0, 0, S("a"));
1169     test(S("abcde"), 1, 4, SV("12345678901234567890"), 0, 1, S("a1"));
1170     test(S("abcde"), 1, 4, SV("12345678901234567890"), 0, 10, S("a1234567890"));
1171     test(S("abcde"), 1, 4, SV("12345678901234567890"), 0, 19, S("a1234567890123456789"));
1172     test(S("abcde"), 1, 4, SV("12345678901234567890"), 0, 20, S("a12345678901234567890"));
1173     test(S("abcde"), 1, 4, SV("12345678901234567890"), 0, 21, S("a12345678901234567890"));
1174     test(S("abcde"), 1, 4, SV("12345678901234567890"), 1, 0, S("a"));
1175     test(S("abcde"), 1, 4, SV("12345678901234567890"), 1, 1, S("a2"));
1176     test(S("abcde"), 1, 4, SV("12345678901234567890"), 1, 9, S("a234567890"));
1177     test(S("abcde"), 1, 4, SV("12345678901234567890"), 1, 18, S("a234567890123456789"));
1178     test(S("abcde"), 1, 4, SV("12345678901234567890"), 1, 19, S("a2345678901234567890"));
1179     test(S("abcde"), 1, 4, SV("12345678901234567890"), 1, 20, S("a2345678901234567890"));
1180     test(S("abcde"), 1, 4, SV("12345678901234567890"), 10, 0, S("a"));
1181     test(S("abcde"), 1, 4, SV("12345678901234567890"), 10, 1, S("a1"));
1182     test(S("abcde"), 1, 4, SV("12345678901234567890"), 10, 5, S("a12345"));
1183     test(S("abcde"), 1, 4, SV("12345678901234567890"), 10, 9, S("a123456789"));
1184     test(S("abcde"), 1, 4, SV("12345678901234567890"), 10, 10, S("a1234567890"));
1185     test(S("abcde"), 1, 4, SV("12345678901234567890"), 10, 11, S("a1234567890"));
1186     test(S("abcde"), 1, 4, SV("12345678901234567890"), 19, 0, S("a"));
1187     test(S("abcde"), 1, 4, SV("12345678901234567890"), 19, 1, S("a0"));
1188     test(S("abcde"), 1, 4, SV("12345678901234567890"), 19, 2, S("a0"));
1189     test(S("abcde"), 1, 4, SV("12345678901234567890"), 20, 0, S("a"));
1190     test(S("abcde"), 1, 4, SV("12345678901234567890"), 20, 1, S("a"));
1191     test(S("abcde"), 1, 4, SV("12345678901234567890"), 21, 0, S("can't happen"));
1192     test(S("abcde"), 1, 5, SV(""), 0, 0, S("a"));
1193     test(S("abcde"), 1, 5, SV(""), 0, 1, S("a"));
1194     test(S("abcde"), 1, 5, SV(""), 1, 0, S("can't happen"));
1195     test(S("abcde"), 1, 5, SV("12345"), 0, 0, S("a"));
1196     test(S("abcde"), 1, 5, SV("12345"), 0, 1, S("a1"));
1197     test(S("abcde"), 1, 5, SV("12345"), 0, 2, S("a12"));
1198     test(S("abcde"), 1, 5, SV("12345"), 0, 4, S("a1234"));
1199     test(S("abcde"), 1, 5, SV("12345"), 0, 5, S("a12345"));
1200     test(S("abcde"), 1, 5, SV("12345"), 0, 6, S("a12345"));
1201     test(S("abcde"), 1, 5, SV("12345"), 1, 0, S("a"));
1202     test(S("abcde"), 1, 5, SV("12345"), 1, 1, S("a2"));
1203     test(S("abcde"), 1, 5, SV("12345"), 1, 2, S("a23"));
1204     test(S("abcde"), 1, 5, SV("12345"), 1, 3, S("a234"));
1205     test(S("abcde"), 1, 5, SV("12345"), 1, 4, S("a2345"));
1206     test(S("abcde"), 1, 5, SV("12345"), 1, 5, S("a2345"));
1207     test(S("abcde"), 1, 5, SV("12345"), 2, 0, S("a"));
1208     test(S("abcde"), 1, 5, SV("12345"), 2, 1, S("a3"));
1209     test(S("abcde"), 1, 5, SV("12345"), 2, 2, S("a34"));
1210     test(S("abcde"), 1, 5, SV("12345"), 2, 3, S("a345"));
1211     test(S("abcde"), 1, 5, SV("12345"), 2, 4, S("a345"));
1212     test(S("abcde"), 1, 5, SV("12345"), 4, 0, S("a"));
1213     test(S("abcde"), 1, 5, SV("12345"), 4, 1, S("a5"));
1214     test(S("abcde"), 1, 5, SV("12345"), 4, 2, S("a5"));
1215     test(S("abcde"), 1, 5, SV("12345"), 5, 0, S("a"));
1216     test(S("abcde"), 1, 5, SV("12345"), 5, 1, S("a"));
1217     test(S("abcde"), 1, 5, SV("12345"), 6, 0, S("can't happen"));
1218     test(S("abcde"), 1, 5, SV("1234567890"), 0, 0, S("a"));
1219     test(S("abcde"), 1, 5, SV("1234567890"), 0, 1, S("a1"));
1220     test(S("abcde"), 1, 5, SV("1234567890"), 0, 5, S("a12345"));
1221     test(S("abcde"), 1, 5, SV("1234567890"), 0, 9, S("a123456789"));
1222     test(S("abcde"), 1, 5, SV("1234567890"), 0, 10, S("a1234567890"));
1223     test(S("abcde"), 1, 5, SV("1234567890"), 0, 11, S("a1234567890"));
1224     test(S("abcde"), 1, 5, SV("1234567890"), 1, 0, S("a"));
1225     test(S("abcde"), 1, 5, SV("1234567890"), 1, 1, S("a2"));
1226     test(S("abcde"), 1, 5, SV("1234567890"), 1, 4, S("a2345"));
1227     test(S("abcde"), 1, 5, SV("1234567890"), 1, 8, S("a23456789"));
1228     test(S("abcde"), 1, 5, SV("1234567890"), 1, 9, S("a234567890"));
1229     test(S("abcde"), 1, 5, SV("1234567890"), 1, 10, S("a234567890"));
1230     test(S("abcde"), 1, 5, SV("1234567890"), 5, 0, S("a"));
1231     test(S("abcde"), 1, 5, SV("1234567890"), 5, 1, S("a6"));
1232     test(S("abcde"), 1, 5, SV("1234567890"), 5, 2, S("a67"));
1233     test(S("abcde"), 1, 5, SV("1234567890"), 5, 4, S("a6789"));
1234     test(S("abcde"), 1, 5, SV("1234567890"), 5, 5, S("a67890"));
1235     test(S("abcde"), 1, 5, SV("1234567890"), 5, 6, S("a67890"));
1236     test(S("abcde"), 1, 5, SV("1234567890"), 9, 0, S("a"));
1237     test(S("abcde"), 1, 5, SV("1234567890"), 9, 1, S("a0"));
1238     test(S("abcde"), 1, 5, SV("1234567890"), 9, 2, S("a0"));
1239     test(S("abcde"), 1, 5, SV("1234567890"), 10, 0, S("a"));
1240     test(S("abcde"), 1, 5, SV("1234567890"), 10, 1, S("a"));
1241     test(S("abcde"), 1, 5, SV("1234567890"), 11, 0, S("can't happen"));
1242     test(S("abcde"), 1, 5, SV("12345678901234567890"), 0, 0, S("a"));
1243     test(S("abcde"), 1, 5, SV("12345678901234567890"), 0, 1, S("a1"));
1244     test(S("abcde"), 1, 5, SV("12345678901234567890"), 0, 10, S("a1234567890"));
1245     test(S("abcde"), 1, 5, SV("12345678901234567890"), 0, 19, S("a1234567890123456789"));
1246     test(S("abcde"), 1, 5, SV("12345678901234567890"), 0, 20, S("a12345678901234567890"));
1247     test(S("abcde"), 1, 5, SV("12345678901234567890"), 0, 21, S("a12345678901234567890"));
1248     test(S("abcde"), 1, 5, SV("12345678901234567890"), 1, 0, S("a"));
1249     test(S("abcde"), 1, 5, SV("12345678901234567890"), 1, 1, S("a2"));
1250     test(S("abcde"), 1, 5, SV("12345678901234567890"), 1, 9, S("a234567890"));
1251     test(S("abcde"), 1, 5, SV("12345678901234567890"), 1, 18, S("a234567890123456789"));
1252     test(S("abcde"), 1, 5, SV("12345678901234567890"), 1, 19, S("a2345678901234567890"));
1253     test(S("abcde"), 1, 5, SV("12345678901234567890"), 1, 20, S("a2345678901234567890"));
1254     test(S("abcde"), 1, 5, SV("12345678901234567890"), 10, 0, S("a"));
1255     test(S("abcde"), 1, 5, SV("12345678901234567890"), 10, 1, S("a1"));
1256 }
1257 
1258 template <class S, class SV>
test11()1259 void test11()
1260 {
1261     test(S("abcde"), 1, 5, SV("12345678901234567890"), 10, 5, S("a12345"));
1262     test(S("abcde"), 1, 5, SV("12345678901234567890"), 10, 9, S("a123456789"));
1263     test(S("abcde"), 1, 5, SV("12345678901234567890"), 10, 10, S("a1234567890"));
1264     test(S("abcde"), 1, 5, SV("12345678901234567890"), 10, 11, S("a1234567890"));
1265     test(S("abcde"), 1, 5, SV("12345678901234567890"), 19, 0, S("a"));
1266     test(S("abcde"), 1, 5, SV("12345678901234567890"), 19, 1, S("a0"));
1267     test(S("abcde"), 1, 5, SV("12345678901234567890"), 19, 2, S("a0"));
1268     test(S("abcde"), 1, 5, SV("12345678901234567890"), 20, 0, S("a"));
1269     test(S("abcde"), 1, 5, SV("12345678901234567890"), 20, 1, S("a"));
1270     test(S("abcde"), 1, 5, SV("12345678901234567890"), 21, 0, S("can't happen"));
1271     test(S("abcde"), 2, 0, SV(""), 0, 0, S("abcde"));
1272     test(S("abcde"), 2, 0, SV(""), 0, 1, S("abcde"));
1273     test(S("abcde"), 2, 0, SV(""), 1, 0, S("can't happen"));
1274     test(S("abcde"), 2, 0, SV("12345"), 0, 0, S("abcde"));
1275     test(S("abcde"), 2, 0, SV("12345"), 0, 1, S("ab1cde"));
1276     test(S("abcde"), 2, 0, SV("12345"), 0, 2, S("ab12cde"));
1277     test(S("abcde"), 2, 0, SV("12345"), 0, 4, S("ab1234cde"));
1278     test(S("abcde"), 2, 0, SV("12345"), 0, 5, S("ab12345cde"));
1279     test(S("abcde"), 2, 0, SV("12345"), 0, 6, S("ab12345cde"));
1280     test(S("abcde"), 2, 0, SV("12345"), 1, 0, S("abcde"));
1281     test(S("abcde"), 2, 0, SV("12345"), 1, 1, S("ab2cde"));
1282     test(S("abcde"), 2, 0, SV("12345"), 1, 2, S("ab23cde"));
1283     test(S("abcde"), 2, 0, SV("12345"), 1, 3, S("ab234cde"));
1284     test(S("abcde"), 2, 0, SV("12345"), 1, 4, S("ab2345cde"));
1285     test(S("abcde"), 2, 0, SV("12345"), 1, 5, S("ab2345cde"));
1286     test(S("abcde"), 2, 0, SV("12345"), 2, 0, S("abcde"));
1287     test(S("abcde"), 2, 0, SV("12345"), 2, 1, S("ab3cde"));
1288     test(S("abcde"), 2, 0, SV("12345"), 2, 2, S("ab34cde"));
1289     test(S("abcde"), 2, 0, SV("12345"), 2, 3, S("ab345cde"));
1290     test(S("abcde"), 2, 0, SV("12345"), 2, 4, S("ab345cde"));
1291     test(S("abcde"), 2, 0, SV("12345"), 4, 0, S("abcde"));
1292     test(S("abcde"), 2, 0, SV("12345"), 4, 1, S("ab5cde"));
1293     test(S("abcde"), 2, 0, SV("12345"), 4, 2, S("ab5cde"));
1294     test(S("abcde"), 2, 0, SV("12345"), 5, 0, S("abcde"));
1295     test(S("abcde"), 2, 0, SV("12345"), 5, 1, S("abcde"));
1296     test(S("abcde"), 2, 0, SV("12345"), 6, 0, S("can't happen"));
1297     test(S("abcde"), 2, 0, SV("1234567890"), 0, 0, S("abcde"));
1298     test(S("abcde"), 2, 0, SV("1234567890"), 0, 1, S("ab1cde"));
1299     test(S("abcde"), 2, 0, SV("1234567890"), 0, 5, S("ab12345cde"));
1300     test(S("abcde"), 2, 0, SV("1234567890"), 0, 9, S("ab123456789cde"));
1301     test(S("abcde"), 2, 0, SV("1234567890"), 0, 10, S("ab1234567890cde"));
1302     test(S("abcde"), 2, 0, SV("1234567890"), 0, 11, S("ab1234567890cde"));
1303     test(S("abcde"), 2, 0, SV("1234567890"), 1, 0, S("abcde"));
1304     test(S("abcde"), 2, 0, SV("1234567890"), 1, 1, S("ab2cde"));
1305     test(S("abcde"), 2, 0, SV("1234567890"), 1, 4, S("ab2345cde"));
1306     test(S("abcde"), 2, 0, SV("1234567890"), 1, 8, S("ab23456789cde"));
1307     test(S("abcde"), 2, 0, SV("1234567890"), 1, 9, S("ab234567890cde"));
1308     test(S("abcde"), 2, 0, SV("1234567890"), 1, 10, S("ab234567890cde"));
1309     test(S("abcde"), 2, 0, SV("1234567890"), 5, 0, S("abcde"));
1310     test(S("abcde"), 2, 0, SV("1234567890"), 5, 1, S("ab6cde"));
1311     test(S("abcde"), 2, 0, SV("1234567890"), 5, 2, S("ab67cde"));
1312     test(S("abcde"), 2, 0, SV("1234567890"), 5, 4, S("ab6789cde"));
1313     test(S("abcde"), 2, 0, SV("1234567890"), 5, 5, S("ab67890cde"));
1314     test(S("abcde"), 2, 0, SV("1234567890"), 5, 6, S("ab67890cde"));
1315     test(S("abcde"), 2, 0, SV("1234567890"), 9, 0, S("abcde"));
1316     test(S("abcde"), 2, 0, SV("1234567890"), 9, 1, S("ab0cde"));
1317     test(S("abcde"), 2, 0, SV("1234567890"), 9, 2, S("ab0cde"));
1318     test(S("abcde"), 2, 0, SV("1234567890"), 10, 0, S("abcde"));
1319     test(S("abcde"), 2, 0, SV("1234567890"), 10, 1, S("abcde"));
1320     test(S("abcde"), 2, 0, SV("1234567890"), 11, 0, S("can't happen"));
1321     test(S("abcde"), 2, 0, SV("12345678901234567890"), 0, 0, S("abcde"));
1322     test(S("abcde"), 2, 0, SV("12345678901234567890"), 0, 1, S("ab1cde"));
1323     test(S("abcde"), 2, 0, SV("12345678901234567890"), 0, 10, S("ab1234567890cde"));
1324     test(S("abcde"), 2, 0, SV("12345678901234567890"), 0, 19, S("ab1234567890123456789cde"));
1325     test(S("abcde"), 2, 0, SV("12345678901234567890"), 0, 20, S("ab12345678901234567890cde"));
1326     test(S("abcde"), 2, 0, SV("12345678901234567890"), 0, 21, S("ab12345678901234567890cde"));
1327     test(S("abcde"), 2, 0, SV("12345678901234567890"), 1, 0, S("abcde"));
1328     test(S("abcde"), 2, 0, SV("12345678901234567890"), 1, 1, S("ab2cde"));
1329     test(S("abcde"), 2, 0, SV("12345678901234567890"), 1, 9, S("ab234567890cde"));
1330     test(S("abcde"), 2, 0, SV("12345678901234567890"), 1, 18, S("ab234567890123456789cde"));
1331     test(S("abcde"), 2, 0, SV("12345678901234567890"), 1, 19, S("ab2345678901234567890cde"));
1332     test(S("abcde"), 2, 0, SV("12345678901234567890"), 1, 20, S("ab2345678901234567890cde"));
1333     test(S("abcde"), 2, 0, SV("12345678901234567890"), 10, 0, S("abcde"));
1334     test(S("abcde"), 2, 0, SV("12345678901234567890"), 10, 1, S("ab1cde"));
1335     test(S("abcde"), 2, 0, SV("12345678901234567890"), 10, 5, S("ab12345cde"));
1336     test(S("abcde"), 2, 0, SV("12345678901234567890"), 10, 9, S("ab123456789cde"));
1337     test(S("abcde"), 2, 0, SV("12345678901234567890"), 10, 10, S("ab1234567890cde"));
1338     test(S("abcde"), 2, 0, SV("12345678901234567890"), 10, 11, S("ab1234567890cde"));
1339     test(S("abcde"), 2, 0, SV("12345678901234567890"), 19, 0, S("abcde"));
1340     test(S("abcde"), 2, 0, SV("12345678901234567890"), 19, 1, S("ab0cde"));
1341     test(S("abcde"), 2, 0, SV("12345678901234567890"), 19, 2, S("ab0cde"));
1342     test(S("abcde"), 2, 0, SV("12345678901234567890"), 20, 0, S("abcde"));
1343     test(S("abcde"), 2, 0, SV("12345678901234567890"), 20, 1, S("abcde"));
1344     test(S("abcde"), 2, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
1345     test(S("abcde"), 2, 1, SV(""), 0, 0, S("abde"));
1346     test(S("abcde"), 2, 1, SV(""), 0, 1, S("abde"));
1347     test(S("abcde"), 2, 1, SV(""), 1, 0, S("can't happen"));
1348     test(S("abcde"), 2, 1, SV("12345"), 0, 0, S("abde"));
1349     test(S("abcde"), 2, 1, SV("12345"), 0, 1, S("ab1de"));
1350     test(S("abcde"), 2, 1, SV("12345"), 0, 2, S("ab12de"));
1351     test(S("abcde"), 2, 1, SV("12345"), 0, 4, S("ab1234de"));
1352     test(S("abcde"), 2, 1, SV("12345"), 0, 5, S("ab12345de"));
1353     test(S("abcde"), 2, 1, SV("12345"), 0, 6, S("ab12345de"));
1354     test(S("abcde"), 2, 1, SV("12345"), 1, 0, S("abde"));
1355     test(S("abcde"), 2, 1, SV("12345"), 1, 1, S("ab2de"));
1356     test(S("abcde"), 2, 1, SV("12345"), 1, 2, S("ab23de"));
1357     test(S("abcde"), 2, 1, SV("12345"), 1, 3, S("ab234de"));
1358     test(S("abcde"), 2, 1, SV("12345"), 1, 4, S("ab2345de"));
1359     test(S("abcde"), 2, 1, SV("12345"), 1, 5, S("ab2345de"));
1360     test(S("abcde"), 2, 1, SV("12345"), 2, 0, S("abde"));
1361 }
1362 
1363 template <class S, class SV>
test12()1364 void test12()
1365 {
1366     test(S("abcde"), 2, 1, SV("12345"), 2, 1, S("ab3de"));
1367     test(S("abcde"), 2, 1, SV("12345"), 2, 2, S("ab34de"));
1368     test(S("abcde"), 2, 1, SV("12345"), 2, 3, S("ab345de"));
1369     test(S("abcde"), 2, 1, SV("12345"), 2, 4, S("ab345de"));
1370     test(S("abcde"), 2, 1, SV("12345"), 4, 0, S("abde"));
1371     test(S("abcde"), 2, 1, SV("12345"), 4, 1, S("ab5de"));
1372     test(S("abcde"), 2, 1, SV("12345"), 4, 2, S("ab5de"));
1373     test(S("abcde"), 2, 1, SV("12345"), 5, 0, S("abde"));
1374     test(S("abcde"), 2, 1, SV("12345"), 5, 1, S("abde"));
1375     test(S("abcde"), 2, 1, SV("12345"), 6, 0, S("can't happen"));
1376     test(S("abcde"), 2, 1, SV("1234567890"), 0, 0, S("abde"));
1377     test(S("abcde"), 2, 1, SV("1234567890"), 0, 1, S("ab1de"));
1378     test(S("abcde"), 2, 1, SV("1234567890"), 0, 5, S("ab12345de"));
1379     test(S("abcde"), 2, 1, SV("1234567890"), 0, 9, S("ab123456789de"));
1380     test(S("abcde"), 2, 1, SV("1234567890"), 0, 10, S("ab1234567890de"));
1381     test(S("abcde"), 2, 1, SV("1234567890"), 0, 11, S("ab1234567890de"));
1382     test(S("abcde"), 2, 1, SV("1234567890"), 1, 0, S("abde"));
1383     test(S("abcde"), 2, 1, SV("1234567890"), 1, 1, S("ab2de"));
1384     test(S("abcde"), 2, 1, SV("1234567890"), 1, 4, S("ab2345de"));
1385     test(S("abcde"), 2, 1, SV("1234567890"), 1, 8, S("ab23456789de"));
1386     test(S("abcde"), 2, 1, SV("1234567890"), 1, 9, S("ab234567890de"));
1387     test(S("abcde"), 2, 1, SV("1234567890"), 1, 10, S("ab234567890de"));
1388     test(S("abcde"), 2, 1, SV("1234567890"), 5, 0, S("abde"));
1389     test(S("abcde"), 2, 1, SV("1234567890"), 5, 1, S("ab6de"));
1390     test(S("abcde"), 2, 1, SV("1234567890"), 5, 2, S("ab67de"));
1391     test(S("abcde"), 2, 1, SV("1234567890"), 5, 4, S("ab6789de"));
1392     test(S("abcde"), 2, 1, SV("1234567890"), 5, 5, S("ab67890de"));
1393     test(S("abcde"), 2, 1, SV("1234567890"), 5, 6, S("ab67890de"));
1394     test(S("abcde"), 2, 1, SV("1234567890"), 9, 0, S("abde"));
1395     test(S("abcde"), 2, 1, SV("1234567890"), 9, 1, S("ab0de"));
1396     test(S("abcde"), 2, 1, SV("1234567890"), 9, 2, S("ab0de"));
1397     test(S("abcde"), 2, 1, SV("1234567890"), 10, 0, S("abde"));
1398     test(S("abcde"), 2, 1, SV("1234567890"), 10, 1, S("abde"));
1399     test(S("abcde"), 2, 1, SV("1234567890"), 11, 0, S("can't happen"));
1400     test(S("abcde"), 2, 1, SV("12345678901234567890"), 0, 0, S("abde"));
1401     test(S("abcde"), 2, 1, SV("12345678901234567890"), 0, 1, S("ab1de"));
1402     test(S("abcde"), 2, 1, SV("12345678901234567890"), 0, 10, S("ab1234567890de"));
1403     test(S("abcde"), 2, 1, SV("12345678901234567890"), 0, 19, S("ab1234567890123456789de"));
1404     test(S("abcde"), 2, 1, SV("12345678901234567890"), 0, 20, S("ab12345678901234567890de"));
1405     test(S("abcde"), 2, 1, SV("12345678901234567890"), 0, 21, S("ab12345678901234567890de"));
1406     test(S("abcde"), 2, 1, SV("12345678901234567890"), 1, 0, S("abde"));
1407     test(S("abcde"), 2, 1, SV("12345678901234567890"), 1, 1, S("ab2de"));
1408     test(S("abcde"), 2, 1, SV("12345678901234567890"), 1, 9, S("ab234567890de"));
1409     test(S("abcde"), 2, 1, SV("12345678901234567890"), 1, 18, S("ab234567890123456789de"));
1410     test(S("abcde"), 2, 1, SV("12345678901234567890"), 1, 19, S("ab2345678901234567890de"));
1411     test(S("abcde"), 2, 1, SV("12345678901234567890"), 1, 20, S("ab2345678901234567890de"));
1412     test(S("abcde"), 2, 1, SV("12345678901234567890"), 10, 0, S("abde"));
1413     test(S("abcde"), 2, 1, SV("12345678901234567890"), 10, 1, S("ab1de"));
1414     test(S("abcde"), 2, 1, SV("12345678901234567890"), 10, 5, S("ab12345de"));
1415     test(S("abcde"), 2, 1, SV("12345678901234567890"), 10, 9, S("ab123456789de"));
1416     test(S("abcde"), 2, 1, SV("12345678901234567890"), 10, 10, S("ab1234567890de"));
1417     test(S("abcde"), 2, 1, SV("12345678901234567890"), 10, 11, S("ab1234567890de"));
1418     test(S("abcde"), 2, 1, SV("12345678901234567890"), 19, 0, S("abde"));
1419     test(S("abcde"), 2, 1, SV("12345678901234567890"), 19, 1, S("ab0de"));
1420     test(S("abcde"), 2, 1, SV("12345678901234567890"), 19, 2, S("ab0de"));
1421     test(S("abcde"), 2, 1, SV("12345678901234567890"), 20, 0, S("abde"));
1422     test(S("abcde"), 2, 1, SV("12345678901234567890"), 20, 1, S("abde"));
1423     test(S("abcde"), 2, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
1424     test(S("abcde"), 2, 2, SV(""), 0, 0, S("abe"));
1425     test(S("abcde"), 2, 2, SV(""), 0, 1, S("abe"));
1426     test(S("abcde"), 2, 2, SV(""), 1, 0, S("can't happen"));
1427     test(S("abcde"), 2, 2, SV("12345"), 0, 0, S("abe"));
1428     test(S("abcde"), 2, 2, SV("12345"), 0, 1, S("ab1e"));
1429     test(S("abcde"), 2, 2, SV("12345"), 0, 2, S("ab12e"));
1430     test(S("abcde"), 2, 2, SV("12345"), 0, 4, S("ab1234e"));
1431     test(S("abcde"), 2, 2, SV("12345"), 0, 5, S("ab12345e"));
1432     test(S("abcde"), 2, 2, SV("12345"), 0, 6, S("ab12345e"));
1433     test(S("abcde"), 2, 2, SV("12345"), 1, 0, S("abe"));
1434     test(S("abcde"), 2, 2, SV("12345"), 1, 1, S("ab2e"));
1435     test(S("abcde"), 2, 2, SV("12345"), 1, 2, S("ab23e"));
1436     test(S("abcde"), 2, 2, SV("12345"), 1, 3, S("ab234e"));
1437     test(S("abcde"), 2, 2, SV("12345"), 1, 4, S("ab2345e"));
1438     test(S("abcde"), 2, 2, SV("12345"), 1, 5, S("ab2345e"));
1439     test(S("abcde"), 2, 2, SV("12345"), 2, 0, S("abe"));
1440     test(S("abcde"), 2, 2, SV("12345"), 2, 1, S("ab3e"));
1441     test(S("abcde"), 2, 2, SV("12345"), 2, 2, S("ab34e"));
1442     test(S("abcde"), 2, 2, SV("12345"), 2, 3, S("ab345e"));
1443     test(S("abcde"), 2, 2, SV("12345"), 2, 4, S("ab345e"));
1444     test(S("abcde"), 2, 2, SV("12345"), 4, 0, S("abe"));
1445     test(S("abcde"), 2, 2, SV("12345"), 4, 1, S("ab5e"));
1446     test(S("abcde"), 2, 2, SV("12345"), 4, 2, S("ab5e"));
1447     test(S("abcde"), 2, 2, SV("12345"), 5, 0, S("abe"));
1448     test(S("abcde"), 2, 2, SV("12345"), 5, 1, S("abe"));
1449     test(S("abcde"), 2, 2, SV("12345"), 6, 0, S("can't happen"));
1450     test(S("abcde"), 2, 2, SV("1234567890"), 0, 0, S("abe"));
1451     test(S("abcde"), 2, 2, SV("1234567890"), 0, 1, S("ab1e"));
1452     test(S("abcde"), 2, 2, SV("1234567890"), 0, 5, S("ab12345e"));
1453     test(S("abcde"), 2, 2, SV("1234567890"), 0, 9, S("ab123456789e"));
1454     test(S("abcde"), 2, 2, SV("1234567890"), 0, 10, S("ab1234567890e"));
1455     test(S("abcde"), 2, 2, SV("1234567890"), 0, 11, S("ab1234567890e"));
1456     test(S("abcde"), 2, 2, SV("1234567890"), 1, 0, S("abe"));
1457     test(S("abcde"), 2, 2, SV("1234567890"), 1, 1, S("ab2e"));
1458     test(S("abcde"), 2, 2, SV("1234567890"), 1, 4, S("ab2345e"));
1459     test(S("abcde"), 2, 2, SV("1234567890"), 1, 8, S("ab23456789e"));
1460     test(S("abcde"), 2, 2, SV("1234567890"), 1, 9, S("ab234567890e"));
1461     test(S("abcde"), 2, 2, SV("1234567890"), 1, 10, S("ab234567890e"));
1462     test(S("abcde"), 2, 2, SV("1234567890"), 5, 0, S("abe"));
1463     test(S("abcde"), 2, 2, SV("1234567890"), 5, 1, S("ab6e"));
1464     test(S("abcde"), 2, 2, SV("1234567890"), 5, 2, S("ab67e"));
1465     test(S("abcde"), 2, 2, SV("1234567890"), 5, 4, S("ab6789e"));
1466 }
1467 
1468 template <class S, class SV>
test13()1469 void test13()
1470 {
1471     test(S("abcde"), 2, 2, SV("1234567890"), 5, 5, S("ab67890e"));
1472     test(S("abcde"), 2, 2, SV("1234567890"), 5, 6, S("ab67890e"));
1473     test(S("abcde"), 2, 2, SV("1234567890"), 9, 0, S("abe"));
1474     test(S("abcde"), 2, 2, SV("1234567890"), 9, 1, S("ab0e"));
1475     test(S("abcde"), 2, 2, SV("1234567890"), 9, 2, S("ab0e"));
1476     test(S("abcde"), 2, 2, SV("1234567890"), 10, 0, S("abe"));
1477     test(S("abcde"), 2, 2, SV("1234567890"), 10, 1, S("abe"));
1478     test(S("abcde"), 2, 2, SV("1234567890"), 11, 0, S("can't happen"));
1479     test(S("abcde"), 2, 2, SV("12345678901234567890"), 0, 0, S("abe"));
1480     test(S("abcde"), 2, 2, SV("12345678901234567890"), 0, 1, S("ab1e"));
1481     test(S("abcde"), 2, 2, SV("12345678901234567890"), 0, 10, S("ab1234567890e"));
1482     test(S("abcde"), 2, 2, SV("12345678901234567890"), 0, 19, S("ab1234567890123456789e"));
1483     test(S("abcde"), 2, 2, SV("12345678901234567890"), 0, 20, S("ab12345678901234567890e"));
1484     test(S("abcde"), 2, 2, SV("12345678901234567890"), 0, 21, S("ab12345678901234567890e"));
1485     test(S("abcde"), 2, 2, SV("12345678901234567890"), 1, 0, S("abe"));
1486     test(S("abcde"), 2, 2, SV("12345678901234567890"), 1, 1, S("ab2e"));
1487     test(S("abcde"), 2, 2, SV("12345678901234567890"), 1, 9, S("ab234567890e"));
1488     test(S("abcde"), 2, 2, SV("12345678901234567890"), 1, 18, S("ab234567890123456789e"));
1489     test(S("abcde"), 2, 2, SV("12345678901234567890"), 1, 19, S("ab2345678901234567890e"));
1490     test(S("abcde"), 2, 2, SV("12345678901234567890"), 1, 20, S("ab2345678901234567890e"));
1491     test(S("abcde"), 2, 2, SV("12345678901234567890"), 10, 0, S("abe"));
1492     test(S("abcde"), 2, 2, SV("12345678901234567890"), 10, 1, S("ab1e"));
1493     test(S("abcde"), 2, 2, SV("12345678901234567890"), 10, 5, S("ab12345e"));
1494     test(S("abcde"), 2, 2, SV("12345678901234567890"), 10, 9, S("ab123456789e"));
1495     test(S("abcde"), 2, 2, SV("12345678901234567890"), 10, 10, S("ab1234567890e"));
1496     test(S("abcde"), 2, 2, SV("12345678901234567890"), 10, 11, S("ab1234567890e"));
1497     test(S("abcde"), 2, 2, SV("12345678901234567890"), 19, 0, S("abe"));
1498     test(S("abcde"), 2, 2, SV("12345678901234567890"), 19, 1, S("ab0e"));
1499     test(S("abcde"), 2, 2, SV("12345678901234567890"), 19, 2, S("ab0e"));
1500     test(S("abcde"), 2, 2, SV("12345678901234567890"), 20, 0, S("abe"));
1501     test(S("abcde"), 2, 2, SV("12345678901234567890"), 20, 1, S("abe"));
1502     test(S("abcde"), 2, 2, SV("12345678901234567890"), 21, 0, S("can't happen"));
1503     test(S("abcde"), 2, 3, SV(""), 0, 0, S("ab"));
1504     test(S("abcde"), 2, 3, SV(""), 0, 1, S("ab"));
1505     test(S("abcde"), 2, 3, SV(""), 1, 0, S("can't happen"));
1506     test(S("abcde"), 2, 3, SV("12345"), 0, 0, S("ab"));
1507     test(S("abcde"), 2, 3, SV("12345"), 0, 1, S("ab1"));
1508     test(S("abcde"), 2, 3, SV("12345"), 0, 2, S("ab12"));
1509     test(S("abcde"), 2, 3, SV("12345"), 0, 4, S("ab1234"));
1510     test(S("abcde"), 2, 3, SV("12345"), 0, 5, S("ab12345"));
1511     test(S("abcde"), 2, 3, SV("12345"), 0, 6, S("ab12345"));
1512     test(S("abcde"), 2, 3, SV("12345"), 1, 0, S("ab"));
1513     test(S("abcde"), 2, 3, SV("12345"), 1, 1, S("ab2"));
1514     test(S("abcde"), 2, 3, SV("12345"), 1, 2, S("ab23"));
1515     test(S("abcde"), 2, 3, SV("12345"), 1, 3, S("ab234"));
1516     test(S("abcde"), 2, 3, SV("12345"), 1, 4, S("ab2345"));
1517     test(S("abcde"), 2, 3, SV("12345"), 1, 5, S("ab2345"));
1518     test(S("abcde"), 2, 3, SV("12345"), 2, 0, S("ab"));
1519     test(S("abcde"), 2, 3, SV("12345"), 2, 1, S("ab3"));
1520     test(S("abcde"), 2, 3, SV("12345"), 2, 2, S("ab34"));
1521     test(S("abcde"), 2, 3, SV("12345"), 2, 3, S("ab345"));
1522     test(S("abcde"), 2, 3, SV("12345"), 2, 4, S("ab345"));
1523     test(S("abcde"), 2, 3, SV("12345"), 4, 0, S("ab"));
1524     test(S("abcde"), 2, 3, SV("12345"), 4, 1, S("ab5"));
1525     test(S("abcde"), 2, 3, SV("12345"), 4, 2, S("ab5"));
1526     test(S("abcde"), 2, 3, SV("12345"), 5, 0, S("ab"));
1527     test(S("abcde"), 2, 3, SV("12345"), 5, 1, S("ab"));
1528     test(S("abcde"), 2, 3, SV("12345"), 6, 0, S("can't happen"));
1529     test(S("abcde"), 2, 3, SV("1234567890"), 0, 0, S("ab"));
1530     test(S("abcde"), 2, 3, SV("1234567890"), 0, 1, S("ab1"));
1531     test(S("abcde"), 2, 3, SV("1234567890"), 0, 5, S("ab12345"));
1532     test(S("abcde"), 2, 3, SV("1234567890"), 0, 9, S("ab123456789"));
1533     test(S("abcde"), 2, 3, SV("1234567890"), 0, 10, S("ab1234567890"));
1534     test(S("abcde"), 2, 3, SV("1234567890"), 0, 11, S("ab1234567890"));
1535     test(S("abcde"), 2, 3, SV("1234567890"), 1, 0, S("ab"));
1536     test(S("abcde"), 2, 3, SV("1234567890"), 1, 1, S("ab2"));
1537     test(S("abcde"), 2, 3, SV("1234567890"), 1, 4, S("ab2345"));
1538     test(S("abcde"), 2, 3, SV("1234567890"), 1, 8, S("ab23456789"));
1539     test(S("abcde"), 2, 3, SV("1234567890"), 1, 9, S("ab234567890"));
1540     test(S("abcde"), 2, 3, SV("1234567890"), 1, 10, S("ab234567890"));
1541     test(S("abcde"), 2, 3, SV("1234567890"), 5, 0, S("ab"));
1542     test(S("abcde"), 2, 3, SV("1234567890"), 5, 1, S("ab6"));
1543     test(S("abcde"), 2, 3, SV("1234567890"), 5, 2, S("ab67"));
1544     test(S("abcde"), 2, 3, SV("1234567890"), 5, 4, S("ab6789"));
1545     test(S("abcde"), 2, 3, SV("1234567890"), 5, 5, S("ab67890"));
1546     test(S("abcde"), 2, 3, SV("1234567890"), 5, 6, S("ab67890"));
1547     test(S("abcde"), 2, 3, SV("1234567890"), 9, 0, S("ab"));
1548     test(S("abcde"), 2, 3, SV("1234567890"), 9, 1, S("ab0"));
1549     test(S("abcde"), 2, 3, SV("1234567890"), 9, 2, S("ab0"));
1550     test(S("abcde"), 2, 3, SV("1234567890"), 10, 0, S("ab"));
1551     test(S("abcde"), 2, 3, SV("1234567890"), 10, 1, S("ab"));
1552     test(S("abcde"), 2, 3, SV("1234567890"), 11, 0, S("can't happen"));
1553     test(S("abcde"), 2, 3, SV("12345678901234567890"), 0, 0, S("ab"));
1554     test(S("abcde"), 2, 3, SV("12345678901234567890"), 0, 1, S("ab1"));
1555     test(S("abcde"), 2, 3, SV("12345678901234567890"), 0, 10, S("ab1234567890"));
1556     test(S("abcde"), 2, 3, SV("12345678901234567890"), 0, 19, S("ab1234567890123456789"));
1557     test(S("abcde"), 2, 3, SV("12345678901234567890"), 0, 20, S("ab12345678901234567890"));
1558     test(S("abcde"), 2, 3, SV("12345678901234567890"), 0, 21, S("ab12345678901234567890"));
1559     test(S("abcde"), 2, 3, SV("12345678901234567890"), 1, 0, S("ab"));
1560     test(S("abcde"), 2, 3, SV("12345678901234567890"), 1, 1, S("ab2"));
1561     test(S("abcde"), 2, 3, SV("12345678901234567890"), 1, 9, S("ab234567890"));
1562     test(S("abcde"), 2, 3, SV("12345678901234567890"), 1, 18, S("ab234567890123456789"));
1563     test(S("abcde"), 2, 3, SV("12345678901234567890"), 1, 19, S("ab2345678901234567890"));
1564     test(S("abcde"), 2, 3, SV("12345678901234567890"), 1, 20, S("ab2345678901234567890"));
1565     test(S("abcde"), 2, 3, SV("12345678901234567890"), 10, 0, S("ab"));
1566     test(S("abcde"), 2, 3, SV("12345678901234567890"), 10, 1, S("ab1"));
1567     test(S("abcde"), 2, 3, SV("12345678901234567890"), 10, 5, S("ab12345"));
1568     test(S("abcde"), 2, 3, SV("12345678901234567890"), 10, 9, S("ab123456789"));
1569     test(S("abcde"), 2, 3, SV("12345678901234567890"), 10, 10, S("ab1234567890"));
1570     test(S("abcde"), 2, 3, SV("12345678901234567890"), 10, 11, S("ab1234567890"));
1571 }
1572 
1573 template <class S, class SV>
test14()1574 void test14()
1575 {
1576     test(S("abcde"), 2, 3, SV("12345678901234567890"), 19, 0, S("ab"));
1577     test(S("abcde"), 2, 3, SV("12345678901234567890"), 19, 1, S("ab0"));
1578     test(S("abcde"), 2, 3, SV("12345678901234567890"), 19, 2, S("ab0"));
1579     test(S("abcde"), 2, 3, SV("12345678901234567890"), 20, 0, S("ab"));
1580     test(S("abcde"), 2, 3, SV("12345678901234567890"), 20, 1, S("ab"));
1581     test(S("abcde"), 2, 3, SV("12345678901234567890"), 21, 0, S("can't happen"));
1582     test(S("abcde"), 2, 4, SV(""), 0, 0, S("ab"));
1583     test(S("abcde"), 2, 4, SV(""), 0, 1, S("ab"));
1584     test(S("abcde"), 2, 4, SV(""), 1, 0, S("can't happen"));
1585     test(S("abcde"), 2, 4, SV("12345"), 0, 0, S("ab"));
1586     test(S("abcde"), 2, 4, SV("12345"), 0, 1, S("ab1"));
1587     test(S("abcde"), 2, 4, SV("12345"), 0, 2, S("ab12"));
1588     test(S("abcde"), 2, 4, SV("12345"), 0, 4, S("ab1234"));
1589     test(S("abcde"), 2, 4, SV("12345"), 0, 5, S("ab12345"));
1590     test(S("abcde"), 2, 4, SV("12345"), 0, 6, S("ab12345"));
1591     test(S("abcde"), 2, 4, SV("12345"), 1, 0, S("ab"));
1592     test(S("abcde"), 2, 4, SV("12345"), 1, 1, S("ab2"));
1593     test(S("abcde"), 2, 4, SV("12345"), 1, 2, S("ab23"));
1594     test(S("abcde"), 2, 4, SV("12345"), 1, 3, S("ab234"));
1595     test(S("abcde"), 2, 4, SV("12345"), 1, 4, S("ab2345"));
1596     test(S("abcde"), 2, 4, SV("12345"), 1, 5, S("ab2345"));
1597     test(S("abcde"), 2, 4, SV("12345"), 2, 0, S("ab"));
1598     test(S("abcde"), 2, 4, SV("12345"), 2, 1, S("ab3"));
1599     test(S("abcde"), 2, 4, SV("12345"), 2, 2, S("ab34"));
1600     test(S("abcde"), 2, 4, SV("12345"), 2, 3, S("ab345"));
1601     test(S("abcde"), 2, 4, SV("12345"), 2, 4, S("ab345"));
1602     test(S("abcde"), 2, 4, SV("12345"), 4, 0, S("ab"));
1603     test(S("abcde"), 2, 4, SV("12345"), 4, 1, S("ab5"));
1604     test(S("abcde"), 2, 4, SV("12345"), 4, 2, S("ab5"));
1605     test(S("abcde"), 2, 4, SV("12345"), 5, 0, S("ab"));
1606     test(S("abcde"), 2, 4, SV("12345"), 5, 1, S("ab"));
1607     test(S("abcde"), 2, 4, SV("12345"), 6, 0, S("can't happen"));
1608     test(S("abcde"), 2, 4, SV("1234567890"), 0, 0, S("ab"));
1609     test(S("abcde"), 2, 4, SV("1234567890"), 0, 1, S("ab1"));
1610     test(S("abcde"), 2, 4, SV("1234567890"), 0, 5, S("ab12345"));
1611     test(S("abcde"), 2, 4, SV("1234567890"), 0, 9, S("ab123456789"));
1612     test(S("abcde"), 2, 4, SV("1234567890"), 0, 10, S("ab1234567890"));
1613     test(S("abcde"), 2, 4, SV("1234567890"), 0, 11, S("ab1234567890"));
1614     test(S("abcde"), 2, 4, SV("1234567890"), 1, 0, S("ab"));
1615     test(S("abcde"), 2, 4, SV("1234567890"), 1, 1, S("ab2"));
1616     test(S("abcde"), 2, 4, SV("1234567890"), 1, 4, S("ab2345"));
1617     test(S("abcde"), 2, 4, SV("1234567890"), 1, 8, S("ab23456789"));
1618     test(S("abcde"), 2, 4, SV("1234567890"), 1, 9, S("ab234567890"));
1619     test(S("abcde"), 2, 4, SV("1234567890"), 1, 10, S("ab234567890"));
1620     test(S("abcde"), 2, 4, SV("1234567890"), 5, 0, S("ab"));
1621     test(S("abcde"), 2, 4, SV("1234567890"), 5, 1, S("ab6"));
1622     test(S("abcde"), 2, 4, SV("1234567890"), 5, 2, S("ab67"));
1623     test(S("abcde"), 2, 4, SV("1234567890"), 5, 4, S("ab6789"));
1624     test(S("abcde"), 2, 4, SV("1234567890"), 5, 5, S("ab67890"));
1625     test(S("abcde"), 2, 4, SV("1234567890"), 5, 6, S("ab67890"));
1626     test(S("abcde"), 2, 4, SV("1234567890"), 9, 0, S("ab"));
1627     test(S("abcde"), 2, 4, SV("1234567890"), 9, 1, S("ab0"));
1628     test(S("abcde"), 2, 4, SV("1234567890"), 9, 2, S("ab0"));
1629     test(S("abcde"), 2, 4, SV("1234567890"), 10, 0, S("ab"));
1630     test(S("abcde"), 2, 4, SV("1234567890"), 10, 1, S("ab"));
1631     test(S("abcde"), 2, 4, SV("1234567890"), 11, 0, S("can't happen"));
1632     test(S("abcde"), 2, 4, SV("12345678901234567890"), 0, 0, S("ab"));
1633     test(S("abcde"), 2, 4, SV("12345678901234567890"), 0, 1, S("ab1"));
1634     test(S("abcde"), 2, 4, SV("12345678901234567890"), 0, 10, S("ab1234567890"));
1635     test(S("abcde"), 2, 4, SV("12345678901234567890"), 0, 19, S("ab1234567890123456789"));
1636     test(S("abcde"), 2, 4, SV("12345678901234567890"), 0, 20, S("ab12345678901234567890"));
1637     test(S("abcde"), 2, 4, SV("12345678901234567890"), 0, 21, S("ab12345678901234567890"));
1638     test(S("abcde"), 2, 4, SV("12345678901234567890"), 1, 0, S("ab"));
1639     test(S("abcde"), 2, 4, SV("12345678901234567890"), 1, 1, S("ab2"));
1640     test(S("abcde"), 2, 4, SV("12345678901234567890"), 1, 9, S("ab234567890"));
1641     test(S("abcde"), 2, 4, SV("12345678901234567890"), 1, 18, S("ab234567890123456789"));
1642     test(S("abcde"), 2, 4, SV("12345678901234567890"), 1, 19, S("ab2345678901234567890"));
1643     test(S("abcde"), 2, 4, SV("12345678901234567890"), 1, 20, S("ab2345678901234567890"));
1644     test(S("abcde"), 2, 4, SV("12345678901234567890"), 10, 0, S("ab"));
1645     test(S("abcde"), 2, 4, SV("12345678901234567890"), 10, 1, S("ab1"));
1646     test(S("abcde"), 2, 4, SV("12345678901234567890"), 10, 5, S("ab12345"));
1647     test(S("abcde"), 2, 4, SV("12345678901234567890"), 10, 9, S("ab123456789"));
1648     test(S("abcde"), 2, 4, SV("12345678901234567890"), 10, 10, S("ab1234567890"));
1649     test(S("abcde"), 2, 4, SV("12345678901234567890"), 10, 11, S("ab1234567890"));
1650     test(S("abcde"), 2, 4, SV("12345678901234567890"), 19, 0, S("ab"));
1651     test(S("abcde"), 2, 4, SV("12345678901234567890"), 19, 1, S("ab0"));
1652     test(S("abcde"), 2, 4, SV("12345678901234567890"), 19, 2, S("ab0"));
1653     test(S("abcde"), 2, 4, SV("12345678901234567890"), 20, 0, S("ab"));
1654     test(S("abcde"), 2, 4, SV("12345678901234567890"), 20, 1, S("ab"));
1655     test(S("abcde"), 2, 4, SV("12345678901234567890"), 21, 0, S("can't happen"));
1656     test(S("abcde"), 4, 0, SV(""), 0, 0, S("abcde"));
1657     test(S("abcde"), 4, 0, SV(""), 0, 1, S("abcde"));
1658     test(S("abcde"), 4, 0, SV(""), 1, 0, S("can't happen"));
1659     test(S("abcde"), 4, 0, SV("12345"), 0, 0, S("abcde"));
1660     test(S("abcde"), 4, 0, SV("12345"), 0, 1, S("abcd1e"));
1661     test(S("abcde"), 4, 0, SV("12345"), 0, 2, S("abcd12e"));
1662     test(S("abcde"), 4, 0, SV("12345"), 0, 4, S("abcd1234e"));
1663     test(S("abcde"), 4, 0, SV("12345"), 0, 5, S("abcd12345e"));
1664     test(S("abcde"), 4, 0, SV("12345"), 0, 6, S("abcd12345e"));
1665     test(S("abcde"), 4, 0, SV("12345"), 1, 0, S("abcde"));
1666     test(S("abcde"), 4, 0, SV("12345"), 1, 1, S("abcd2e"));
1667     test(S("abcde"), 4, 0, SV("12345"), 1, 2, S("abcd23e"));
1668     test(S("abcde"), 4, 0, SV("12345"), 1, 3, S("abcd234e"));
1669     test(S("abcde"), 4, 0, SV("12345"), 1, 4, S("abcd2345e"));
1670     test(S("abcde"), 4, 0, SV("12345"), 1, 5, S("abcd2345e"));
1671     test(S("abcde"), 4, 0, SV("12345"), 2, 0, S("abcde"));
1672     test(S("abcde"), 4, 0, SV("12345"), 2, 1, S("abcd3e"));
1673     test(S("abcde"), 4, 0, SV("12345"), 2, 2, S("abcd34e"));
1674     test(S("abcde"), 4, 0, SV("12345"), 2, 3, S("abcd345e"));
1675     test(S("abcde"), 4, 0, SV("12345"), 2, 4, S("abcd345e"));
1676 }
1677 
1678 template <class S, class SV>
test15()1679 void test15()
1680 {
1681     test(S("abcde"), 4, 0, SV("12345"), 4, 0, S("abcde"));
1682     test(S("abcde"), 4, 0, SV("12345"), 4, 1, S("abcd5e"));
1683     test(S("abcde"), 4, 0, SV("12345"), 4, 2, S("abcd5e"));
1684     test(S("abcde"), 4, 0, SV("12345"), 5, 0, S("abcde"));
1685     test(S("abcde"), 4, 0, SV("12345"), 5, 1, S("abcde"));
1686     test(S("abcde"), 4, 0, SV("12345"), 6, 0, S("can't happen"));
1687     test(S("abcde"), 4, 0, SV("1234567890"), 0, 0, S("abcde"));
1688     test(S("abcde"), 4, 0, SV("1234567890"), 0, 1, S("abcd1e"));
1689     test(S("abcde"), 4, 0, SV("1234567890"), 0, 5, S("abcd12345e"));
1690     test(S("abcde"), 4, 0, SV("1234567890"), 0, 9, S("abcd123456789e"));
1691     test(S("abcde"), 4, 0, SV("1234567890"), 0, 10, S("abcd1234567890e"));
1692     test(S("abcde"), 4, 0, SV("1234567890"), 0, 11, S("abcd1234567890e"));
1693     test(S("abcde"), 4, 0, SV("1234567890"), 1, 0, S("abcde"));
1694     test(S("abcde"), 4, 0, SV("1234567890"), 1, 1, S("abcd2e"));
1695     test(S("abcde"), 4, 0, SV("1234567890"), 1, 4, S("abcd2345e"));
1696     test(S("abcde"), 4, 0, SV("1234567890"), 1, 8, S("abcd23456789e"));
1697     test(S("abcde"), 4, 0, SV("1234567890"), 1, 9, S("abcd234567890e"));
1698     test(S("abcde"), 4, 0, SV("1234567890"), 1, 10, S("abcd234567890e"));
1699     test(S("abcde"), 4, 0, SV("1234567890"), 5, 0, S("abcde"));
1700     test(S("abcde"), 4, 0, SV("1234567890"), 5, 1, S("abcd6e"));
1701     test(S("abcde"), 4, 0, SV("1234567890"), 5, 2, S("abcd67e"));
1702     test(S("abcde"), 4, 0, SV("1234567890"), 5, 4, S("abcd6789e"));
1703     test(S("abcde"), 4, 0, SV("1234567890"), 5, 5, S("abcd67890e"));
1704     test(S("abcde"), 4, 0, SV("1234567890"), 5, 6, S("abcd67890e"));
1705     test(S("abcde"), 4, 0, SV("1234567890"), 9, 0, S("abcde"));
1706     test(S("abcde"), 4, 0, SV("1234567890"), 9, 1, S("abcd0e"));
1707     test(S("abcde"), 4, 0, SV("1234567890"), 9, 2, S("abcd0e"));
1708     test(S("abcde"), 4, 0, SV("1234567890"), 10, 0, S("abcde"));
1709     test(S("abcde"), 4, 0, SV("1234567890"), 10, 1, S("abcde"));
1710     test(S("abcde"), 4, 0, SV("1234567890"), 11, 0, S("can't happen"));
1711     test(S("abcde"), 4, 0, SV("12345678901234567890"), 0, 0, S("abcde"));
1712     test(S("abcde"), 4, 0, SV("12345678901234567890"), 0, 1, S("abcd1e"));
1713     test(S("abcde"), 4, 0, SV("12345678901234567890"), 0, 10, S("abcd1234567890e"));
1714     test(S("abcde"), 4, 0, SV("12345678901234567890"), 0, 19, S("abcd1234567890123456789e"));
1715     test(S("abcde"), 4, 0, SV("12345678901234567890"), 0, 20, S("abcd12345678901234567890e"));
1716     test(S("abcde"), 4, 0, SV("12345678901234567890"), 0, 21, S("abcd12345678901234567890e"));
1717     test(S("abcde"), 4, 0, SV("12345678901234567890"), 1, 0, S("abcde"));
1718     test(S("abcde"), 4, 0, SV("12345678901234567890"), 1, 1, S("abcd2e"));
1719     test(S("abcde"), 4, 0, SV("12345678901234567890"), 1, 9, S("abcd234567890e"));
1720     test(S("abcde"), 4, 0, SV("12345678901234567890"), 1, 18, S("abcd234567890123456789e"));
1721     test(S("abcde"), 4, 0, SV("12345678901234567890"), 1, 19, S("abcd2345678901234567890e"));
1722     test(S("abcde"), 4, 0, SV("12345678901234567890"), 1, 20, S("abcd2345678901234567890e"));
1723     test(S("abcde"), 4, 0, SV("12345678901234567890"), 10, 0, S("abcde"));
1724     test(S("abcde"), 4, 0, SV("12345678901234567890"), 10, 1, S("abcd1e"));
1725     test(S("abcde"), 4, 0, SV("12345678901234567890"), 10, 5, S("abcd12345e"));
1726     test(S("abcde"), 4, 0, SV("12345678901234567890"), 10, 9, S("abcd123456789e"));
1727     test(S("abcde"), 4, 0, SV("12345678901234567890"), 10, 10, S("abcd1234567890e"));
1728     test(S("abcde"), 4, 0, SV("12345678901234567890"), 10, 11, S("abcd1234567890e"));
1729     test(S("abcde"), 4, 0, SV("12345678901234567890"), 19, 0, S("abcde"));
1730     test(S("abcde"), 4, 0, SV("12345678901234567890"), 19, 1, S("abcd0e"));
1731     test(S("abcde"), 4, 0, SV("12345678901234567890"), 19, 2, S("abcd0e"));
1732     test(S("abcde"), 4, 0, SV("12345678901234567890"), 20, 0, S("abcde"));
1733     test(S("abcde"), 4, 0, SV("12345678901234567890"), 20, 1, S("abcde"));
1734     test(S("abcde"), 4, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
1735     test(S("abcde"), 4, 1, SV(""), 0, 0, S("abcd"));
1736     test(S("abcde"), 4, 1, SV(""), 0, 1, S("abcd"));
1737     test(S("abcde"), 4, 1, SV(""), 1, 0, S("can't happen"));
1738     test(S("abcde"), 4, 1, SV("12345"), 0, 0, S("abcd"));
1739     test(S("abcde"), 4, 1, SV("12345"), 0, 1, S("abcd1"));
1740     test(S("abcde"), 4, 1, SV("12345"), 0, 2, S("abcd12"));
1741     test(S("abcde"), 4, 1, SV("12345"), 0, 4, S("abcd1234"));
1742     test(S("abcde"), 4, 1, SV("12345"), 0, 5, S("abcd12345"));
1743     test(S("abcde"), 4, 1, SV("12345"), 0, 6, S("abcd12345"));
1744     test(S("abcde"), 4, 1, SV("12345"), 1, 0, S("abcd"));
1745     test(S("abcde"), 4, 1, SV("12345"), 1, 1, S("abcd2"));
1746     test(S("abcde"), 4, 1, SV("12345"), 1, 2, S("abcd23"));
1747     test(S("abcde"), 4, 1, SV("12345"), 1, 3, S("abcd234"));
1748     test(S("abcde"), 4, 1, SV("12345"), 1, 4, S("abcd2345"));
1749     test(S("abcde"), 4, 1, SV("12345"), 1, 5, S("abcd2345"));
1750     test(S("abcde"), 4, 1, SV("12345"), 2, 0, S("abcd"));
1751     test(S("abcde"), 4, 1, SV("12345"), 2, 1, S("abcd3"));
1752     test(S("abcde"), 4, 1, SV("12345"), 2, 2, S("abcd34"));
1753     test(S("abcde"), 4, 1, SV("12345"), 2, 3, S("abcd345"));
1754     test(S("abcde"), 4, 1, SV("12345"), 2, 4, S("abcd345"));
1755     test(S("abcde"), 4, 1, SV("12345"), 4, 0, S("abcd"));
1756     test(S("abcde"), 4, 1, SV("12345"), 4, 1, S("abcd5"));
1757     test(S("abcde"), 4, 1, SV("12345"), 4, 2, S("abcd5"));
1758     test(S("abcde"), 4, 1, SV("12345"), 5, 0, S("abcd"));
1759     test(S("abcde"), 4, 1, SV("12345"), 5, 1, S("abcd"));
1760     test(S("abcde"), 4, 1, SV("12345"), 6, 0, S("can't happen"));
1761     test(S("abcde"), 4, 1, SV("1234567890"), 0, 0, S("abcd"));
1762     test(S("abcde"), 4, 1, SV("1234567890"), 0, 1, S("abcd1"));
1763     test(S("abcde"), 4, 1, SV("1234567890"), 0, 5, S("abcd12345"));
1764     test(S("abcde"), 4, 1, SV("1234567890"), 0, 9, S("abcd123456789"));
1765     test(S("abcde"), 4, 1, SV("1234567890"), 0, 10, S("abcd1234567890"));
1766     test(S("abcde"), 4, 1, SV("1234567890"), 0, 11, S("abcd1234567890"));
1767     test(S("abcde"), 4, 1, SV("1234567890"), 1, 0, S("abcd"));
1768     test(S("abcde"), 4, 1, SV("1234567890"), 1, 1, S("abcd2"));
1769     test(S("abcde"), 4, 1, SV("1234567890"), 1, 4, S("abcd2345"));
1770     test(S("abcde"), 4, 1, SV("1234567890"), 1, 8, S("abcd23456789"));
1771     test(S("abcde"), 4, 1, SV("1234567890"), 1, 9, S("abcd234567890"));
1772     test(S("abcde"), 4, 1, SV("1234567890"), 1, 10, S("abcd234567890"));
1773     test(S("abcde"), 4, 1, SV("1234567890"), 5, 0, S("abcd"));
1774     test(S("abcde"), 4, 1, SV("1234567890"), 5, 1, S("abcd6"));
1775     test(S("abcde"), 4, 1, SV("1234567890"), 5, 2, S("abcd67"));
1776     test(S("abcde"), 4, 1, SV("1234567890"), 5, 4, S("abcd6789"));
1777     test(S("abcde"), 4, 1, SV("1234567890"), 5, 5, S("abcd67890"));
1778     test(S("abcde"), 4, 1, SV("1234567890"), 5, 6, S("abcd67890"));
1779     test(S("abcde"), 4, 1, SV("1234567890"), 9, 0, S("abcd"));
1780     test(S("abcde"), 4, 1, SV("1234567890"), 9, 1, S("abcd0"));
1781 }
1782 
1783 template <class S, class SV>
test16()1784 void test16()
1785 {
1786     test(S("abcde"), 4, 1, SV("1234567890"), 9, 2, S("abcd0"));
1787     test(S("abcde"), 4, 1, SV("1234567890"), 10, 0, S("abcd"));
1788     test(S("abcde"), 4, 1, SV("1234567890"), 10, 1, S("abcd"));
1789     test(S("abcde"), 4, 1, SV("1234567890"), 11, 0, S("can't happen"));
1790     test(S("abcde"), 4, 1, SV("12345678901234567890"), 0, 0, S("abcd"));
1791     test(S("abcde"), 4, 1, SV("12345678901234567890"), 0, 1, S("abcd1"));
1792     test(S("abcde"), 4, 1, SV("12345678901234567890"), 0, 10, S("abcd1234567890"));
1793     test(S("abcde"), 4, 1, SV("12345678901234567890"), 0, 19, S("abcd1234567890123456789"));
1794     test(S("abcde"), 4, 1, SV("12345678901234567890"), 0, 20, S("abcd12345678901234567890"));
1795     test(S("abcde"), 4, 1, SV("12345678901234567890"), 0, 21, S("abcd12345678901234567890"));
1796     test(S("abcde"), 4, 1, SV("12345678901234567890"), 1, 0, S("abcd"));
1797     test(S("abcde"), 4, 1, SV("12345678901234567890"), 1, 1, S("abcd2"));
1798     test(S("abcde"), 4, 1, SV("12345678901234567890"), 1, 9, S("abcd234567890"));
1799     test(S("abcde"), 4, 1, SV("12345678901234567890"), 1, 18, S("abcd234567890123456789"));
1800     test(S("abcde"), 4, 1, SV("12345678901234567890"), 1, 19, S("abcd2345678901234567890"));
1801     test(S("abcde"), 4, 1, SV("12345678901234567890"), 1, 20, S("abcd2345678901234567890"));
1802     test(S("abcde"), 4, 1, SV("12345678901234567890"), 10, 0, S("abcd"));
1803     test(S("abcde"), 4, 1, SV("12345678901234567890"), 10, 1, S("abcd1"));
1804     test(S("abcde"), 4, 1, SV("12345678901234567890"), 10, 5, S("abcd12345"));
1805     test(S("abcde"), 4, 1, SV("12345678901234567890"), 10, 9, S("abcd123456789"));
1806     test(S("abcde"), 4, 1, SV("12345678901234567890"), 10, 10, S("abcd1234567890"));
1807     test(S("abcde"), 4, 1, SV("12345678901234567890"), 10, 11, S("abcd1234567890"));
1808     test(S("abcde"), 4, 1, SV("12345678901234567890"), 19, 0, S("abcd"));
1809     test(S("abcde"), 4, 1, SV("12345678901234567890"), 19, 1, S("abcd0"));
1810     test(S("abcde"), 4, 1, SV("12345678901234567890"), 19, 2, S("abcd0"));
1811     test(S("abcde"), 4, 1, SV("12345678901234567890"), 20, 0, S("abcd"));
1812     test(S("abcde"), 4, 1, SV("12345678901234567890"), 20, 1, S("abcd"));
1813     test(S("abcde"), 4, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
1814     test(S("abcde"), 4, 2, SV(""), 0, 0, S("abcd"));
1815     test(S("abcde"), 4, 2, SV(""), 0, 1, S("abcd"));
1816     test(S("abcde"), 4, 2, SV(""), 1, 0, S("can't happen"));
1817     test(S("abcde"), 4, 2, SV("12345"), 0, 0, S("abcd"));
1818     test(S("abcde"), 4, 2, SV("12345"), 0, 1, S("abcd1"));
1819     test(S("abcde"), 4, 2, SV("12345"), 0, 2, S("abcd12"));
1820     test(S("abcde"), 4, 2, SV("12345"), 0, 4, S("abcd1234"));
1821     test(S("abcde"), 4, 2, SV("12345"), 0, 5, S("abcd12345"));
1822     test(S("abcde"), 4, 2, SV("12345"), 0, 6, S("abcd12345"));
1823     test(S("abcde"), 4, 2, SV("12345"), 1, 0, S("abcd"));
1824     test(S("abcde"), 4, 2, SV("12345"), 1, 1, S("abcd2"));
1825     test(S("abcde"), 4, 2, SV("12345"), 1, 2, S("abcd23"));
1826     test(S("abcde"), 4, 2, SV("12345"), 1, 3, S("abcd234"));
1827     test(S("abcde"), 4, 2, SV("12345"), 1, 4, S("abcd2345"));
1828     test(S("abcde"), 4, 2, SV("12345"), 1, 5, S("abcd2345"));
1829     test(S("abcde"), 4, 2, SV("12345"), 2, 0, S("abcd"));
1830     test(S("abcde"), 4, 2, SV("12345"), 2, 1, S("abcd3"));
1831     test(S("abcde"), 4, 2, SV("12345"), 2, 2, S("abcd34"));
1832     test(S("abcde"), 4, 2, SV("12345"), 2, 3, S("abcd345"));
1833     test(S("abcde"), 4, 2, SV("12345"), 2, 4, S("abcd345"));
1834     test(S("abcde"), 4, 2, SV("12345"), 4, 0, S("abcd"));
1835     test(S("abcde"), 4, 2, SV("12345"), 4, 1, S("abcd5"));
1836     test(S("abcde"), 4, 2, SV("12345"), 4, 2, S("abcd5"));
1837     test(S("abcde"), 4, 2, SV("12345"), 5, 0, S("abcd"));
1838     test(S("abcde"), 4, 2, SV("12345"), 5, 1, S("abcd"));
1839     test(S("abcde"), 4, 2, SV("12345"), 6, 0, S("can't happen"));
1840     test(S("abcde"), 4, 2, SV("1234567890"), 0, 0, S("abcd"));
1841     test(S("abcde"), 4, 2, SV("1234567890"), 0, 1, S("abcd1"));
1842     test(S("abcde"), 4, 2, SV("1234567890"), 0, 5, S("abcd12345"));
1843     test(S("abcde"), 4, 2, SV("1234567890"), 0, 9, S("abcd123456789"));
1844     test(S("abcde"), 4, 2, SV("1234567890"), 0, 10, S("abcd1234567890"));
1845     test(S("abcde"), 4, 2, SV("1234567890"), 0, 11, S("abcd1234567890"));
1846     test(S("abcde"), 4, 2, SV("1234567890"), 1, 0, S("abcd"));
1847     test(S("abcde"), 4, 2, SV("1234567890"), 1, 1, S("abcd2"));
1848     test(S("abcde"), 4, 2, SV("1234567890"), 1, 4, S("abcd2345"));
1849     test(S("abcde"), 4, 2, SV("1234567890"), 1, 8, S("abcd23456789"));
1850     test(S("abcde"), 4, 2, SV("1234567890"), 1, 9, S("abcd234567890"));
1851     test(S("abcde"), 4, 2, SV("1234567890"), 1, 10, S("abcd234567890"));
1852     test(S("abcde"), 4, 2, SV("1234567890"), 5, 0, S("abcd"));
1853     test(S("abcde"), 4, 2, SV("1234567890"), 5, 1, S("abcd6"));
1854     test(S("abcde"), 4, 2, SV("1234567890"), 5, 2, S("abcd67"));
1855     test(S("abcde"), 4, 2, SV("1234567890"), 5, 4, S("abcd6789"));
1856     test(S("abcde"), 4, 2, SV("1234567890"), 5, 5, S("abcd67890"));
1857     test(S("abcde"), 4, 2, SV("1234567890"), 5, 6, S("abcd67890"));
1858     test(S("abcde"), 4, 2, SV("1234567890"), 9, 0, S("abcd"));
1859     test(S("abcde"), 4, 2, SV("1234567890"), 9, 1, S("abcd0"));
1860     test(S("abcde"), 4, 2, SV("1234567890"), 9, 2, S("abcd0"));
1861     test(S("abcde"), 4, 2, SV("1234567890"), 10, 0, S("abcd"));
1862     test(S("abcde"), 4, 2, SV("1234567890"), 10, 1, S("abcd"));
1863     test(S("abcde"), 4, 2, SV("1234567890"), 11, 0, S("can't happen"));
1864     test(S("abcde"), 4, 2, SV("12345678901234567890"), 0, 0, S("abcd"));
1865     test(S("abcde"), 4, 2, SV("12345678901234567890"), 0, 1, S("abcd1"));
1866     test(S("abcde"), 4, 2, SV("12345678901234567890"), 0, 10, S("abcd1234567890"));
1867     test(S("abcde"), 4, 2, SV("12345678901234567890"), 0, 19, S("abcd1234567890123456789"));
1868     test(S("abcde"), 4, 2, SV("12345678901234567890"), 0, 20, S("abcd12345678901234567890"));
1869     test(S("abcde"), 4, 2, SV("12345678901234567890"), 0, 21, S("abcd12345678901234567890"));
1870     test(S("abcde"), 4, 2, SV("12345678901234567890"), 1, 0, S("abcd"));
1871     test(S("abcde"), 4, 2, SV("12345678901234567890"), 1, 1, S("abcd2"));
1872     test(S("abcde"), 4, 2, SV("12345678901234567890"), 1, 9, S("abcd234567890"));
1873     test(S("abcde"), 4, 2, SV("12345678901234567890"), 1, 18, S("abcd234567890123456789"));
1874     test(S("abcde"), 4, 2, SV("12345678901234567890"), 1, 19, S("abcd2345678901234567890"));
1875     test(S("abcde"), 4, 2, SV("12345678901234567890"), 1, 20, S("abcd2345678901234567890"));
1876     test(S("abcde"), 4, 2, SV("12345678901234567890"), 10, 0, S("abcd"));
1877     test(S("abcde"), 4, 2, SV("12345678901234567890"), 10, 1, S("abcd1"));
1878     test(S("abcde"), 4, 2, SV("12345678901234567890"), 10, 5, S("abcd12345"));
1879     test(S("abcde"), 4, 2, SV("12345678901234567890"), 10, 9, S("abcd123456789"));
1880     test(S("abcde"), 4, 2, SV("12345678901234567890"), 10, 10, S("abcd1234567890"));
1881     test(S("abcde"), 4, 2, SV("12345678901234567890"), 10, 11, S("abcd1234567890"));
1882     test(S("abcde"), 4, 2, SV("12345678901234567890"), 19, 0, S("abcd"));
1883     test(S("abcde"), 4, 2, SV("12345678901234567890"), 19, 1, S("abcd0"));
1884     test(S("abcde"), 4, 2, SV("12345678901234567890"), 19, 2, S("abcd0"));
1885     test(S("abcde"), 4, 2, SV("12345678901234567890"), 20, 0, S("abcd"));
1886 }
1887 
1888 template <class S, class SV>
test17()1889 void test17()
1890 {
1891     test(S("abcde"), 4, 2, SV("12345678901234567890"), 20, 1, S("abcd"));
1892     test(S("abcde"), 4, 2, SV("12345678901234567890"), 21, 0, S("can't happen"));
1893     test(S("abcde"), 5, 0, SV(""), 0, 0, S("abcde"));
1894     test(S("abcde"), 5, 0, SV(""), 0, 1, S("abcde"));
1895     test(S("abcde"), 5, 0, SV(""), 1, 0, S("can't happen"));
1896     test(S("abcde"), 5, 0, SV("12345"), 0, 0, S("abcde"));
1897     test(S("abcde"), 5, 0, SV("12345"), 0, 1, S("abcde1"));
1898     test(S("abcde"), 5, 0, SV("12345"), 0, 2, S("abcde12"));
1899     test(S("abcde"), 5, 0, SV("12345"), 0, 4, S("abcde1234"));
1900     test(S("abcde"), 5, 0, SV("12345"), 0, 5, S("abcde12345"));
1901     test(S("abcde"), 5, 0, SV("12345"), 0, 6, S("abcde12345"));
1902     test(S("abcde"), 5, 0, SV("12345"), 1, 0, S("abcde"));
1903     test(S("abcde"), 5, 0, SV("12345"), 1, 1, S("abcde2"));
1904     test(S("abcde"), 5, 0, SV("12345"), 1, 2, S("abcde23"));
1905     test(S("abcde"), 5, 0, SV("12345"), 1, 3, S("abcde234"));
1906     test(S("abcde"), 5, 0, SV("12345"), 1, 4, S("abcde2345"));
1907     test(S("abcde"), 5, 0, SV("12345"), 1, 5, S("abcde2345"));
1908     test(S("abcde"), 5, 0, SV("12345"), 2, 0, S("abcde"));
1909     test(S("abcde"), 5, 0, SV("12345"), 2, 1, S("abcde3"));
1910     test(S("abcde"), 5, 0, SV("12345"), 2, 2, S("abcde34"));
1911     test(S("abcde"), 5, 0, SV("12345"), 2, 3, S("abcde345"));
1912     test(S("abcde"), 5, 0, SV("12345"), 2, 4, S("abcde345"));
1913     test(S("abcde"), 5, 0, SV("12345"), 4, 0, S("abcde"));
1914     test(S("abcde"), 5, 0, SV("12345"), 4, 1, S("abcde5"));
1915     test(S("abcde"), 5, 0, SV("12345"), 4, 2, S("abcde5"));
1916     test(S("abcde"), 5, 0, SV("12345"), 5, 0, S("abcde"));
1917     test(S("abcde"), 5, 0, SV("12345"), 5, 1, S("abcde"));
1918     test(S("abcde"), 5, 0, SV("12345"), 6, 0, S("can't happen"));
1919     test(S("abcde"), 5, 0, SV("1234567890"), 0, 0, S("abcde"));
1920     test(S("abcde"), 5, 0, SV("1234567890"), 0, 1, S("abcde1"));
1921     test(S("abcde"), 5, 0, SV("1234567890"), 0, 5, S("abcde12345"));
1922     test(S("abcde"), 5, 0, SV("1234567890"), 0, 9, S("abcde123456789"));
1923     test(S("abcde"), 5, 0, SV("1234567890"), 0, 10, S("abcde1234567890"));
1924     test(S("abcde"), 5, 0, SV("1234567890"), 0, 11, S("abcde1234567890"));
1925     test(S("abcde"), 5, 0, SV("1234567890"), 1, 0, S("abcde"));
1926     test(S("abcde"), 5, 0, SV("1234567890"), 1, 1, S("abcde2"));
1927     test(S("abcde"), 5, 0, SV("1234567890"), 1, 4, S("abcde2345"));
1928     test(S("abcde"), 5, 0, SV("1234567890"), 1, 8, S("abcde23456789"));
1929     test(S("abcde"), 5, 0, SV("1234567890"), 1, 9, S("abcde234567890"));
1930     test(S("abcde"), 5, 0, SV("1234567890"), 1, 10, S("abcde234567890"));
1931     test(S("abcde"), 5, 0, SV("1234567890"), 5, 0, S("abcde"));
1932     test(S("abcde"), 5, 0, SV("1234567890"), 5, 1, S("abcde6"));
1933     test(S("abcde"), 5, 0, SV("1234567890"), 5, 2, S("abcde67"));
1934     test(S("abcde"), 5, 0, SV("1234567890"), 5, 4, S("abcde6789"));
1935     test(S("abcde"), 5, 0, SV("1234567890"), 5, 5, S("abcde67890"));
1936     test(S("abcde"), 5, 0, SV("1234567890"), 5, 6, S("abcde67890"));
1937     test(S("abcde"), 5, 0, SV("1234567890"), 9, 0, S("abcde"));
1938     test(S("abcde"), 5, 0, SV("1234567890"), 9, 1, S("abcde0"));
1939     test(S("abcde"), 5, 0, SV("1234567890"), 9, 2, S("abcde0"));
1940     test(S("abcde"), 5, 0, SV("1234567890"), 10, 0, S("abcde"));
1941     test(S("abcde"), 5, 0, SV("1234567890"), 10, 1, S("abcde"));
1942     test(S("abcde"), 5, 0, SV("1234567890"), 11, 0, S("can't happen"));
1943     test(S("abcde"), 5, 0, SV("12345678901234567890"), 0, 0, S("abcde"));
1944     test(S("abcde"), 5, 0, SV("12345678901234567890"), 0, 1, S("abcde1"));
1945     test(S("abcde"), 5, 0, SV("12345678901234567890"), 0, 10, S("abcde1234567890"));
1946     test(S("abcde"), 5, 0, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
1947     test(S("abcde"), 5, 0, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
1948     test(S("abcde"), 5, 0, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
1949     test(S("abcde"), 5, 0, SV("12345678901234567890"), 1, 0, S("abcde"));
1950     test(S("abcde"), 5, 0, SV("12345678901234567890"), 1, 1, S("abcde2"));
1951     test(S("abcde"), 5, 0, SV("12345678901234567890"), 1, 9, S("abcde234567890"));
1952     test(S("abcde"), 5, 0, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
1953     test(S("abcde"), 5, 0, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
1954     test(S("abcde"), 5, 0, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
1955     test(S("abcde"), 5, 0, SV("12345678901234567890"), 10, 0, S("abcde"));
1956     test(S("abcde"), 5, 0, SV("12345678901234567890"), 10, 1, S("abcde1"));
1957     test(S("abcde"), 5, 0, SV("12345678901234567890"), 10, 5, S("abcde12345"));
1958     test(S("abcde"), 5, 0, SV("12345678901234567890"), 10, 9, S("abcde123456789"));
1959     test(S("abcde"), 5, 0, SV("12345678901234567890"), 10, 10, S("abcde1234567890"));
1960     test(S("abcde"), 5, 0, SV("12345678901234567890"), 10, 11, S("abcde1234567890"));
1961     test(S("abcde"), 5, 0, SV("12345678901234567890"), 19, 0, S("abcde"));
1962     test(S("abcde"), 5, 0, SV("12345678901234567890"), 19, 1, S("abcde0"));
1963     test(S("abcde"), 5, 0, SV("12345678901234567890"), 19, 2, S("abcde0"));
1964     test(S("abcde"), 5, 0, SV("12345678901234567890"), 20, 0, S("abcde"));
1965     test(S("abcde"), 5, 0, SV("12345678901234567890"), 20, 1, S("abcde"));
1966     test(S("abcde"), 5, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
1967     test(S("abcde"), 5, 1, SV(""), 0, 0, S("abcde"));
1968     test(S("abcde"), 5, 1, SV(""), 0, 1, S("abcde"));
1969     test(S("abcde"), 5, 1, SV(""), 1, 0, S("can't happen"));
1970     test(S("abcde"), 5, 1, SV("12345"), 0, 0, S("abcde"));
1971     test(S("abcde"), 5, 1, SV("12345"), 0, 1, S("abcde1"));
1972     test(S("abcde"), 5, 1, SV("12345"), 0, 2, S("abcde12"));
1973     test(S("abcde"), 5, 1, SV("12345"), 0, 4, S("abcde1234"));
1974     test(S("abcde"), 5, 1, SV("12345"), 0, 5, S("abcde12345"));
1975     test(S("abcde"), 5, 1, SV("12345"), 0, 6, S("abcde12345"));
1976     test(S("abcde"), 5, 1, SV("12345"), 1, 0, S("abcde"));
1977     test(S("abcde"), 5, 1, SV("12345"), 1, 1, S("abcde2"));
1978     test(S("abcde"), 5, 1, SV("12345"), 1, 2, S("abcde23"));
1979     test(S("abcde"), 5, 1, SV("12345"), 1, 3, S("abcde234"));
1980     test(S("abcde"), 5, 1, SV("12345"), 1, 4, S("abcde2345"));
1981     test(S("abcde"), 5, 1, SV("12345"), 1, 5, S("abcde2345"));
1982     test(S("abcde"), 5, 1, SV("12345"), 2, 0, S("abcde"));
1983     test(S("abcde"), 5, 1, SV("12345"), 2, 1, S("abcde3"));
1984     test(S("abcde"), 5, 1, SV("12345"), 2, 2, S("abcde34"));
1985     test(S("abcde"), 5, 1, SV("12345"), 2, 3, S("abcde345"));
1986     test(S("abcde"), 5, 1, SV("12345"), 2, 4, S("abcde345"));
1987     test(S("abcde"), 5, 1, SV("12345"), 4, 0, S("abcde"));
1988     test(S("abcde"), 5, 1, SV("12345"), 4, 1, S("abcde5"));
1989     test(S("abcde"), 5, 1, SV("12345"), 4, 2, S("abcde5"));
1990     test(S("abcde"), 5, 1, SV("12345"), 5, 0, S("abcde"));
1991 }
1992 
1993 template <class S, class SV>
test18()1994 void test18()
1995 {
1996     test(S("abcde"), 5, 1, SV("12345"), 5, 1, S("abcde"));
1997     test(S("abcde"), 5, 1, SV("12345"), 6, 0, S("can't happen"));
1998     test(S("abcde"), 5, 1, SV("1234567890"), 0, 0, S("abcde"));
1999     test(S("abcde"), 5, 1, SV("1234567890"), 0, 1, S("abcde1"));
2000     test(S("abcde"), 5, 1, SV("1234567890"), 0, 5, S("abcde12345"));
2001     test(S("abcde"), 5, 1, SV("1234567890"), 0, 9, S("abcde123456789"));
2002     test(S("abcde"), 5, 1, SV("1234567890"), 0, 10, S("abcde1234567890"));
2003     test(S("abcde"), 5, 1, SV("1234567890"), 0, 11, S("abcde1234567890"));
2004     test(S("abcde"), 5, 1, SV("1234567890"), 1, 0, S("abcde"));
2005     test(S("abcde"), 5, 1, SV("1234567890"), 1, 1, S("abcde2"));
2006     test(S("abcde"), 5, 1, SV("1234567890"), 1, 4, S("abcde2345"));
2007     test(S("abcde"), 5, 1, SV("1234567890"), 1, 8, S("abcde23456789"));
2008     test(S("abcde"), 5, 1, SV("1234567890"), 1, 9, S("abcde234567890"));
2009     test(S("abcde"), 5, 1, SV("1234567890"), 1, 10, S("abcde234567890"));
2010     test(S("abcde"), 5, 1, SV("1234567890"), 5, 0, S("abcde"));
2011     test(S("abcde"), 5, 1, SV("1234567890"), 5, 1, S("abcde6"));
2012     test(S("abcde"), 5, 1, SV("1234567890"), 5, 2, S("abcde67"));
2013     test(S("abcde"), 5, 1, SV("1234567890"), 5, 4, S("abcde6789"));
2014     test(S("abcde"), 5, 1, SV("1234567890"), 5, 5, S("abcde67890"));
2015     test(S("abcde"), 5, 1, SV("1234567890"), 5, 6, S("abcde67890"));
2016     test(S("abcde"), 5, 1, SV("1234567890"), 9, 0, S("abcde"));
2017     test(S("abcde"), 5, 1, SV("1234567890"), 9, 1, S("abcde0"));
2018     test(S("abcde"), 5, 1, SV("1234567890"), 9, 2, S("abcde0"));
2019     test(S("abcde"), 5, 1, SV("1234567890"), 10, 0, S("abcde"));
2020     test(S("abcde"), 5, 1, SV("1234567890"), 10, 1, S("abcde"));
2021     test(S("abcde"), 5, 1, SV("1234567890"), 11, 0, S("can't happen"));
2022     test(S("abcde"), 5, 1, SV("12345678901234567890"), 0, 0, S("abcde"));
2023     test(S("abcde"), 5, 1, SV("12345678901234567890"), 0, 1, S("abcde1"));
2024     test(S("abcde"), 5, 1, SV("12345678901234567890"), 0, 10, S("abcde1234567890"));
2025     test(S("abcde"), 5, 1, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
2026     test(S("abcde"), 5, 1, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
2027     test(S("abcde"), 5, 1, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
2028     test(S("abcde"), 5, 1, SV("12345678901234567890"), 1, 0, S("abcde"));
2029     test(S("abcde"), 5, 1, SV("12345678901234567890"), 1, 1, S("abcde2"));
2030     test(S("abcde"), 5, 1, SV("12345678901234567890"), 1, 9, S("abcde234567890"));
2031     test(S("abcde"), 5, 1, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
2032     test(S("abcde"), 5, 1, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
2033     test(S("abcde"), 5, 1, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
2034     test(S("abcde"), 5, 1, SV("12345678901234567890"), 10, 0, S("abcde"));
2035     test(S("abcde"), 5, 1, SV("12345678901234567890"), 10, 1, S("abcde1"));
2036     test(S("abcde"), 5, 1, SV("12345678901234567890"), 10, 5, S("abcde12345"));
2037     test(S("abcde"), 5, 1, SV("12345678901234567890"), 10, 9, S("abcde123456789"));
2038     test(S("abcde"), 5, 1, SV("12345678901234567890"), 10, 10, S("abcde1234567890"));
2039     test(S("abcde"), 5, 1, SV("12345678901234567890"), 10, 11, S("abcde1234567890"));
2040     test(S("abcde"), 5, 1, SV("12345678901234567890"), 19, 0, S("abcde"));
2041     test(S("abcde"), 5, 1, SV("12345678901234567890"), 19, 1, S("abcde0"));
2042     test(S("abcde"), 5, 1, SV("12345678901234567890"), 19, 2, S("abcde0"));
2043     test(S("abcde"), 5, 1, SV("12345678901234567890"), 20, 0, S("abcde"));
2044     test(S("abcde"), 5, 1, SV("12345678901234567890"), 20, 1, S("abcde"));
2045     test(S("abcde"), 5, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
2046     test(S("abcde"), 6, 0, SV(""), 0, 0, S("can't happen"));
2047     test(S("abcde"), 6, 0, SV(""), 0, 1, S("can't happen"));
2048     test(S("abcde"), 6, 0, SV(""), 1, 0, S("can't happen"));
2049     test(S("abcde"), 6, 0, SV("12345"), 0, 0, S("can't happen"));
2050     test(S("abcde"), 6, 0, SV("12345"), 0, 1, S("can't happen"));
2051     test(S("abcde"), 6, 0, SV("12345"), 0, 2, S("can't happen"));
2052     test(S("abcde"), 6, 0, SV("12345"), 0, 4, S("can't happen"));
2053     test(S("abcde"), 6, 0, SV("12345"), 0, 5, S("can't happen"));
2054     test(S("abcde"), 6, 0, SV("12345"), 0, 6, S("can't happen"));
2055     test(S("abcde"), 6, 0, SV("12345"), 1, 0, S("can't happen"));
2056     test(S("abcde"), 6, 0, SV("12345"), 1, 1, S("can't happen"));
2057     test(S("abcde"), 6, 0, SV("12345"), 1, 2, S("can't happen"));
2058     test(S("abcde"), 6, 0, SV("12345"), 1, 3, S("can't happen"));
2059     test(S("abcde"), 6, 0, SV("12345"), 1, 4, S("can't happen"));
2060     test(S("abcde"), 6, 0, SV("12345"), 1, 5, S("can't happen"));
2061     test(S("abcde"), 6, 0, SV("12345"), 2, 0, S("can't happen"));
2062     test(S("abcde"), 6, 0, SV("12345"), 2, 1, S("can't happen"));
2063     test(S("abcde"), 6, 0, SV("12345"), 2, 2, S("can't happen"));
2064     test(S("abcde"), 6, 0, SV("12345"), 2, 3, S("can't happen"));
2065     test(S("abcde"), 6, 0, SV("12345"), 2, 4, S("can't happen"));
2066     test(S("abcde"), 6, 0, SV("12345"), 4, 0, S("can't happen"));
2067     test(S("abcde"), 6, 0, SV("12345"), 4, 1, S("can't happen"));
2068     test(S("abcde"), 6, 0, SV("12345"), 4, 2, S("can't happen"));
2069     test(S("abcde"), 6, 0, SV("12345"), 5, 0, S("can't happen"));
2070     test(S("abcde"), 6, 0, SV("12345"), 5, 1, S("can't happen"));
2071     test(S("abcde"), 6, 0, SV("12345"), 6, 0, S("can't happen"));
2072     test(S("abcde"), 6, 0, SV("1234567890"), 0, 0, S("can't happen"));
2073     test(S("abcde"), 6, 0, SV("1234567890"), 0, 1, S("can't happen"));
2074     test(S("abcde"), 6, 0, SV("1234567890"), 0, 5, S("can't happen"));
2075     test(S("abcde"), 6, 0, SV("1234567890"), 0, 9, S("can't happen"));
2076     test(S("abcde"), 6, 0, SV("1234567890"), 0, 10, S("can't happen"));
2077     test(S("abcde"), 6, 0, SV("1234567890"), 0, 11, S("can't happen"));
2078     test(S("abcde"), 6, 0, SV("1234567890"), 1, 0, S("can't happen"));
2079     test(S("abcde"), 6, 0, SV("1234567890"), 1, 1, S("can't happen"));
2080     test(S("abcde"), 6, 0, SV("1234567890"), 1, 4, S("can't happen"));
2081     test(S("abcde"), 6, 0, SV("1234567890"), 1, 8, S("can't happen"));
2082     test(S("abcde"), 6, 0, SV("1234567890"), 1, 9, S("can't happen"));
2083     test(S("abcde"), 6, 0, SV("1234567890"), 1, 10, S("can't happen"));
2084     test(S("abcde"), 6, 0, SV("1234567890"), 5, 0, S("can't happen"));
2085     test(S("abcde"), 6, 0, SV("1234567890"), 5, 1, S("can't happen"));
2086     test(S("abcde"), 6, 0, SV("1234567890"), 5, 2, S("can't happen"));
2087     test(S("abcde"), 6, 0, SV("1234567890"), 5, 4, S("can't happen"));
2088     test(S("abcde"), 6, 0, SV("1234567890"), 5, 5, S("can't happen"));
2089     test(S("abcde"), 6, 0, SV("1234567890"), 5, 6, S("can't happen"));
2090     test(S("abcde"), 6, 0, SV("1234567890"), 9, 0, S("can't happen"));
2091     test(S("abcde"), 6, 0, SV("1234567890"), 9, 1, S("can't happen"));
2092     test(S("abcde"), 6, 0, SV("1234567890"), 9, 2, S("can't happen"));
2093     test(S("abcde"), 6, 0, SV("1234567890"), 10, 0, S("can't happen"));
2094     test(S("abcde"), 6, 0, SV("1234567890"), 10, 1, S("can't happen"));
2095     test(S("abcde"), 6, 0, SV("1234567890"), 11, 0, S("can't happen"));
2096 }
2097 
2098 template <class S, class SV>
test19()2099 void test19()
2100 {
2101     test(S("abcde"), 6, 0, SV("12345678901234567890"), 0, 0, S("can't happen"));
2102     test(S("abcde"), 6, 0, SV("12345678901234567890"), 0, 1, S("can't happen"));
2103     test(S("abcde"), 6, 0, SV("12345678901234567890"), 0, 10, S("can't happen"));
2104     test(S("abcde"), 6, 0, SV("12345678901234567890"), 0, 19, S("can't happen"));
2105     test(S("abcde"), 6, 0, SV("12345678901234567890"), 0, 20, S("can't happen"));
2106     test(S("abcde"), 6, 0, SV("12345678901234567890"), 0, 21, S("can't happen"));
2107     test(S("abcde"), 6, 0, SV("12345678901234567890"), 1, 0, S("can't happen"));
2108     test(S("abcde"), 6, 0, SV("12345678901234567890"), 1, 1, S("can't happen"));
2109     test(S("abcde"), 6, 0, SV("12345678901234567890"), 1, 9, S("can't happen"));
2110     test(S("abcde"), 6, 0, SV("12345678901234567890"), 1, 18, S("can't happen"));
2111     test(S("abcde"), 6, 0, SV("12345678901234567890"), 1, 19, S("can't happen"));
2112     test(S("abcde"), 6, 0, SV("12345678901234567890"), 1, 20, S("can't happen"));
2113     test(S("abcde"), 6, 0, SV("12345678901234567890"), 10, 0, S("can't happen"));
2114     test(S("abcde"), 6, 0, SV("12345678901234567890"), 10, 1, S("can't happen"));
2115     test(S("abcde"), 6, 0, SV("12345678901234567890"), 10, 5, S("can't happen"));
2116     test(S("abcde"), 6, 0, SV("12345678901234567890"), 10, 9, S("can't happen"));
2117     test(S("abcde"), 6, 0, SV("12345678901234567890"), 10, 10, S("can't happen"));
2118     test(S("abcde"), 6, 0, SV("12345678901234567890"), 10, 11, S("can't happen"));
2119     test(S("abcde"), 6, 0, SV("12345678901234567890"), 19, 0, S("can't happen"));
2120     test(S("abcde"), 6, 0, SV("12345678901234567890"), 19, 1, S("can't happen"));
2121     test(S("abcde"), 6, 0, SV("12345678901234567890"), 19, 2, S("can't happen"));
2122     test(S("abcde"), 6, 0, SV("12345678901234567890"), 20, 0, S("can't happen"));
2123     test(S("abcde"), 6, 0, SV("12345678901234567890"), 20, 1, S("can't happen"));
2124     test(S("abcde"), 6, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
2125     test(S("abcdefghij"), 0, 0, SV(""), 0, 0, S("abcdefghij"));
2126     test(S("abcdefghij"), 0, 0, SV(""), 0, 1, S("abcdefghij"));
2127     test(S("abcdefghij"), 0, 0, SV(""), 1, 0, S("can't happen"));
2128     test(S("abcdefghij"), 0, 0, SV("12345"), 0, 0, S("abcdefghij"));
2129     test(S("abcdefghij"), 0, 0, SV("12345"), 0, 1, S("1abcdefghij"));
2130     test(S("abcdefghij"), 0, 0, SV("12345"), 0, 2, S("12abcdefghij"));
2131     test(S("abcdefghij"), 0, 0, SV("12345"), 0, 4, S("1234abcdefghij"));
2132     test(S("abcdefghij"), 0, 0, SV("12345"), 0, 5, S("12345abcdefghij"));
2133     test(S("abcdefghij"), 0, 0, SV("12345"), 0, 6, S("12345abcdefghij"));
2134     test(S("abcdefghij"), 0, 0, SV("12345"), 1, 0, S("abcdefghij"));
2135     test(S("abcdefghij"), 0, 0, SV("12345"), 1, 1, S("2abcdefghij"));
2136     test(S("abcdefghij"), 0, 0, SV("12345"), 1, 2, S("23abcdefghij"));
2137     test(S("abcdefghij"), 0, 0, SV("12345"), 1, 3, S("234abcdefghij"));
2138     test(S("abcdefghij"), 0, 0, SV("12345"), 1, 4, S("2345abcdefghij"));
2139     test(S("abcdefghij"), 0, 0, SV("12345"), 1, 5, S("2345abcdefghij"));
2140     test(S("abcdefghij"), 0, 0, SV("12345"), 2, 0, S("abcdefghij"));
2141     test(S("abcdefghij"), 0, 0, SV("12345"), 2, 1, S("3abcdefghij"));
2142     test(S("abcdefghij"), 0, 0, SV("12345"), 2, 2, S("34abcdefghij"));
2143     test(S("abcdefghij"), 0, 0, SV("12345"), 2, 3, S("345abcdefghij"));
2144     test(S("abcdefghij"), 0, 0, SV("12345"), 2, 4, S("345abcdefghij"));
2145     test(S("abcdefghij"), 0, 0, SV("12345"), 4, 0, S("abcdefghij"));
2146     test(S("abcdefghij"), 0, 0, SV("12345"), 4, 1, S("5abcdefghij"));
2147     test(S("abcdefghij"), 0, 0, SV("12345"), 4, 2, S("5abcdefghij"));
2148     test(S("abcdefghij"), 0, 0, SV("12345"), 5, 0, S("abcdefghij"));
2149     test(S("abcdefghij"), 0, 0, SV("12345"), 5, 1, S("abcdefghij"));
2150     test(S("abcdefghij"), 0, 0, SV("12345"), 6, 0, S("can't happen"));
2151     test(S("abcdefghij"), 0, 0, SV("1234567890"), 0, 0, S("abcdefghij"));
2152     test(S("abcdefghij"), 0, 0, SV("1234567890"), 0, 1, S("1abcdefghij"));
2153     test(S("abcdefghij"), 0, 0, SV("1234567890"), 0, 5, S("12345abcdefghij"));
2154     test(S("abcdefghij"), 0, 0, SV("1234567890"), 0, 9, S("123456789abcdefghij"));
2155     test(S("abcdefghij"), 0, 0, SV("1234567890"), 0, 10, S("1234567890abcdefghij"));
2156     test(S("abcdefghij"), 0, 0, SV("1234567890"), 0, 11, S("1234567890abcdefghij"));
2157     test(S("abcdefghij"), 0, 0, SV("1234567890"), 1, 0, S("abcdefghij"));
2158     test(S("abcdefghij"), 0, 0, SV("1234567890"), 1, 1, S("2abcdefghij"));
2159     test(S("abcdefghij"), 0, 0, SV("1234567890"), 1, 4, S("2345abcdefghij"));
2160     test(S("abcdefghij"), 0, 0, SV("1234567890"), 1, 8, S("23456789abcdefghij"));
2161     test(S("abcdefghij"), 0, 0, SV("1234567890"), 1, 9, S("234567890abcdefghij"));
2162     test(S("abcdefghij"), 0, 0, SV("1234567890"), 1, 10, S("234567890abcdefghij"));
2163     test(S("abcdefghij"), 0, 0, SV("1234567890"), 5, 0, S("abcdefghij"));
2164     test(S("abcdefghij"), 0, 0, SV("1234567890"), 5, 1, S("6abcdefghij"));
2165     test(S("abcdefghij"), 0, 0, SV("1234567890"), 5, 2, S("67abcdefghij"));
2166     test(S("abcdefghij"), 0, 0, SV("1234567890"), 5, 4, S("6789abcdefghij"));
2167     test(S("abcdefghij"), 0, 0, SV("1234567890"), 5, 5, S("67890abcdefghij"));
2168     test(S("abcdefghij"), 0, 0, SV("1234567890"), 5, 6, S("67890abcdefghij"));
2169     test(S("abcdefghij"), 0, 0, SV("1234567890"), 9, 0, S("abcdefghij"));
2170     test(S("abcdefghij"), 0, 0, SV("1234567890"), 9, 1, S("0abcdefghij"));
2171     test(S("abcdefghij"), 0, 0, SV("1234567890"), 9, 2, S("0abcdefghij"));
2172     test(S("abcdefghij"), 0, 0, SV("1234567890"), 10, 0, S("abcdefghij"));
2173     test(S("abcdefghij"), 0, 0, SV("1234567890"), 10, 1, S("abcdefghij"));
2174     test(S("abcdefghij"), 0, 0, SV("1234567890"), 11, 0, S("can't happen"));
2175     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
2176     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 0, 1, S("1abcdefghij"));
2177     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 0, 10, S("1234567890abcdefghij"));
2178     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghij"));
2179     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghij"));
2180     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghij"));
2181     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
2182     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 1, 1, S("2abcdefghij"));
2183     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 1, 9, S("234567890abcdefghij"));
2184     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 1, 18, S("234567890123456789abcdefghij"));
2185     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghij"));
2186     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghij"));
2187     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
2188     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 10, 1, S("1abcdefghij"));
2189     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 10, 5, S("12345abcdefghij"));
2190     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 10, 9, S("123456789abcdefghij"));
2191     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 10, 10, S("1234567890abcdefghij"));
2192     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 10, 11, S("1234567890abcdefghij"));
2193     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
2194     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 19, 1, S("0abcdefghij"));
2195     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 19, 2, S("0abcdefghij"));
2196     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
2197     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
2198     test(S("abcdefghij"), 0, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
2199     test(S("abcdefghij"), 0, 1, SV(""), 0, 0, S("bcdefghij"));
2200     test(S("abcdefghij"), 0, 1, SV(""), 0, 1, S("bcdefghij"));
2201 }
2202 
2203 template <class S, class SV>
test20()2204 void test20()
2205 {
2206     test(S("abcdefghij"), 0, 1, SV(""), 1, 0, S("can't happen"));
2207     test(S("abcdefghij"), 0, 1, SV("12345"), 0, 0, S("bcdefghij"));
2208     test(S("abcdefghij"), 0, 1, SV("12345"), 0, 1, S("1bcdefghij"));
2209     test(S("abcdefghij"), 0, 1, SV("12345"), 0, 2, S("12bcdefghij"));
2210     test(S("abcdefghij"), 0, 1, SV("12345"), 0, 4, S("1234bcdefghij"));
2211     test(S("abcdefghij"), 0, 1, SV("12345"), 0, 5, S("12345bcdefghij"));
2212     test(S("abcdefghij"), 0, 1, SV("12345"), 0, 6, S("12345bcdefghij"));
2213     test(S("abcdefghij"), 0, 1, SV("12345"), 1, 0, S("bcdefghij"));
2214     test(S("abcdefghij"), 0, 1, SV("12345"), 1, 1, S("2bcdefghij"));
2215     test(S("abcdefghij"), 0, 1, SV("12345"), 1, 2, S("23bcdefghij"));
2216     test(S("abcdefghij"), 0, 1, SV("12345"), 1, 3, S("234bcdefghij"));
2217     test(S("abcdefghij"), 0, 1, SV("12345"), 1, 4, S("2345bcdefghij"));
2218     test(S("abcdefghij"), 0, 1, SV("12345"), 1, 5, S("2345bcdefghij"));
2219     test(S("abcdefghij"), 0, 1, SV("12345"), 2, 0, S("bcdefghij"));
2220     test(S("abcdefghij"), 0, 1, SV("12345"), 2, 1, S("3bcdefghij"));
2221     test(S("abcdefghij"), 0, 1, SV("12345"), 2, 2, S("34bcdefghij"));
2222     test(S("abcdefghij"), 0, 1, SV("12345"), 2, 3, S("345bcdefghij"));
2223     test(S("abcdefghij"), 0, 1, SV("12345"), 2, 4, S("345bcdefghij"));
2224     test(S("abcdefghij"), 0, 1, SV("12345"), 4, 0, S("bcdefghij"));
2225     test(S("abcdefghij"), 0, 1, SV("12345"), 4, 1, S("5bcdefghij"));
2226     test(S("abcdefghij"), 0, 1, SV("12345"), 4, 2, S("5bcdefghij"));
2227     test(S("abcdefghij"), 0, 1, SV("12345"), 5, 0, S("bcdefghij"));
2228     test(S("abcdefghij"), 0, 1, SV("12345"), 5, 1, S("bcdefghij"));
2229     test(S("abcdefghij"), 0, 1, SV("12345"), 6, 0, S("can't happen"));
2230     test(S("abcdefghij"), 0, 1, SV("1234567890"), 0, 0, S("bcdefghij"));
2231     test(S("abcdefghij"), 0, 1, SV("1234567890"), 0, 1, S("1bcdefghij"));
2232     test(S("abcdefghij"), 0, 1, SV("1234567890"), 0, 5, S("12345bcdefghij"));
2233     test(S("abcdefghij"), 0, 1, SV("1234567890"), 0, 9, S("123456789bcdefghij"));
2234     test(S("abcdefghij"), 0, 1, SV("1234567890"), 0, 10, S("1234567890bcdefghij"));
2235     test(S("abcdefghij"), 0, 1, SV("1234567890"), 0, 11, S("1234567890bcdefghij"));
2236     test(S("abcdefghij"), 0, 1, SV("1234567890"), 1, 0, S("bcdefghij"));
2237     test(S("abcdefghij"), 0, 1, SV("1234567890"), 1, 1, S("2bcdefghij"));
2238     test(S("abcdefghij"), 0, 1, SV("1234567890"), 1, 4, S("2345bcdefghij"));
2239     test(S("abcdefghij"), 0, 1, SV("1234567890"), 1, 8, S("23456789bcdefghij"));
2240     test(S("abcdefghij"), 0, 1, SV("1234567890"), 1, 9, S("234567890bcdefghij"));
2241     test(S("abcdefghij"), 0, 1, SV("1234567890"), 1, 10, S("234567890bcdefghij"));
2242     test(S("abcdefghij"), 0, 1, SV("1234567890"), 5, 0, S("bcdefghij"));
2243     test(S("abcdefghij"), 0, 1, SV("1234567890"), 5, 1, S("6bcdefghij"));
2244     test(S("abcdefghij"), 0, 1, SV("1234567890"), 5, 2, S("67bcdefghij"));
2245     test(S("abcdefghij"), 0, 1, SV("1234567890"), 5, 4, S("6789bcdefghij"));
2246     test(S("abcdefghij"), 0, 1, SV("1234567890"), 5, 5, S("67890bcdefghij"));
2247     test(S("abcdefghij"), 0, 1, SV("1234567890"), 5, 6, S("67890bcdefghij"));
2248     test(S("abcdefghij"), 0, 1, SV("1234567890"), 9, 0, S("bcdefghij"));
2249     test(S("abcdefghij"), 0, 1, SV("1234567890"), 9, 1, S("0bcdefghij"));
2250     test(S("abcdefghij"), 0, 1, SV("1234567890"), 9, 2, S("0bcdefghij"));
2251     test(S("abcdefghij"), 0, 1, SV("1234567890"), 10, 0, S("bcdefghij"));
2252     test(S("abcdefghij"), 0, 1, SV("1234567890"), 10, 1, S("bcdefghij"));
2253     test(S("abcdefghij"), 0, 1, SV("1234567890"), 11, 0, S("can't happen"));
2254     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 0, 0, S("bcdefghij"));
2255     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 0, 1, S("1bcdefghij"));
2256     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 0, 10, S("1234567890bcdefghij"));
2257     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 0, 19, S("1234567890123456789bcdefghij"));
2258     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 0, 20, S("12345678901234567890bcdefghij"));
2259     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 0, 21, S("12345678901234567890bcdefghij"));
2260     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 1, 0, S("bcdefghij"));
2261     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 1, 1, S("2bcdefghij"));
2262     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 1, 9, S("234567890bcdefghij"));
2263     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 1, 18, S("234567890123456789bcdefghij"));
2264     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 1, 19, S("2345678901234567890bcdefghij"));
2265     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 1, 20, S("2345678901234567890bcdefghij"));
2266     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 10, 0, S("bcdefghij"));
2267     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 10, 1, S("1bcdefghij"));
2268     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 10, 5, S("12345bcdefghij"));
2269     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 10, 9, S("123456789bcdefghij"));
2270     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 10, 10, S("1234567890bcdefghij"));
2271     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 10, 11, S("1234567890bcdefghij"));
2272     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 19, 0, S("bcdefghij"));
2273     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 19, 1, S("0bcdefghij"));
2274     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 19, 2, S("0bcdefghij"));
2275     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 20, 0, S("bcdefghij"));
2276     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 20, 1, S("bcdefghij"));
2277     test(S("abcdefghij"), 0, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
2278     test(S("abcdefghij"), 0, 5, SV(""), 0, 0, S("fghij"));
2279     test(S("abcdefghij"), 0, 5, SV(""), 0, 1, S("fghij"));
2280     test(S("abcdefghij"), 0, 5, SV(""), 1, 0, S("can't happen"));
2281     test(S("abcdefghij"), 0, 5, SV("12345"), 0, 0, S("fghij"));
2282     test(S("abcdefghij"), 0, 5, SV("12345"), 0, 1, S("1fghij"));
2283     test(S("abcdefghij"), 0, 5, SV("12345"), 0, 2, S("12fghij"));
2284     test(S("abcdefghij"), 0, 5, SV("12345"), 0, 4, S("1234fghij"));
2285     test(S("abcdefghij"), 0, 5, SV("12345"), 0, 5, S("12345fghij"));
2286     test(S("abcdefghij"), 0, 5, SV("12345"), 0, 6, S("12345fghij"));
2287     test(S("abcdefghij"), 0, 5, SV("12345"), 1, 0, S("fghij"));
2288     test(S("abcdefghij"), 0, 5, SV("12345"), 1, 1, S("2fghij"));
2289     test(S("abcdefghij"), 0, 5, SV("12345"), 1, 2, S("23fghij"));
2290     test(S("abcdefghij"), 0, 5, SV("12345"), 1, 3, S("234fghij"));
2291     test(S("abcdefghij"), 0, 5, SV("12345"), 1, 4, S("2345fghij"));
2292     test(S("abcdefghij"), 0, 5, SV("12345"), 1, 5, S("2345fghij"));
2293     test(S("abcdefghij"), 0, 5, SV("12345"), 2, 0, S("fghij"));
2294     test(S("abcdefghij"), 0, 5, SV("12345"), 2, 1, S("3fghij"));
2295     test(S("abcdefghij"), 0, 5, SV("12345"), 2, 2, S("34fghij"));
2296     test(S("abcdefghij"), 0, 5, SV("12345"), 2, 3, S("345fghij"));
2297     test(S("abcdefghij"), 0, 5, SV("12345"), 2, 4, S("345fghij"));
2298     test(S("abcdefghij"), 0, 5, SV("12345"), 4, 0, S("fghij"));
2299     test(S("abcdefghij"), 0, 5, SV("12345"), 4, 1, S("5fghij"));
2300     test(S("abcdefghij"), 0, 5, SV("12345"), 4, 2, S("5fghij"));
2301     test(S("abcdefghij"), 0, 5, SV("12345"), 5, 0, S("fghij"));
2302     test(S("abcdefghij"), 0, 5, SV("12345"), 5, 1, S("fghij"));
2303     test(S("abcdefghij"), 0, 5, SV("12345"), 6, 0, S("can't happen"));
2304     test(S("abcdefghij"), 0, 5, SV("1234567890"), 0, 0, S("fghij"));
2305     test(S("abcdefghij"), 0, 5, SV("1234567890"), 0, 1, S("1fghij"));
2306 }
2307 
2308 template <class S, class SV>
test21()2309 void test21()
2310 {
2311     test(S("abcdefghij"), 0, 5, SV("1234567890"), 0, 5, S("12345fghij"));
2312     test(S("abcdefghij"), 0, 5, SV("1234567890"), 0, 9, S("123456789fghij"));
2313     test(S("abcdefghij"), 0, 5, SV("1234567890"), 0, 10, S("1234567890fghij"));
2314     test(S("abcdefghij"), 0, 5, SV("1234567890"), 0, 11, S("1234567890fghij"));
2315     test(S("abcdefghij"), 0, 5, SV("1234567890"), 1, 0, S("fghij"));
2316     test(S("abcdefghij"), 0, 5, SV("1234567890"), 1, 1, S("2fghij"));
2317     test(S("abcdefghij"), 0, 5, SV("1234567890"), 1, 4, S("2345fghij"));
2318     test(S("abcdefghij"), 0, 5, SV("1234567890"), 1, 8, S("23456789fghij"));
2319     test(S("abcdefghij"), 0, 5, SV("1234567890"), 1, 9, S("234567890fghij"));
2320     test(S("abcdefghij"), 0, 5, SV("1234567890"), 1, 10, S("234567890fghij"));
2321     test(S("abcdefghij"), 0, 5, SV("1234567890"), 5, 0, S("fghij"));
2322     test(S("abcdefghij"), 0, 5, SV("1234567890"), 5, 1, S("6fghij"));
2323     test(S("abcdefghij"), 0, 5, SV("1234567890"), 5, 2, S("67fghij"));
2324     test(S("abcdefghij"), 0, 5, SV("1234567890"), 5, 4, S("6789fghij"));
2325     test(S("abcdefghij"), 0, 5, SV("1234567890"), 5, 5, S("67890fghij"));
2326     test(S("abcdefghij"), 0, 5, SV("1234567890"), 5, 6, S("67890fghij"));
2327     test(S("abcdefghij"), 0, 5, SV("1234567890"), 9, 0, S("fghij"));
2328     test(S("abcdefghij"), 0, 5, SV("1234567890"), 9, 1, S("0fghij"));
2329     test(S("abcdefghij"), 0, 5, SV("1234567890"), 9, 2, S("0fghij"));
2330     test(S("abcdefghij"), 0, 5, SV("1234567890"), 10, 0, S("fghij"));
2331     test(S("abcdefghij"), 0, 5, SV("1234567890"), 10, 1, S("fghij"));
2332     test(S("abcdefghij"), 0, 5, SV("1234567890"), 11, 0, S("can't happen"));
2333     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 0, 0, S("fghij"));
2334     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 0, 1, S("1fghij"));
2335     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 0, 10, S("1234567890fghij"));
2336     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 0, 19, S("1234567890123456789fghij"));
2337     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 0, 20, S("12345678901234567890fghij"));
2338     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 0, 21, S("12345678901234567890fghij"));
2339     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 1, 0, S("fghij"));
2340     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 1, 1, S("2fghij"));
2341     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 1, 9, S("234567890fghij"));
2342     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 1, 18, S("234567890123456789fghij"));
2343     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 1, 19, S("2345678901234567890fghij"));
2344     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 1, 20, S("2345678901234567890fghij"));
2345     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 10, 0, S("fghij"));
2346     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 10, 1, S("1fghij"));
2347     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 10, 5, S("12345fghij"));
2348     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 10, 9, S("123456789fghij"));
2349     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 10, 10, S("1234567890fghij"));
2350     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 10, 11, S("1234567890fghij"));
2351     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 19, 0, S("fghij"));
2352     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 19, 1, S("0fghij"));
2353     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 19, 2, S("0fghij"));
2354     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 20, 0, S("fghij"));
2355     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 20, 1, S("fghij"));
2356     test(S("abcdefghij"), 0, 5, SV("12345678901234567890"), 21, 0, S("can't happen"));
2357     test(S("abcdefghij"), 0, 9, SV(""), 0, 0, S("j"));
2358     test(S("abcdefghij"), 0, 9, SV(""), 0, 1, S("j"));
2359     test(S("abcdefghij"), 0, 9, SV(""), 1, 0, S("can't happen"));
2360     test(S("abcdefghij"), 0, 9, SV("12345"), 0, 0, S("j"));
2361     test(S("abcdefghij"), 0, 9, SV("12345"), 0, 1, S("1j"));
2362     test(S("abcdefghij"), 0, 9, SV("12345"), 0, 2, S("12j"));
2363     test(S("abcdefghij"), 0, 9, SV("12345"), 0, 4, S("1234j"));
2364     test(S("abcdefghij"), 0, 9, SV("12345"), 0, 5, S("12345j"));
2365     test(S("abcdefghij"), 0, 9, SV("12345"), 0, 6, S("12345j"));
2366     test(S("abcdefghij"), 0, 9, SV("12345"), 1, 0, S("j"));
2367     test(S("abcdefghij"), 0, 9, SV("12345"), 1, 1, S("2j"));
2368     test(S("abcdefghij"), 0, 9, SV("12345"), 1, 2, S("23j"));
2369     test(S("abcdefghij"), 0, 9, SV("12345"), 1, 3, S("234j"));
2370     test(S("abcdefghij"), 0, 9, SV("12345"), 1, 4, S("2345j"));
2371     test(S("abcdefghij"), 0, 9, SV("12345"), 1, 5, S("2345j"));
2372     test(S("abcdefghij"), 0, 9, SV("12345"), 2, 0, S("j"));
2373     test(S("abcdefghij"), 0, 9, SV("12345"), 2, 1, S("3j"));
2374     test(S("abcdefghij"), 0, 9, SV("12345"), 2, 2, S("34j"));
2375     test(S("abcdefghij"), 0, 9, SV("12345"), 2, 3, S("345j"));
2376     test(S("abcdefghij"), 0, 9, SV("12345"), 2, 4, S("345j"));
2377     test(S("abcdefghij"), 0, 9, SV("12345"), 4, 0, S("j"));
2378     test(S("abcdefghij"), 0, 9, SV("12345"), 4, 1, S("5j"));
2379     test(S("abcdefghij"), 0, 9, SV("12345"), 4, 2, S("5j"));
2380     test(S("abcdefghij"), 0, 9, SV("12345"), 5, 0, S("j"));
2381     test(S("abcdefghij"), 0, 9, SV("12345"), 5, 1, S("j"));
2382     test(S("abcdefghij"), 0, 9, SV("12345"), 6, 0, S("can't happen"));
2383     test(S("abcdefghij"), 0, 9, SV("1234567890"), 0, 0, S("j"));
2384     test(S("abcdefghij"), 0, 9, SV("1234567890"), 0, 1, S("1j"));
2385     test(S("abcdefghij"), 0, 9, SV("1234567890"), 0, 5, S("12345j"));
2386     test(S("abcdefghij"), 0, 9, SV("1234567890"), 0, 9, S("123456789j"));
2387     test(S("abcdefghij"), 0, 9, SV("1234567890"), 0, 10, S("1234567890j"));
2388     test(S("abcdefghij"), 0, 9, SV("1234567890"), 0, 11, S("1234567890j"));
2389     test(S("abcdefghij"), 0, 9, SV("1234567890"), 1, 0, S("j"));
2390     test(S("abcdefghij"), 0, 9, SV("1234567890"), 1, 1, S("2j"));
2391     test(S("abcdefghij"), 0, 9, SV("1234567890"), 1, 4, S("2345j"));
2392     test(S("abcdefghij"), 0, 9, SV("1234567890"), 1, 8, S("23456789j"));
2393     test(S("abcdefghij"), 0, 9, SV("1234567890"), 1, 9, S("234567890j"));
2394     test(S("abcdefghij"), 0, 9, SV("1234567890"), 1, 10, S("234567890j"));
2395     test(S("abcdefghij"), 0, 9, SV("1234567890"), 5, 0, S("j"));
2396     test(S("abcdefghij"), 0, 9, SV("1234567890"), 5, 1, S("6j"));
2397     test(S("abcdefghij"), 0, 9, SV("1234567890"), 5, 2, S("67j"));
2398     test(S("abcdefghij"), 0, 9, SV("1234567890"), 5, 4, S("6789j"));
2399     test(S("abcdefghij"), 0, 9, SV("1234567890"), 5, 5, S("67890j"));
2400     test(S("abcdefghij"), 0, 9, SV("1234567890"), 5, 6, S("67890j"));
2401     test(S("abcdefghij"), 0, 9, SV("1234567890"), 9, 0, S("j"));
2402     test(S("abcdefghij"), 0, 9, SV("1234567890"), 9, 1, S("0j"));
2403     test(S("abcdefghij"), 0, 9, SV("1234567890"), 9, 2, S("0j"));
2404     test(S("abcdefghij"), 0, 9, SV("1234567890"), 10, 0, S("j"));
2405     test(S("abcdefghij"), 0, 9, SV("1234567890"), 10, 1, S("j"));
2406     test(S("abcdefghij"), 0, 9, SV("1234567890"), 11, 0, S("can't happen"));
2407     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 0, 0, S("j"));
2408     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 0, 1, S("1j"));
2409     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 0, 10, S("1234567890j"));
2410     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 0, 19, S("1234567890123456789j"));
2411 }
2412 
2413 template <class S, class SV>
test22()2414 void test22()
2415 {
2416     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 0, 20, S("12345678901234567890j"));
2417     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 0, 21, S("12345678901234567890j"));
2418     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 1, 0, S("j"));
2419     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 1, 1, S("2j"));
2420     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 1, 9, S("234567890j"));
2421     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 1, 18, S("234567890123456789j"));
2422     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 1, 19, S("2345678901234567890j"));
2423     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 1, 20, S("2345678901234567890j"));
2424     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 10, 0, S("j"));
2425     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 10, 1, S("1j"));
2426     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 10, 5, S("12345j"));
2427     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 10, 9, S("123456789j"));
2428     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 10, 10, S("1234567890j"));
2429     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 10, 11, S("1234567890j"));
2430     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 19, 0, S("j"));
2431     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 19, 1, S("0j"));
2432     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 19, 2, S("0j"));
2433     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 20, 0, S("j"));
2434     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 20, 1, S("j"));
2435     test(S("abcdefghij"), 0, 9, SV("12345678901234567890"), 21, 0, S("can't happen"));
2436     test(S("abcdefghij"), 0, 10, SV(""), 0, 0, S(""));
2437     test(S("abcdefghij"), 0, 10, SV(""), 0, 1, S(""));
2438     test(S("abcdefghij"), 0, 10, SV(""), 1, 0, S("can't happen"));
2439     test(S("abcdefghij"), 0, 10, SV("12345"), 0, 0, S(""));
2440     test(S("abcdefghij"), 0, 10, SV("12345"), 0, 1, S("1"));
2441     test(S("abcdefghij"), 0, 10, SV("12345"), 0, 2, S("12"));
2442     test(S("abcdefghij"), 0, 10, SV("12345"), 0, 4, S("1234"));
2443     test(S("abcdefghij"), 0, 10, SV("12345"), 0, 5, S("12345"));
2444     test(S("abcdefghij"), 0, 10, SV("12345"), 0, 6, S("12345"));
2445     test(S("abcdefghij"), 0, 10, SV("12345"), 1, 0, S(""));
2446     test(S("abcdefghij"), 0, 10, SV("12345"), 1, 1, S("2"));
2447     test(S("abcdefghij"), 0, 10, SV("12345"), 1, 2, S("23"));
2448     test(S("abcdefghij"), 0, 10, SV("12345"), 1, 3, S("234"));
2449     test(S("abcdefghij"), 0, 10, SV("12345"), 1, 4, S("2345"));
2450     test(S("abcdefghij"), 0, 10, SV("12345"), 1, 5, S("2345"));
2451     test(S("abcdefghij"), 0, 10, SV("12345"), 2, 0, S(""));
2452     test(S("abcdefghij"), 0, 10, SV("12345"), 2, 1, S("3"));
2453     test(S("abcdefghij"), 0, 10, SV("12345"), 2, 2, S("34"));
2454     test(S("abcdefghij"), 0, 10, SV("12345"), 2, 3, S("345"));
2455     test(S("abcdefghij"), 0, 10, SV("12345"), 2, 4, S("345"));
2456     test(S("abcdefghij"), 0, 10, SV("12345"), 4, 0, S(""));
2457     test(S("abcdefghij"), 0, 10, SV("12345"), 4, 1, S("5"));
2458     test(S("abcdefghij"), 0, 10, SV("12345"), 4, 2, S("5"));
2459     test(S("abcdefghij"), 0, 10, SV("12345"), 5, 0, S(""));
2460     test(S("abcdefghij"), 0, 10, SV("12345"), 5, 1, S(""));
2461     test(S("abcdefghij"), 0, 10, SV("12345"), 6, 0, S("can't happen"));
2462     test(S("abcdefghij"), 0, 10, SV("1234567890"), 0, 0, S(""));
2463     test(S("abcdefghij"), 0, 10, SV("1234567890"), 0, 1, S("1"));
2464     test(S("abcdefghij"), 0, 10, SV("1234567890"), 0, 5, S("12345"));
2465     test(S("abcdefghij"), 0, 10, SV("1234567890"), 0, 9, S("123456789"));
2466     test(S("abcdefghij"), 0, 10, SV("1234567890"), 0, 10, S("1234567890"));
2467     test(S("abcdefghij"), 0, 10, SV("1234567890"), 0, 11, S("1234567890"));
2468     test(S("abcdefghij"), 0, 10, SV("1234567890"), 1, 0, S(""));
2469     test(S("abcdefghij"), 0, 10, SV("1234567890"), 1, 1, S("2"));
2470     test(S("abcdefghij"), 0, 10, SV("1234567890"), 1, 4, S("2345"));
2471     test(S("abcdefghij"), 0, 10, SV("1234567890"), 1, 8, S("23456789"));
2472     test(S("abcdefghij"), 0, 10, SV("1234567890"), 1, 9, S("234567890"));
2473     test(S("abcdefghij"), 0, 10, SV("1234567890"), 1, 10, S("234567890"));
2474     test(S("abcdefghij"), 0, 10, SV("1234567890"), 5, 0, S(""));
2475     test(S("abcdefghij"), 0, 10, SV("1234567890"), 5, 1, S("6"));
2476     test(S("abcdefghij"), 0, 10, SV("1234567890"), 5, 2, S("67"));
2477     test(S("abcdefghij"), 0, 10, SV("1234567890"), 5, 4, S("6789"));
2478     test(S("abcdefghij"), 0, 10, SV("1234567890"), 5, 5, S("67890"));
2479     test(S("abcdefghij"), 0, 10, SV("1234567890"), 5, 6, S("67890"));
2480     test(S("abcdefghij"), 0, 10, SV("1234567890"), 9, 0, S(""));
2481     test(S("abcdefghij"), 0, 10, SV("1234567890"), 9, 1, S("0"));
2482     test(S("abcdefghij"), 0, 10, SV("1234567890"), 9, 2, S("0"));
2483     test(S("abcdefghij"), 0, 10, SV("1234567890"), 10, 0, S(""));
2484     test(S("abcdefghij"), 0, 10, SV("1234567890"), 10, 1, S(""));
2485     test(S("abcdefghij"), 0, 10, SV("1234567890"), 11, 0, S("can't happen"));
2486     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 0, 0, S(""));
2487     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 0, 1, S("1"));
2488     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 0, 10, S("1234567890"));
2489     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
2490     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
2491     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
2492     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 1, 0, S(""));
2493     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 1, 1, S("2"));
2494     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 1, 9, S("234567890"));
2495     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
2496     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
2497     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
2498     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 10, 0, S(""));
2499     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 10, 1, S("1"));
2500     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 10, 5, S("12345"));
2501     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 10, 9, S("123456789"));
2502     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 10, 10, S("1234567890"));
2503     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 10, 11, S("1234567890"));
2504     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 19, 0, S(""));
2505     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 19, 1, S("0"));
2506     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 19, 2, S("0"));
2507     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 20, 0, S(""));
2508     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 20, 1, S(""));
2509     test(S("abcdefghij"), 0, 10, SV("12345678901234567890"), 21, 0, S("can't happen"));
2510     test(S("abcdefghij"), 0, 11, SV(""), 0, 0, S(""));
2511     test(S("abcdefghij"), 0, 11, SV(""), 0, 1, S(""));
2512     test(S("abcdefghij"), 0, 11, SV(""), 1, 0, S("can't happen"));
2513     test(S("abcdefghij"), 0, 11, SV("12345"), 0, 0, S(""));
2514     test(S("abcdefghij"), 0, 11, SV("12345"), 0, 1, S("1"));
2515     test(S("abcdefghij"), 0, 11, SV("12345"), 0, 2, S("12"));
2516 }
2517 
2518 template <class S, class SV>
test23()2519 void test23()
2520 {
2521     test(S("abcdefghij"), 0, 11, SV("12345"), 0, 4, S("1234"));
2522     test(S("abcdefghij"), 0, 11, SV("12345"), 0, 5, S("12345"));
2523     test(S("abcdefghij"), 0, 11, SV("12345"), 0, 6, S("12345"));
2524     test(S("abcdefghij"), 0, 11, SV("12345"), 1, 0, S(""));
2525     test(S("abcdefghij"), 0, 11, SV("12345"), 1, 1, S("2"));
2526     test(S("abcdefghij"), 0, 11, SV("12345"), 1, 2, S("23"));
2527     test(S("abcdefghij"), 0, 11, SV("12345"), 1, 3, S("234"));
2528     test(S("abcdefghij"), 0, 11, SV("12345"), 1, 4, S("2345"));
2529     test(S("abcdefghij"), 0, 11, SV("12345"), 1, 5, S("2345"));
2530     test(S("abcdefghij"), 0, 11, SV("12345"), 2, 0, S(""));
2531     test(S("abcdefghij"), 0, 11, SV("12345"), 2, 1, S("3"));
2532     test(S("abcdefghij"), 0, 11, SV("12345"), 2, 2, S("34"));
2533     test(S("abcdefghij"), 0, 11, SV("12345"), 2, 3, S("345"));
2534     test(S("abcdefghij"), 0, 11, SV("12345"), 2, 4, S("345"));
2535     test(S("abcdefghij"), 0, 11, SV("12345"), 4, 0, S(""));
2536     test(S("abcdefghij"), 0, 11, SV("12345"), 4, 1, S("5"));
2537     test(S("abcdefghij"), 0, 11, SV("12345"), 4, 2, S("5"));
2538     test(S("abcdefghij"), 0, 11, SV("12345"), 5, 0, S(""));
2539     test(S("abcdefghij"), 0, 11, SV("12345"), 5, 1, S(""));
2540     test(S("abcdefghij"), 0, 11, SV("12345"), 6, 0, S("can't happen"));
2541     test(S("abcdefghij"), 0, 11, SV("1234567890"), 0, 0, S(""));
2542     test(S("abcdefghij"), 0, 11, SV("1234567890"), 0, 1, S("1"));
2543     test(S("abcdefghij"), 0, 11, SV("1234567890"), 0, 5, S("12345"));
2544     test(S("abcdefghij"), 0, 11, SV("1234567890"), 0, 9, S("123456789"));
2545     test(S("abcdefghij"), 0, 11, SV("1234567890"), 0, 10, S("1234567890"));
2546     test(S("abcdefghij"), 0, 11, SV("1234567890"), 0, 11, S("1234567890"));
2547     test(S("abcdefghij"), 0, 11, SV("1234567890"), 1, 0, S(""));
2548     test(S("abcdefghij"), 0, 11, SV("1234567890"), 1, 1, S("2"));
2549     test(S("abcdefghij"), 0, 11, SV("1234567890"), 1, 4, S("2345"));
2550     test(S("abcdefghij"), 0, 11, SV("1234567890"), 1, 8, S("23456789"));
2551     test(S("abcdefghij"), 0, 11, SV("1234567890"), 1, 9, S("234567890"));
2552     test(S("abcdefghij"), 0, 11, SV("1234567890"), 1, 10, S("234567890"));
2553     test(S("abcdefghij"), 0, 11, SV("1234567890"), 5, 0, S(""));
2554     test(S("abcdefghij"), 0, 11, SV("1234567890"), 5, 1, S("6"));
2555     test(S("abcdefghij"), 0, 11, SV("1234567890"), 5, 2, S("67"));
2556     test(S("abcdefghij"), 0, 11, SV("1234567890"), 5, 4, S("6789"));
2557     test(S("abcdefghij"), 0, 11, SV("1234567890"), 5, 5, S("67890"));
2558     test(S("abcdefghij"), 0, 11, SV("1234567890"), 5, 6, S("67890"));
2559     test(S("abcdefghij"), 0, 11, SV("1234567890"), 9, 0, S(""));
2560     test(S("abcdefghij"), 0, 11, SV("1234567890"), 9, 1, S("0"));
2561     test(S("abcdefghij"), 0, 11, SV("1234567890"), 9, 2, S("0"));
2562     test(S("abcdefghij"), 0, 11, SV("1234567890"), 10, 0, S(""));
2563     test(S("abcdefghij"), 0, 11, SV("1234567890"), 10, 1, S(""));
2564     test(S("abcdefghij"), 0, 11, SV("1234567890"), 11, 0, S("can't happen"));
2565     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 0, 0, S(""));
2566     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 0, 1, S("1"));
2567     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 0, 10, S("1234567890"));
2568     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
2569     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
2570     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
2571     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 1, 0, S(""));
2572     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 1, 1, S("2"));
2573     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 1, 9, S("234567890"));
2574     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
2575     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
2576     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
2577     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 10, 0, S(""));
2578     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 10, 1, S("1"));
2579     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 10, 5, S("12345"));
2580     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 10, 9, S("123456789"));
2581     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 10, 10, S("1234567890"));
2582     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 10, 11, S("1234567890"));
2583     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 19, 0, S(""));
2584     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 19, 1, S("0"));
2585     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 19, 2, S("0"));
2586     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 20, 0, S(""));
2587     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 20, 1, S(""));
2588     test(S("abcdefghij"), 0, 11, SV("12345678901234567890"), 21, 0, S("can't happen"));
2589     test(S("abcdefghij"), 1, 0, SV(""), 0, 0, S("abcdefghij"));
2590     test(S("abcdefghij"), 1, 0, SV(""), 0, 1, S("abcdefghij"));
2591     test(S("abcdefghij"), 1, 0, SV(""), 1, 0, S("can't happen"));
2592     test(S("abcdefghij"), 1, 0, SV("12345"), 0, 0, S("abcdefghij"));
2593     test(S("abcdefghij"), 1, 0, SV("12345"), 0, 1, S("a1bcdefghij"));
2594     test(S("abcdefghij"), 1, 0, SV("12345"), 0, 2, S("a12bcdefghij"));
2595     test(S("abcdefghij"), 1, 0, SV("12345"), 0, 4, S("a1234bcdefghij"));
2596     test(S("abcdefghij"), 1, 0, SV("12345"), 0, 5, S("a12345bcdefghij"));
2597     test(S("abcdefghij"), 1, 0, SV("12345"), 0, 6, S("a12345bcdefghij"));
2598     test(S("abcdefghij"), 1, 0, SV("12345"), 1, 0, S("abcdefghij"));
2599     test(S("abcdefghij"), 1, 0, SV("12345"), 1, 1, S("a2bcdefghij"));
2600     test(S("abcdefghij"), 1, 0, SV("12345"), 1, 2, S("a23bcdefghij"));
2601     test(S("abcdefghij"), 1, 0, SV("12345"), 1, 3, S("a234bcdefghij"));
2602     test(S("abcdefghij"), 1, 0, SV("12345"), 1, 4, S("a2345bcdefghij"));
2603     test(S("abcdefghij"), 1, 0, SV("12345"), 1, 5, S("a2345bcdefghij"));
2604     test(S("abcdefghij"), 1, 0, SV("12345"), 2, 0, S("abcdefghij"));
2605     test(S("abcdefghij"), 1, 0, SV("12345"), 2, 1, S("a3bcdefghij"));
2606     test(S("abcdefghij"), 1, 0, SV("12345"), 2, 2, S("a34bcdefghij"));
2607     test(S("abcdefghij"), 1, 0, SV("12345"), 2, 3, S("a345bcdefghij"));
2608     test(S("abcdefghij"), 1, 0, SV("12345"), 2, 4, S("a345bcdefghij"));
2609     test(S("abcdefghij"), 1, 0, SV("12345"), 4, 0, S("abcdefghij"));
2610     test(S("abcdefghij"), 1, 0, SV("12345"), 4, 1, S("a5bcdefghij"));
2611     test(S("abcdefghij"), 1, 0, SV("12345"), 4, 2, S("a5bcdefghij"));
2612     test(S("abcdefghij"), 1, 0, SV("12345"), 5, 0, S("abcdefghij"));
2613     test(S("abcdefghij"), 1, 0, SV("12345"), 5, 1, S("abcdefghij"));
2614     test(S("abcdefghij"), 1, 0, SV("12345"), 6, 0, S("can't happen"));
2615     test(S("abcdefghij"), 1, 0, SV("1234567890"), 0, 0, S("abcdefghij"));
2616     test(S("abcdefghij"), 1, 0, SV("1234567890"), 0, 1, S("a1bcdefghij"));
2617     test(S("abcdefghij"), 1, 0, SV("1234567890"), 0, 5, S("a12345bcdefghij"));
2618     test(S("abcdefghij"), 1, 0, SV("1234567890"), 0, 9, S("a123456789bcdefghij"));
2619     test(S("abcdefghij"), 1, 0, SV("1234567890"), 0, 10, S("a1234567890bcdefghij"));
2620     test(S("abcdefghij"), 1, 0, SV("1234567890"), 0, 11, S("a1234567890bcdefghij"));
2621 }
2622 
2623 template <class S, class SV>
test24()2624 void test24()
2625 {
2626     test(S("abcdefghij"), 1, 0, SV("1234567890"), 1, 0, S("abcdefghij"));
2627     test(S("abcdefghij"), 1, 0, SV("1234567890"), 1, 1, S("a2bcdefghij"));
2628     test(S("abcdefghij"), 1, 0, SV("1234567890"), 1, 4, S("a2345bcdefghij"));
2629     test(S("abcdefghij"), 1, 0, SV("1234567890"), 1, 8, S("a23456789bcdefghij"));
2630     test(S("abcdefghij"), 1, 0, SV("1234567890"), 1, 9, S("a234567890bcdefghij"));
2631     test(S("abcdefghij"), 1, 0, SV("1234567890"), 1, 10, S("a234567890bcdefghij"));
2632     test(S("abcdefghij"), 1, 0, SV("1234567890"), 5, 0, S("abcdefghij"));
2633     test(S("abcdefghij"), 1, 0, SV("1234567890"), 5, 1, S("a6bcdefghij"));
2634     test(S("abcdefghij"), 1, 0, SV("1234567890"), 5, 2, S("a67bcdefghij"));
2635     test(S("abcdefghij"), 1, 0, SV("1234567890"), 5, 4, S("a6789bcdefghij"));
2636     test(S("abcdefghij"), 1, 0, SV("1234567890"), 5, 5, S("a67890bcdefghij"));
2637     test(S("abcdefghij"), 1, 0, SV("1234567890"), 5, 6, S("a67890bcdefghij"));
2638     test(S("abcdefghij"), 1, 0, SV("1234567890"), 9, 0, S("abcdefghij"));
2639     test(S("abcdefghij"), 1, 0, SV("1234567890"), 9, 1, S("a0bcdefghij"));
2640     test(S("abcdefghij"), 1, 0, SV("1234567890"), 9, 2, S("a0bcdefghij"));
2641     test(S("abcdefghij"), 1, 0, SV("1234567890"), 10, 0, S("abcdefghij"));
2642     test(S("abcdefghij"), 1, 0, SV("1234567890"), 10, 1, S("abcdefghij"));
2643     test(S("abcdefghij"), 1, 0, SV("1234567890"), 11, 0, S("can't happen"));
2644     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
2645     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 0, 1, S("a1bcdefghij"));
2646     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 0, 10, S("a1234567890bcdefghij"));
2647     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghij"));
2648     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghij"));
2649     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghij"));
2650     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
2651     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 1, 1, S("a2bcdefghij"));
2652     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 1, 9, S("a234567890bcdefghij"));
2653     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghij"));
2654     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghij"));
2655     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghij"));
2656     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
2657     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 10, 1, S("a1bcdefghij"));
2658     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 10, 5, S("a12345bcdefghij"));
2659     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 10, 9, S("a123456789bcdefghij"));
2660     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 10, 10, S("a1234567890bcdefghij"));
2661     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 10, 11, S("a1234567890bcdefghij"));
2662     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
2663     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 19, 1, S("a0bcdefghij"));
2664     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 19, 2, S("a0bcdefghij"));
2665     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
2666     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
2667     test(S("abcdefghij"), 1, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
2668     test(S("abcdefghij"), 1, 1, SV(""), 0, 0, S("acdefghij"));
2669     test(S("abcdefghij"), 1, 1, SV(""), 0, 1, S("acdefghij"));
2670     test(S("abcdefghij"), 1, 1, SV(""), 1, 0, S("can't happen"));
2671     test(S("abcdefghij"), 1, 1, SV("12345"), 0, 0, S("acdefghij"));
2672     test(S("abcdefghij"), 1, 1, SV("12345"), 0, 1, S("a1cdefghij"));
2673     test(S("abcdefghij"), 1, 1, SV("12345"), 0, 2, S("a12cdefghij"));
2674     test(S("abcdefghij"), 1, 1, SV("12345"), 0, 4, S("a1234cdefghij"));
2675     test(S("abcdefghij"), 1, 1, SV("12345"), 0, 5, S("a12345cdefghij"));
2676     test(S("abcdefghij"), 1, 1, SV("12345"), 0, 6, S("a12345cdefghij"));
2677     test(S("abcdefghij"), 1, 1, SV("12345"), 1, 0, S("acdefghij"));
2678     test(S("abcdefghij"), 1, 1, SV("12345"), 1, 1, S("a2cdefghij"));
2679     test(S("abcdefghij"), 1, 1, SV("12345"), 1, 2, S("a23cdefghij"));
2680     test(S("abcdefghij"), 1, 1, SV("12345"), 1, 3, S("a234cdefghij"));
2681     test(S("abcdefghij"), 1, 1, SV("12345"), 1, 4, S("a2345cdefghij"));
2682     test(S("abcdefghij"), 1, 1, SV("12345"), 1, 5, S("a2345cdefghij"));
2683     test(S("abcdefghij"), 1, 1, SV("12345"), 2, 0, S("acdefghij"));
2684     test(S("abcdefghij"), 1, 1, SV("12345"), 2, 1, S("a3cdefghij"));
2685     test(S("abcdefghij"), 1, 1, SV("12345"), 2, 2, S("a34cdefghij"));
2686     test(S("abcdefghij"), 1, 1, SV("12345"), 2, 3, S("a345cdefghij"));
2687     test(S("abcdefghij"), 1, 1, SV("12345"), 2, 4, S("a345cdefghij"));
2688     test(S("abcdefghij"), 1, 1, SV("12345"), 4, 0, S("acdefghij"));
2689     test(S("abcdefghij"), 1, 1, SV("12345"), 4, 1, S("a5cdefghij"));
2690     test(S("abcdefghij"), 1, 1, SV("12345"), 4, 2, S("a5cdefghij"));
2691     test(S("abcdefghij"), 1, 1, SV("12345"), 5, 0, S("acdefghij"));
2692     test(S("abcdefghij"), 1, 1, SV("12345"), 5, 1, S("acdefghij"));
2693     test(S("abcdefghij"), 1, 1, SV("12345"), 6, 0, S("can't happen"));
2694     test(S("abcdefghij"), 1, 1, SV("1234567890"), 0, 0, S("acdefghij"));
2695     test(S("abcdefghij"), 1, 1, SV("1234567890"), 0, 1, S("a1cdefghij"));
2696     test(S("abcdefghij"), 1, 1, SV("1234567890"), 0, 5, S("a12345cdefghij"));
2697     test(S("abcdefghij"), 1, 1, SV("1234567890"), 0, 9, S("a123456789cdefghij"));
2698     test(S("abcdefghij"), 1, 1, SV("1234567890"), 0, 10, S("a1234567890cdefghij"));
2699     test(S("abcdefghij"), 1, 1, SV("1234567890"), 0, 11, S("a1234567890cdefghij"));
2700     test(S("abcdefghij"), 1, 1, SV("1234567890"), 1, 0, S("acdefghij"));
2701     test(S("abcdefghij"), 1, 1, SV("1234567890"), 1, 1, S("a2cdefghij"));
2702     test(S("abcdefghij"), 1, 1, SV("1234567890"), 1, 4, S("a2345cdefghij"));
2703     test(S("abcdefghij"), 1, 1, SV("1234567890"), 1, 8, S("a23456789cdefghij"));
2704     test(S("abcdefghij"), 1, 1, SV("1234567890"), 1, 9, S("a234567890cdefghij"));
2705     test(S("abcdefghij"), 1, 1, SV("1234567890"), 1, 10, S("a234567890cdefghij"));
2706     test(S("abcdefghij"), 1, 1, SV("1234567890"), 5, 0, S("acdefghij"));
2707     test(S("abcdefghij"), 1, 1, SV("1234567890"), 5, 1, S("a6cdefghij"));
2708     test(S("abcdefghij"), 1, 1, SV("1234567890"), 5, 2, S("a67cdefghij"));
2709     test(S("abcdefghij"), 1, 1, SV("1234567890"), 5, 4, S("a6789cdefghij"));
2710     test(S("abcdefghij"), 1, 1, SV("1234567890"), 5, 5, S("a67890cdefghij"));
2711     test(S("abcdefghij"), 1, 1, SV("1234567890"), 5, 6, S("a67890cdefghij"));
2712     test(S("abcdefghij"), 1, 1, SV("1234567890"), 9, 0, S("acdefghij"));
2713     test(S("abcdefghij"), 1, 1, SV("1234567890"), 9, 1, S("a0cdefghij"));
2714     test(S("abcdefghij"), 1, 1, SV("1234567890"), 9, 2, S("a0cdefghij"));
2715     test(S("abcdefghij"), 1, 1, SV("1234567890"), 10, 0, S("acdefghij"));
2716     test(S("abcdefghij"), 1, 1, SV("1234567890"), 10, 1, S("acdefghij"));
2717     test(S("abcdefghij"), 1, 1, SV("1234567890"), 11, 0, S("can't happen"));
2718     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 0, 0, S("acdefghij"));
2719     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 0, 1, S("a1cdefghij"));
2720     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 0, 10, S("a1234567890cdefghij"));
2721     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 0, 19, S("a1234567890123456789cdefghij"));
2722     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 0, 20, S("a12345678901234567890cdefghij"));
2723     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 0, 21, S("a12345678901234567890cdefghij"));
2724     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 1, 0, S("acdefghij"));
2725     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 1, 1, S("a2cdefghij"));
2726 }
2727 
2728 template <class S, class SV>
test25()2729 void test25()
2730 {
2731     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 1, 9, S("a234567890cdefghij"));
2732     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 1, 18, S("a234567890123456789cdefghij"));
2733     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 1, 19, S("a2345678901234567890cdefghij"));
2734     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 1, 20, S("a2345678901234567890cdefghij"));
2735     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 10, 0, S("acdefghij"));
2736     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 10, 1, S("a1cdefghij"));
2737     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 10, 5, S("a12345cdefghij"));
2738     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 10, 9, S("a123456789cdefghij"));
2739     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 10, 10, S("a1234567890cdefghij"));
2740     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 10, 11, S("a1234567890cdefghij"));
2741     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 19, 0, S("acdefghij"));
2742     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 19, 1, S("a0cdefghij"));
2743     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 19, 2, S("a0cdefghij"));
2744     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 20, 0, S("acdefghij"));
2745     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 20, 1, S("acdefghij"));
2746     test(S("abcdefghij"), 1, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
2747     test(S("abcdefghij"), 1, 4, SV(""), 0, 0, S("afghij"));
2748     test(S("abcdefghij"), 1, 4, SV(""), 0, 1, S("afghij"));
2749     test(S("abcdefghij"), 1, 4, SV(""), 1, 0, S("can't happen"));
2750     test(S("abcdefghij"), 1, 4, SV("12345"), 0, 0, S("afghij"));
2751     test(S("abcdefghij"), 1, 4, SV("12345"), 0, 1, S("a1fghij"));
2752     test(S("abcdefghij"), 1, 4, SV("12345"), 0, 2, S("a12fghij"));
2753     test(S("abcdefghij"), 1, 4, SV("12345"), 0, 4, S("a1234fghij"));
2754     test(S("abcdefghij"), 1, 4, SV("12345"), 0, 5, S("a12345fghij"));
2755     test(S("abcdefghij"), 1, 4, SV("12345"), 0, 6, S("a12345fghij"));
2756     test(S("abcdefghij"), 1, 4, SV("12345"), 1, 0, S("afghij"));
2757     test(S("abcdefghij"), 1, 4, SV("12345"), 1, 1, S("a2fghij"));
2758     test(S("abcdefghij"), 1, 4, SV("12345"), 1, 2, S("a23fghij"));
2759     test(S("abcdefghij"), 1, 4, SV("12345"), 1, 3, S("a234fghij"));
2760     test(S("abcdefghij"), 1, 4, SV("12345"), 1, 4, S("a2345fghij"));
2761     test(S("abcdefghij"), 1, 4, SV("12345"), 1, 5, S("a2345fghij"));
2762     test(S("abcdefghij"), 1, 4, SV("12345"), 2, 0, S("afghij"));
2763     test(S("abcdefghij"), 1, 4, SV("12345"), 2, 1, S("a3fghij"));
2764     test(S("abcdefghij"), 1, 4, SV("12345"), 2, 2, S("a34fghij"));
2765     test(S("abcdefghij"), 1, 4, SV("12345"), 2, 3, S("a345fghij"));
2766     test(S("abcdefghij"), 1, 4, SV("12345"), 2, 4, S("a345fghij"));
2767     test(S("abcdefghij"), 1, 4, SV("12345"), 4, 0, S("afghij"));
2768     test(S("abcdefghij"), 1, 4, SV("12345"), 4, 1, S("a5fghij"));
2769     test(S("abcdefghij"), 1, 4, SV("12345"), 4, 2, S("a5fghij"));
2770     test(S("abcdefghij"), 1, 4, SV("12345"), 5, 0, S("afghij"));
2771     test(S("abcdefghij"), 1, 4, SV("12345"), 5, 1, S("afghij"));
2772     test(S("abcdefghij"), 1, 4, SV("12345"), 6, 0, S("can't happen"));
2773     test(S("abcdefghij"), 1, 4, SV("1234567890"), 0, 0, S("afghij"));
2774     test(S("abcdefghij"), 1, 4, SV("1234567890"), 0, 1, S("a1fghij"));
2775     test(S("abcdefghij"), 1, 4, SV("1234567890"), 0, 5, S("a12345fghij"));
2776     test(S("abcdefghij"), 1, 4, SV("1234567890"), 0, 9, S("a123456789fghij"));
2777     test(S("abcdefghij"), 1, 4, SV("1234567890"), 0, 10, S("a1234567890fghij"));
2778     test(S("abcdefghij"), 1, 4, SV("1234567890"), 0, 11, S("a1234567890fghij"));
2779     test(S("abcdefghij"), 1, 4, SV("1234567890"), 1, 0, S("afghij"));
2780     test(S("abcdefghij"), 1, 4, SV("1234567890"), 1, 1, S("a2fghij"));
2781     test(S("abcdefghij"), 1, 4, SV("1234567890"), 1, 4, S("a2345fghij"));
2782     test(S("abcdefghij"), 1, 4, SV("1234567890"), 1, 8, S("a23456789fghij"));
2783     test(S("abcdefghij"), 1, 4, SV("1234567890"), 1, 9, S("a234567890fghij"));
2784     test(S("abcdefghij"), 1, 4, SV("1234567890"), 1, 10, S("a234567890fghij"));
2785     test(S("abcdefghij"), 1, 4, SV("1234567890"), 5, 0, S("afghij"));
2786     test(S("abcdefghij"), 1, 4, SV("1234567890"), 5, 1, S("a6fghij"));
2787     test(S("abcdefghij"), 1, 4, SV("1234567890"), 5, 2, S("a67fghij"));
2788     test(S("abcdefghij"), 1, 4, SV("1234567890"), 5, 4, S("a6789fghij"));
2789     test(S("abcdefghij"), 1, 4, SV("1234567890"), 5, 5, S("a67890fghij"));
2790     test(S("abcdefghij"), 1, 4, SV("1234567890"), 5, 6, S("a67890fghij"));
2791     test(S("abcdefghij"), 1, 4, SV("1234567890"), 9, 0, S("afghij"));
2792     test(S("abcdefghij"), 1, 4, SV("1234567890"), 9, 1, S("a0fghij"));
2793     test(S("abcdefghij"), 1, 4, SV("1234567890"), 9, 2, S("a0fghij"));
2794     test(S("abcdefghij"), 1, 4, SV("1234567890"), 10, 0, S("afghij"));
2795     test(S("abcdefghij"), 1, 4, SV("1234567890"), 10, 1, S("afghij"));
2796     test(S("abcdefghij"), 1, 4, SV("1234567890"), 11, 0, S("can't happen"));
2797     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 0, 0, S("afghij"));
2798     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 0, 1, S("a1fghij"));
2799     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 0, 10, S("a1234567890fghij"));
2800     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 0, 19, S("a1234567890123456789fghij"));
2801     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 0, 20, S("a12345678901234567890fghij"));
2802     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 0, 21, S("a12345678901234567890fghij"));
2803     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 1, 0, S("afghij"));
2804     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 1, 1, S("a2fghij"));
2805     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 1, 9, S("a234567890fghij"));
2806     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 1, 18, S("a234567890123456789fghij"));
2807     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 1, 19, S("a2345678901234567890fghij"));
2808     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 1, 20, S("a2345678901234567890fghij"));
2809     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 10, 0, S("afghij"));
2810     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 10, 1, S("a1fghij"));
2811     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 10, 5, S("a12345fghij"));
2812     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 10, 9, S("a123456789fghij"));
2813     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 10, 10, S("a1234567890fghij"));
2814     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 10, 11, S("a1234567890fghij"));
2815     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 19, 0, S("afghij"));
2816     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 19, 1, S("a0fghij"));
2817     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 19, 2, S("a0fghij"));
2818     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 20, 0, S("afghij"));
2819     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 20, 1, S("afghij"));
2820     test(S("abcdefghij"), 1, 4, SV("12345678901234567890"), 21, 0, S("can't happen"));
2821     test(S("abcdefghij"), 1, 8, SV(""), 0, 0, S("aj"));
2822     test(S("abcdefghij"), 1, 8, SV(""), 0, 1, S("aj"));
2823     test(S("abcdefghij"), 1, 8, SV(""), 1, 0, S("can't happen"));
2824     test(S("abcdefghij"), 1, 8, SV("12345"), 0, 0, S("aj"));
2825     test(S("abcdefghij"), 1, 8, SV("12345"), 0, 1, S("a1j"));
2826     test(S("abcdefghij"), 1, 8, SV("12345"), 0, 2, S("a12j"));
2827     test(S("abcdefghij"), 1, 8, SV("12345"), 0, 4, S("a1234j"));
2828     test(S("abcdefghij"), 1, 8, SV("12345"), 0, 5, S("a12345j"));
2829     test(S("abcdefghij"), 1, 8, SV("12345"), 0, 6, S("a12345j"));
2830     test(S("abcdefghij"), 1, 8, SV("12345"), 1, 0, S("aj"));
2831 }
2832 
2833 template <class S, class SV>
test26()2834 void test26()
2835 {
2836     test(S("abcdefghij"), 1, 8, SV("12345"), 1, 1, S("a2j"));
2837     test(S("abcdefghij"), 1, 8, SV("12345"), 1, 2, S("a23j"));
2838     test(S("abcdefghij"), 1, 8, SV("12345"), 1, 3, S("a234j"));
2839     test(S("abcdefghij"), 1, 8, SV("12345"), 1, 4, S("a2345j"));
2840     test(S("abcdefghij"), 1, 8, SV("12345"), 1, 5, S("a2345j"));
2841     test(S("abcdefghij"), 1, 8, SV("12345"), 2, 0, S("aj"));
2842     test(S("abcdefghij"), 1, 8, SV("12345"), 2, 1, S("a3j"));
2843     test(S("abcdefghij"), 1, 8, SV("12345"), 2, 2, S("a34j"));
2844     test(S("abcdefghij"), 1, 8, SV("12345"), 2, 3, S("a345j"));
2845     test(S("abcdefghij"), 1, 8, SV("12345"), 2, 4, S("a345j"));
2846     test(S("abcdefghij"), 1, 8, SV("12345"), 4, 0, S("aj"));
2847     test(S("abcdefghij"), 1, 8, SV("12345"), 4, 1, S("a5j"));
2848     test(S("abcdefghij"), 1, 8, SV("12345"), 4, 2, S("a5j"));
2849     test(S("abcdefghij"), 1, 8, SV("12345"), 5, 0, S("aj"));
2850     test(S("abcdefghij"), 1, 8, SV("12345"), 5, 1, S("aj"));
2851     test(S("abcdefghij"), 1, 8, SV("12345"), 6, 0, S("can't happen"));
2852     test(S("abcdefghij"), 1, 8, SV("1234567890"), 0, 0, S("aj"));
2853     test(S("abcdefghij"), 1, 8, SV("1234567890"), 0, 1, S("a1j"));
2854     test(S("abcdefghij"), 1, 8, SV("1234567890"), 0, 5, S("a12345j"));
2855     test(S("abcdefghij"), 1, 8, SV("1234567890"), 0, 9, S("a123456789j"));
2856     test(S("abcdefghij"), 1, 8, SV("1234567890"), 0, 10, S("a1234567890j"));
2857     test(S("abcdefghij"), 1, 8, SV("1234567890"), 0, 11, S("a1234567890j"));
2858     test(S("abcdefghij"), 1, 8, SV("1234567890"), 1, 0, S("aj"));
2859     test(S("abcdefghij"), 1, 8, SV("1234567890"), 1, 1, S("a2j"));
2860     test(S("abcdefghij"), 1, 8, SV("1234567890"), 1, 4, S("a2345j"));
2861     test(S("abcdefghij"), 1, 8, SV("1234567890"), 1, 8, S("a23456789j"));
2862     test(S("abcdefghij"), 1, 8, SV("1234567890"), 1, 9, S("a234567890j"));
2863     test(S("abcdefghij"), 1, 8, SV("1234567890"), 1, 10, S("a234567890j"));
2864     test(S("abcdefghij"), 1, 8, SV("1234567890"), 5, 0, S("aj"));
2865     test(S("abcdefghij"), 1, 8, SV("1234567890"), 5, 1, S("a6j"));
2866     test(S("abcdefghij"), 1, 8, SV("1234567890"), 5, 2, S("a67j"));
2867     test(S("abcdefghij"), 1, 8, SV("1234567890"), 5, 4, S("a6789j"));
2868     test(S("abcdefghij"), 1, 8, SV("1234567890"), 5, 5, S("a67890j"));
2869     test(S("abcdefghij"), 1, 8, SV("1234567890"), 5, 6, S("a67890j"));
2870     test(S("abcdefghij"), 1, 8, SV("1234567890"), 9, 0, S("aj"));
2871     test(S("abcdefghij"), 1, 8, SV("1234567890"), 9, 1, S("a0j"));
2872     test(S("abcdefghij"), 1, 8, SV("1234567890"), 9, 2, S("a0j"));
2873     test(S("abcdefghij"), 1, 8, SV("1234567890"), 10, 0, S("aj"));
2874     test(S("abcdefghij"), 1, 8, SV("1234567890"), 10, 1, S("aj"));
2875     test(S("abcdefghij"), 1, 8, SV("1234567890"), 11, 0, S("can't happen"));
2876     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 0, 0, S("aj"));
2877     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 0, 1, S("a1j"));
2878     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 0, 10, S("a1234567890j"));
2879     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 0, 19, S("a1234567890123456789j"));
2880     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 0, 20, S("a12345678901234567890j"));
2881     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 0, 21, S("a12345678901234567890j"));
2882     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 1, 0, S("aj"));
2883     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 1, 1, S("a2j"));
2884     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 1, 9, S("a234567890j"));
2885     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 1, 18, S("a234567890123456789j"));
2886     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 1, 19, S("a2345678901234567890j"));
2887     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 1, 20, S("a2345678901234567890j"));
2888     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 10, 0, S("aj"));
2889     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 10, 1, S("a1j"));
2890     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 10, 5, S("a12345j"));
2891     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 10, 9, S("a123456789j"));
2892     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 10, 10, S("a1234567890j"));
2893     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 10, 11, S("a1234567890j"));
2894     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 19, 0, S("aj"));
2895     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 19, 1, S("a0j"));
2896     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 19, 2, S("a0j"));
2897     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 20, 0, S("aj"));
2898     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 20, 1, S("aj"));
2899     test(S("abcdefghij"), 1, 8, SV("12345678901234567890"), 21, 0, S("can't happen"));
2900     test(S("abcdefghij"), 1, 9, SV(""), 0, 0, S("a"));
2901     test(S("abcdefghij"), 1, 9, SV(""), 0, 1, S("a"));
2902     test(S("abcdefghij"), 1, 9, SV(""), 1, 0, S("can't happen"));
2903     test(S("abcdefghij"), 1, 9, SV("12345"), 0, 0, S("a"));
2904     test(S("abcdefghij"), 1, 9, SV("12345"), 0, 1, S("a1"));
2905     test(S("abcdefghij"), 1, 9, SV("12345"), 0, 2, S("a12"));
2906     test(S("abcdefghij"), 1, 9, SV("12345"), 0, 4, S("a1234"));
2907     test(S("abcdefghij"), 1, 9, SV("12345"), 0, 5, S("a12345"));
2908     test(S("abcdefghij"), 1, 9, SV("12345"), 0, 6, S("a12345"));
2909     test(S("abcdefghij"), 1, 9, SV("12345"), 1, 0, S("a"));
2910     test(S("abcdefghij"), 1, 9, SV("12345"), 1, 1, S("a2"));
2911     test(S("abcdefghij"), 1, 9, SV("12345"), 1, 2, S("a23"));
2912     test(S("abcdefghij"), 1, 9, SV("12345"), 1, 3, S("a234"));
2913     test(S("abcdefghij"), 1, 9, SV("12345"), 1, 4, S("a2345"));
2914     test(S("abcdefghij"), 1, 9, SV("12345"), 1, 5, S("a2345"));
2915     test(S("abcdefghij"), 1, 9, SV("12345"), 2, 0, S("a"));
2916     test(S("abcdefghij"), 1, 9, SV("12345"), 2, 1, S("a3"));
2917     test(S("abcdefghij"), 1, 9, SV("12345"), 2, 2, S("a34"));
2918     test(S("abcdefghij"), 1, 9, SV("12345"), 2, 3, S("a345"));
2919     test(S("abcdefghij"), 1, 9, SV("12345"), 2, 4, S("a345"));
2920     test(S("abcdefghij"), 1, 9, SV("12345"), 4, 0, S("a"));
2921     test(S("abcdefghij"), 1, 9, SV("12345"), 4, 1, S("a5"));
2922     test(S("abcdefghij"), 1, 9, SV("12345"), 4, 2, S("a5"));
2923     test(S("abcdefghij"), 1, 9, SV("12345"), 5, 0, S("a"));
2924     test(S("abcdefghij"), 1, 9, SV("12345"), 5, 1, S("a"));
2925     test(S("abcdefghij"), 1, 9, SV("12345"), 6, 0, S("can't happen"));
2926     test(S("abcdefghij"), 1, 9, SV("1234567890"), 0, 0, S("a"));
2927     test(S("abcdefghij"), 1, 9, SV("1234567890"), 0, 1, S("a1"));
2928     test(S("abcdefghij"), 1, 9, SV("1234567890"), 0, 5, S("a12345"));
2929     test(S("abcdefghij"), 1, 9, SV("1234567890"), 0, 9, S("a123456789"));
2930     test(S("abcdefghij"), 1, 9, SV("1234567890"), 0, 10, S("a1234567890"));
2931     test(S("abcdefghij"), 1, 9, SV("1234567890"), 0, 11, S("a1234567890"));
2932     test(S("abcdefghij"), 1, 9, SV("1234567890"), 1, 0, S("a"));
2933     test(S("abcdefghij"), 1, 9, SV("1234567890"), 1, 1, S("a2"));
2934     test(S("abcdefghij"), 1, 9, SV("1234567890"), 1, 4, S("a2345"));
2935     test(S("abcdefghij"), 1, 9, SV("1234567890"), 1, 8, S("a23456789"));
2936 }
2937 
2938 template <class S, class SV>
test27()2939 void test27()
2940 {
2941     test(S("abcdefghij"), 1, 9, SV("1234567890"), 1, 9, S("a234567890"));
2942     test(S("abcdefghij"), 1, 9, SV("1234567890"), 1, 10, S("a234567890"));
2943     test(S("abcdefghij"), 1, 9, SV("1234567890"), 5, 0, S("a"));
2944     test(S("abcdefghij"), 1, 9, SV("1234567890"), 5, 1, S("a6"));
2945     test(S("abcdefghij"), 1, 9, SV("1234567890"), 5, 2, S("a67"));
2946     test(S("abcdefghij"), 1, 9, SV("1234567890"), 5, 4, S("a6789"));
2947     test(S("abcdefghij"), 1, 9, SV("1234567890"), 5, 5, S("a67890"));
2948     test(S("abcdefghij"), 1, 9, SV("1234567890"), 5, 6, S("a67890"));
2949     test(S("abcdefghij"), 1, 9, SV("1234567890"), 9, 0, S("a"));
2950     test(S("abcdefghij"), 1, 9, SV("1234567890"), 9, 1, S("a0"));
2951     test(S("abcdefghij"), 1, 9, SV("1234567890"), 9, 2, S("a0"));
2952     test(S("abcdefghij"), 1, 9, SV("1234567890"), 10, 0, S("a"));
2953     test(S("abcdefghij"), 1, 9, SV("1234567890"), 10, 1, S("a"));
2954     test(S("abcdefghij"), 1, 9, SV("1234567890"), 11, 0, S("can't happen"));
2955     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 0, 0, S("a"));
2956     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 0, 1, S("a1"));
2957     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 0, 10, S("a1234567890"));
2958     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 0, 19, S("a1234567890123456789"));
2959     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 0, 20, S("a12345678901234567890"));
2960     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 0, 21, S("a12345678901234567890"));
2961     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 1, 0, S("a"));
2962     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 1, 1, S("a2"));
2963     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 1, 9, S("a234567890"));
2964     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 1, 18, S("a234567890123456789"));
2965     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 1, 19, S("a2345678901234567890"));
2966     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 1, 20, S("a2345678901234567890"));
2967     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 10, 0, S("a"));
2968     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 10, 1, S("a1"));
2969     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 10, 5, S("a12345"));
2970     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 10, 9, S("a123456789"));
2971     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 10, 10, S("a1234567890"));
2972     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 10, 11, S("a1234567890"));
2973     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 19, 0, S("a"));
2974     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 19, 1, S("a0"));
2975     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 19, 2, S("a0"));
2976     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 20, 0, S("a"));
2977     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 20, 1, S("a"));
2978     test(S("abcdefghij"), 1, 9, SV("12345678901234567890"), 21, 0, S("can't happen"));
2979     test(S("abcdefghij"), 1, 10, SV(""), 0, 0, S("a"));
2980     test(S("abcdefghij"), 1, 10, SV(""), 0, 1, S("a"));
2981     test(S("abcdefghij"), 1, 10, SV(""), 1, 0, S("can't happen"));
2982     test(S("abcdefghij"), 1, 10, SV("12345"), 0, 0, S("a"));
2983     test(S("abcdefghij"), 1, 10, SV("12345"), 0, 1, S("a1"));
2984     test(S("abcdefghij"), 1, 10, SV("12345"), 0, 2, S("a12"));
2985     test(S("abcdefghij"), 1, 10, SV("12345"), 0, 4, S("a1234"));
2986     test(S("abcdefghij"), 1, 10, SV("12345"), 0, 5, S("a12345"));
2987     test(S("abcdefghij"), 1, 10, SV("12345"), 0, 6, S("a12345"));
2988     test(S("abcdefghij"), 1, 10, SV("12345"), 1, 0, S("a"));
2989     test(S("abcdefghij"), 1, 10, SV("12345"), 1, 1, S("a2"));
2990     test(S("abcdefghij"), 1, 10, SV("12345"), 1, 2, S("a23"));
2991     test(S("abcdefghij"), 1, 10, SV("12345"), 1, 3, S("a234"));
2992     test(S("abcdefghij"), 1, 10, SV("12345"), 1, 4, S("a2345"));
2993     test(S("abcdefghij"), 1, 10, SV("12345"), 1, 5, S("a2345"));
2994     test(S("abcdefghij"), 1, 10, SV("12345"), 2, 0, S("a"));
2995     test(S("abcdefghij"), 1, 10, SV("12345"), 2, 1, S("a3"));
2996     test(S("abcdefghij"), 1, 10, SV("12345"), 2, 2, S("a34"));
2997     test(S("abcdefghij"), 1, 10, SV("12345"), 2, 3, S("a345"));
2998     test(S("abcdefghij"), 1, 10, SV("12345"), 2, 4, S("a345"));
2999     test(S("abcdefghij"), 1, 10, SV("12345"), 4, 0, S("a"));
3000     test(S("abcdefghij"), 1, 10, SV("12345"), 4, 1, S("a5"));
3001     test(S("abcdefghij"), 1, 10, SV("12345"), 4, 2, S("a5"));
3002     test(S("abcdefghij"), 1, 10, SV("12345"), 5, 0, S("a"));
3003     test(S("abcdefghij"), 1, 10, SV("12345"), 5, 1, S("a"));
3004     test(S("abcdefghij"), 1, 10, SV("12345"), 6, 0, S("can't happen"));
3005     test(S("abcdefghij"), 1, 10, SV("1234567890"), 0, 0, S("a"));
3006     test(S("abcdefghij"), 1, 10, SV("1234567890"), 0, 1, S("a1"));
3007     test(S("abcdefghij"), 1, 10, SV("1234567890"), 0, 5, S("a12345"));
3008     test(S("abcdefghij"), 1, 10, SV("1234567890"), 0, 9, S("a123456789"));
3009     test(S("abcdefghij"), 1, 10, SV("1234567890"), 0, 10, S("a1234567890"));
3010     test(S("abcdefghij"), 1, 10, SV("1234567890"), 0, 11, S("a1234567890"));
3011     test(S("abcdefghij"), 1, 10, SV("1234567890"), 1, 0, S("a"));
3012     test(S("abcdefghij"), 1, 10, SV("1234567890"), 1, 1, S("a2"));
3013     test(S("abcdefghij"), 1, 10, SV("1234567890"), 1, 4, S("a2345"));
3014     test(S("abcdefghij"), 1, 10, SV("1234567890"), 1, 8, S("a23456789"));
3015     test(S("abcdefghij"), 1, 10, SV("1234567890"), 1, 9, S("a234567890"));
3016     test(S("abcdefghij"), 1, 10, SV("1234567890"), 1, 10, S("a234567890"));
3017     test(S("abcdefghij"), 1, 10, SV("1234567890"), 5, 0, S("a"));
3018     test(S("abcdefghij"), 1, 10, SV("1234567890"), 5, 1, S("a6"));
3019     test(S("abcdefghij"), 1, 10, SV("1234567890"), 5, 2, S("a67"));
3020     test(S("abcdefghij"), 1, 10, SV("1234567890"), 5, 4, S("a6789"));
3021     test(S("abcdefghij"), 1, 10, SV("1234567890"), 5, 5, S("a67890"));
3022     test(S("abcdefghij"), 1, 10, SV("1234567890"), 5, 6, S("a67890"));
3023     test(S("abcdefghij"), 1, 10, SV("1234567890"), 9, 0, S("a"));
3024     test(S("abcdefghij"), 1, 10, SV("1234567890"), 9, 1, S("a0"));
3025     test(S("abcdefghij"), 1, 10, SV("1234567890"), 9, 2, S("a0"));
3026     test(S("abcdefghij"), 1, 10, SV("1234567890"), 10, 0, S("a"));
3027     test(S("abcdefghij"), 1, 10, SV("1234567890"), 10, 1, S("a"));
3028     test(S("abcdefghij"), 1, 10, SV("1234567890"), 11, 0, S("can't happen"));
3029     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 0, 0, S("a"));
3030     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 0, 1, S("a1"));
3031     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 0, 10, S("a1234567890"));
3032     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 0, 19, S("a1234567890123456789"));
3033     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 0, 20, S("a12345678901234567890"));
3034     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 0, 21, S("a12345678901234567890"));
3035     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 1, 0, S("a"));
3036     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 1, 1, S("a2"));
3037     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 1, 9, S("a234567890"));
3038     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 1, 18, S("a234567890123456789"));
3039     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 1, 19, S("a2345678901234567890"));
3040     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 1, 20, S("a2345678901234567890"));
3041 }
3042 
3043 template <class S, class SV>
test28()3044 void test28()
3045 {
3046     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 10, 0, S("a"));
3047     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 10, 1, S("a1"));
3048     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 10, 5, S("a12345"));
3049     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 10, 9, S("a123456789"));
3050     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 10, 10, S("a1234567890"));
3051     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 10, 11, S("a1234567890"));
3052     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 19, 0, S("a"));
3053     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 19, 1, S("a0"));
3054     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 19, 2, S("a0"));
3055     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 20, 0, S("a"));
3056     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 20, 1, S("a"));
3057     test(S("abcdefghij"), 1, 10, SV("12345678901234567890"), 21, 0, S("can't happen"));
3058     test(S("abcdefghij"), 5, 0, SV(""), 0, 0, S("abcdefghij"));
3059     test(S("abcdefghij"), 5, 0, SV(""), 0, 1, S("abcdefghij"));
3060     test(S("abcdefghij"), 5, 0, SV(""), 1, 0, S("can't happen"));
3061     test(S("abcdefghij"), 5, 0, SV("12345"), 0, 0, S("abcdefghij"));
3062     test(S("abcdefghij"), 5, 0, SV("12345"), 0, 1, S("abcde1fghij"));
3063     test(S("abcdefghij"), 5, 0, SV("12345"), 0, 2, S("abcde12fghij"));
3064     test(S("abcdefghij"), 5, 0, SV("12345"), 0, 4, S("abcde1234fghij"));
3065     test(S("abcdefghij"), 5, 0, SV("12345"), 0, 5, S("abcde12345fghij"));
3066     test(S("abcdefghij"), 5, 0, SV("12345"), 0, 6, S("abcde12345fghij"));
3067     test(S("abcdefghij"), 5, 0, SV("12345"), 1, 0, S("abcdefghij"));
3068     test(S("abcdefghij"), 5, 0, SV("12345"), 1, 1, S("abcde2fghij"));
3069     test(S("abcdefghij"), 5, 0, SV("12345"), 1, 2, S("abcde23fghij"));
3070     test(S("abcdefghij"), 5, 0, SV("12345"), 1, 3, S("abcde234fghij"));
3071     test(S("abcdefghij"), 5, 0, SV("12345"), 1, 4, S("abcde2345fghij"));
3072     test(S("abcdefghij"), 5, 0, SV("12345"), 1, 5, S("abcde2345fghij"));
3073     test(S("abcdefghij"), 5, 0, SV("12345"), 2, 0, S("abcdefghij"));
3074     test(S("abcdefghij"), 5, 0, SV("12345"), 2, 1, S("abcde3fghij"));
3075     test(S("abcdefghij"), 5, 0, SV("12345"), 2, 2, S("abcde34fghij"));
3076     test(S("abcdefghij"), 5, 0, SV("12345"), 2, 3, S("abcde345fghij"));
3077     test(S("abcdefghij"), 5, 0, SV("12345"), 2, 4, S("abcde345fghij"));
3078     test(S("abcdefghij"), 5, 0, SV("12345"), 4, 0, S("abcdefghij"));
3079     test(S("abcdefghij"), 5, 0, SV("12345"), 4, 1, S("abcde5fghij"));
3080     test(S("abcdefghij"), 5, 0, SV("12345"), 4, 2, S("abcde5fghij"));
3081     test(S("abcdefghij"), 5, 0, SV("12345"), 5, 0, S("abcdefghij"));
3082     test(S("abcdefghij"), 5, 0, SV("12345"), 5, 1, S("abcdefghij"));
3083     test(S("abcdefghij"), 5, 0, SV("12345"), 6, 0, S("can't happen"));
3084     test(S("abcdefghij"), 5, 0, SV("1234567890"), 0, 0, S("abcdefghij"));
3085     test(S("abcdefghij"), 5, 0, SV("1234567890"), 0, 1, S("abcde1fghij"));
3086     test(S("abcdefghij"), 5, 0, SV("1234567890"), 0, 5, S("abcde12345fghij"));
3087     test(S("abcdefghij"), 5, 0, SV("1234567890"), 0, 9, S("abcde123456789fghij"));
3088     test(S("abcdefghij"), 5, 0, SV("1234567890"), 0, 10, S("abcde1234567890fghij"));
3089     test(S("abcdefghij"), 5, 0, SV("1234567890"), 0, 11, S("abcde1234567890fghij"));
3090     test(S("abcdefghij"), 5, 0, SV("1234567890"), 1, 0, S("abcdefghij"));
3091     test(S("abcdefghij"), 5, 0, SV("1234567890"), 1, 1, S("abcde2fghij"));
3092     test(S("abcdefghij"), 5, 0, SV("1234567890"), 1, 4, S("abcde2345fghij"));
3093     test(S("abcdefghij"), 5, 0, SV("1234567890"), 1, 8, S("abcde23456789fghij"));
3094     test(S("abcdefghij"), 5, 0, SV("1234567890"), 1, 9, S("abcde234567890fghij"));
3095     test(S("abcdefghij"), 5, 0, SV("1234567890"), 1, 10, S("abcde234567890fghij"));
3096     test(S("abcdefghij"), 5, 0, SV("1234567890"), 5, 0, S("abcdefghij"));
3097     test(S("abcdefghij"), 5, 0, SV("1234567890"), 5, 1, S("abcde6fghij"));
3098     test(S("abcdefghij"), 5, 0, SV("1234567890"), 5, 2, S("abcde67fghij"));
3099     test(S("abcdefghij"), 5, 0, SV("1234567890"), 5, 4, S("abcde6789fghij"));
3100     test(S("abcdefghij"), 5, 0, SV("1234567890"), 5, 5, S("abcde67890fghij"));
3101     test(S("abcdefghij"), 5, 0, SV("1234567890"), 5, 6, S("abcde67890fghij"));
3102     test(S("abcdefghij"), 5, 0, SV("1234567890"), 9, 0, S("abcdefghij"));
3103     test(S("abcdefghij"), 5, 0, SV("1234567890"), 9, 1, S("abcde0fghij"));
3104     test(S("abcdefghij"), 5, 0, SV("1234567890"), 9, 2, S("abcde0fghij"));
3105     test(S("abcdefghij"), 5, 0, SV("1234567890"), 10, 0, S("abcdefghij"));
3106     test(S("abcdefghij"), 5, 0, SV("1234567890"), 10, 1, S("abcdefghij"));
3107     test(S("abcdefghij"), 5, 0, SV("1234567890"), 11, 0, S("can't happen"));
3108     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
3109     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 0, 1, S("abcde1fghij"));
3110     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 0, 10, S("abcde1234567890fghij"));
3111     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789fghij"));
3112     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890fghij"));
3113     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890fghij"));
3114     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
3115     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 1, 1, S("abcde2fghij"));
3116     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 1, 9, S("abcde234567890fghij"));
3117     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789fghij"));
3118     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890fghij"));
3119     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890fghij"));
3120     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
3121     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 10, 1, S("abcde1fghij"));
3122     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 10, 5, S("abcde12345fghij"));
3123     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 10, 9, S("abcde123456789fghij"));
3124     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 10, 10, S("abcde1234567890fghij"));
3125     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 10, 11, S("abcde1234567890fghij"));
3126     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
3127     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 19, 1, S("abcde0fghij"));
3128     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 19, 2, S("abcde0fghij"));
3129     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
3130     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
3131     test(S("abcdefghij"), 5, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
3132     test(S("abcdefghij"), 5, 1, SV(""), 0, 0, S("abcdeghij"));
3133     test(S("abcdefghij"), 5, 1, SV(""), 0, 1, S("abcdeghij"));
3134     test(S("abcdefghij"), 5, 1, SV(""), 1, 0, S("can't happen"));
3135     test(S("abcdefghij"), 5, 1, SV("12345"), 0, 0, S("abcdeghij"));
3136     test(S("abcdefghij"), 5, 1, SV("12345"), 0, 1, S("abcde1ghij"));
3137     test(S("abcdefghij"), 5, 1, SV("12345"), 0, 2, S("abcde12ghij"));
3138     test(S("abcdefghij"), 5, 1, SV("12345"), 0, 4, S("abcde1234ghij"));
3139     test(S("abcdefghij"), 5, 1, SV("12345"), 0, 5, S("abcde12345ghij"));
3140     test(S("abcdefghij"), 5, 1, SV("12345"), 0, 6, S("abcde12345ghij"));
3141     test(S("abcdefghij"), 5, 1, SV("12345"), 1, 0, S("abcdeghij"));
3142     test(S("abcdefghij"), 5, 1, SV("12345"), 1, 1, S("abcde2ghij"));
3143     test(S("abcdefghij"), 5, 1, SV("12345"), 1, 2, S("abcde23ghij"));
3144     test(S("abcdefghij"), 5, 1, SV("12345"), 1, 3, S("abcde234ghij"));
3145     test(S("abcdefghij"), 5, 1, SV("12345"), 1, 4, S("abcde2345ghij"));
3146 }
3147 
3148 template <class S, class SV>
test29()3149 void test29()
3150 {
3151     test(S("abcdefghij"), 5, 1, SV("12345"), 1, 5, S("abcde2345ghij"));
3152     test(S("abcdefghij"), 5, 1, SV("12345"), 2, 0, S("abcdeghij"));
3153     test(S("abcdefghij"), 5, 1, SV("12345"), 2, 1, S("abcde3ghij"));
3154     test(S("abcdefghij"), 5, 1, SV("12345"), 2, 2, S("abcde34ghij"));
3155     test(S("abcdefghij"), 5, 1, SV("12345"), 2, 3, S("abcde345ghij"));
3156     test(S("abcdefghij"), 5, 1, SV("12345"), 2, 4, S("abcde345ghij"));
3157     test(S("abcdefghij"), 5, 1, SV("12345"), 4, 0, S("abcdeghij"));
3158     test(S("abcdefghij"), 5, 1, SV("12345"), 4, 1, S("abcde5ghij"));
3159     test(S("abcdefghij"), 5, 1, SV("12345"), 4, 2, S("abcde5ghij"));
3160     test(S("abcdefghij"), 5, 1, SV("12345"), 5, 0, S("abcdeghij"));
3161     test(S("abcdefghij"), 5, 1, SV("12345"), 5, 1, S("abcdeghij"));
3162     test(S("abcdefghij"), 5, 1, SV("12345"), 6, 0, S("can't happen"));
3163     test(S("abcdefghij"), 5, 1, SV("1234567890"), 0, 0, S("abcdeghij"));
3164     test(S("abcdefghij"), 5, 1, SV("1234567890"), 0, 1, S("abcde1ghij"));
3165     test(S("abcdefghij"), 5, 1, SV("1234567890"), 0, 5, S("abcde12345ghij"));
3166     test(S("abcdefghij"), 5, 1, SV("1234567890"), 0, 9, S("abcde123456789ghij"));
3167     test(S("abcdefghij"), 5, 1, SV("1234567890"), 0, 10, S("abcde1234567890ghij"));
3168     test(S("abcdefghij"), 5, 1, SV("1234567890"), 0, 11, S("abcde1234567890ghij"));
3169     test(S("abcdefghij"), 5, 1, SV("1234567890"), 1, 0, S("abcdeghij"));
3170     test(S("abcdefghij"), 5, 1, SV("1234567890"), 1, 1, S("abcde2ghij"));
3171     test(S("abcdefghij"), 5, 1, SV("1234567890"), 1, 4, S("abcde2345ghij"));
3172     test(S("abcdefghij"), 5, 1, SV("1234567890"), 1, 8, S("abcde23456789ghij"));
3173     test(S("abcdefghij"), 5, 1, SV("1234567890"), 1, 9, S("abcde234567890ghij"));
3174     test(S("abcdefghij"), 5, 1, SV("1234567890"), 1, 10, S("abcde234567890ghij"));
3175     test(S("abcdefghij"), 5, 1, SV("1234567890"), 5, 0, S("abcdeghij"));
3176     test(S("abcdefghij"), 5, 1, SV("1234567890"), 5, 1, S("abcde6ghij"));
3177     test(S("abcdefghij"), 5, 1, SV("1234567890"), 5, 2, S("abcde67ghij"));
3178     test(S("abcdefghij"), 5, 1, SV("1234567890"), 5, 4, S("abcde6789ghij"));
3179     test(S("abcdefghij"), 5, 1, SV("1234567890"), 5, 5, S("abcde67890ghij"));
3180     test(S("abcdefghij"), 5, 1, SV("1234567890"), 5, 6, S("abcde67890ghij"));
3181     test(S("abcdefghij"), 5, 1, SV("1234567890"), 9, 0, S("abcdeghij"));
3182     test(S("abcdefghij"), 5, 1, SV("1234567890"), 9, 1, S("abcde0ghij"));
3183     test(S("abcdefghij"), 5, 1, SV("1234567890"), 9, 2, S("abcde0ghij"));
3184     test(S("abcdefghij"), 5, 1, SV("1234567890"), 10, 0, S("abcdeghij"));
3185     test(S("abcdefghij"), 5, 1, SV("1234567890"), 10, 1, S("abcdeghij"));
3186     test(S("abcdefghij"), 5, 1, SV("1234567890"), 11, 0, S("can't happen"));
3187     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 0, 0, S("abcdeghij"));
3188     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 0, 1, S("abcde1ghij"));
3189     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 0, 10, S("abcde1234567890ghij"));
3190     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789ghij"));
3191     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890ghij"));
3192     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890ghij"));
3193     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 1, 0, S("abcdeghij"));
3194     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 1, 1, S("abcde2ghij"));
3195     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 1, 9, S("abcde234567890ghij"));
3196     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789ghij"));
3197     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890ghij"));
3198     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890ghij"));
3199     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 10, 0, S("abcdeghij"));
3200     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 10, 1, S("abcde1ghij"));
3201     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 10, 5, S("abcde12345ghij"));
3202     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 10, 9, S("abcde123456789ghij"));
3203     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 10, 10, S("abcde1234567890ghij"));
3204     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 10, 11, S("abcde1234567890ghij"));
3205     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 19, 0, S("abcdeghij"));
3206     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 19, 1, S("abcde0ghij"));
3207     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 19, 2, S("abcde0ghij"));
3208     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 20, 0, S("abcdeghij"));
3209     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 20, 1, S("abcdeghij"));
3210     test(S("abcdefghij"), 5, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
3211     test(S("abcdefghij"), 5, 2, SV(""), 0, 0, S("abcdehij"));
3212     test(S("abcdefghij"), 5, 2, SV(""), 0, 1, S("abcdehij"));
3213     test(S("abcdefghij"), 5, 2, SV(""), 1, 0, S("can't happen"));
3214     test(S("abcdefghij"), 5, 2, SV("12345"), 0, 0, S("abcdehij"));
3215     test(S("abcdefghij"), 5, 2, SV("12345"), 0, 1, S("abcde1hij"));
3216     test(S("abcdefghij"), 5, 2, SV("12345"), 0, 2, S("abcde12hij"));
3217     test(S("abcdefghij"), 5, 2, SV("12345"), 0, 4, S("abcde1234hij"));
3218     test(S("abcdefghij"), 5, 2, SV("12345"), 0, 5, S("abcde12345hij"));
3219     test(S("abcdefghij"), 5, 2, SV("12345"), 0, 6, S("abcde12345hij"));
3220     test(S("abcdefghij"), 5, 2, SV("12345"), 1, 0, S("abcdehij"));
3221     test(S("abcdefghij"), 5, 2, SV("12345"), 1, 1, S("abcde2hij"));
3222     test(S("abcdefghij"), 5, 2, SV("12345"), 1, 2, S("abcde23hij"));
3223     test(S("abcdefghij"), 5, 2, SV("12345"), 1, 3, S("abcde234hij"));
3224     test(S("abcdefghij"), 5, 2, SV("12345"), 1, 4, S("abcde2345hij"));
3225     test(S("abcdefghij"), 5, 2, SV("12345"), 1, 5, S("abcde2345hij"));
3226     test(S("abcdefghij"), 5, 2, SV("12345"), 2, 0, S("abcdehij"));
3227     test(S("abcdefghij"), 5, 2, SV("12345"), 2, 1, S("abcde3hij"));
3228     test(S("abcdefghij"), 5, 2, SV("12345"), 2, 2, S("abcde34hij"));
3229     test(S("abcdefghij"), 5, 2, SV("12345"), 2, 3, S("abcde345hij"));
3230     test(S("abcdefghij"), 5, 2, SV("12345"), 2, 4, S("abcde345hij"));
3231     test(S("abcdefghij"), 5, 2, SV("12345"), 4, 0, S("abcdehij"));
3232     test(S("abcdefghij"), 5, 2, SV("12345"), 4, 1, S("abcde5hij"));
3233     test(S("abcdefghij"), 5, 2, SV("12345"), 4, 2, S("abcde5hij"));
3234     test(S("abcdefghij"), 5, 2, SV("12345"), 5, 0, S("abcdehij"));
3235     test(S("abcdefghij"), 5, 2, SV("12345"), 5, 1, S("abcdehij"));
3236     test(S("abcdefghij"), 5, 2, SV("12345"), 6, 0, S("can't happen"));
3237     test(S("abcdefghij"), 5, 2, SV("1234567890"), 0, 0, S("abcdehij"));
3238     test(S("abcdefghij"), 5, 2, SV("1234567890"), 0, 1, S("abcde1hij"));
3239     test(S("abcdefghij"), 5, 2, SV("1234567890"), 0, 5, S("abcde12345hij"));
3240     test(S("abcdefghij"), 5, 2, SV("1234567890"), 0, 9, S("abcde123456789hij"));
3241     test(S("abcdefghij"), 5, 2, SV("1234567890"), 0, 10, S("abcde1234567890hij"));
3242     test(S("abcdefghij"), 5, 2, SV("1234567890"), 0, 11, S("abcde1234567890hij"));
3243     test(S("abcdefghij"), 5, 2, SV("1234567890"), 1, 0, S("abcdehij"));
3244     test(S("abcdefghij"), 5, 2, SV("1234567890"), 1, 1, S("abcde2hij"));
3245     test(S("abcdefghij"), 5, 2, SV("1234567890"), 1, 4, S("abcde2345hij"));
3246     test(S("abcdefghij"), 5, 2, SV("1234567890"), 1, 8, S("abcde23456789hij"));
3247     test(S("abcdefghij"), 5, 2, SV("1234567890"), 1, 9, S("abcde234567890hij"));
3248     test(S("abcdefghij"), 5, 2, SV("1234567890"), 1, 10, S("abcde234567890hij"));
3249     test(S("abcdefghij"), 5, 2, SV("1234567890"), 5, 0, S("abcdehij"));
3250     test(S("abcdefghij"), 5, 2, SV("1234567890"), 5, 1, S("abcde6hij"));
3251 }
3252 
3253 template <class S, class SV>
test30()3254 void test30()
3255 {
3256     test(S("abcdefghij"), 5, 2, SV("1234567890"), 5, 2, S("abcde67hij"));
3257     test(S("abcdefghij"), 5, 2, SV("1234567890"), 5, 4, S("abcde6789hij"));
3258     test(S("abcdefghij"), 5, 2, SV("1234567890"), 5, 5, S("abcde67890hij"));
3259     test(S("abcdefghij"), 5, 2, SV("1234567890"), 5, 6, S("abcde67890hij"));
3260     test(S("abcdefghij"), 5, 2, SV("1234567890"), 9, 0, S("abcdehij"));
3261     test(S("abcdefghij"), 5, 2, SV("1234567890"), 9, 1, S("abcde0hij"));
3262     test(S("abcdefghij"), 5, 2, SV("1234567890"), 9, 2, S("abcde0hij"));
3263     test(S("abcdefghij"), 5, 2, SV("1234567890"), 10, 0, S("abcdehij"));
3264     test(S("abcdefghij"), 5, 2, SV("1234567890"), 10, 1, S("abcdehij"));
3265     test(S("abcdefghij"), 5, 2, SV("1234567890"), 11, 0, S("can't happen"));
3266     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 0, 0, S("abcdehij"));
3267     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 0, 1, S("abcde1hij"));
3268     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 0, 10, S("abcde1234567890hij"));
3269     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789hij"));
3270     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890hij"));
3271     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890hij"));
3272     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 1, 0, S("abcdehij"));
3273     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 1, 1, S("abcde2hij"));
3274     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 1, 9, S("abcde234567890hij"));
3275     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789hij"));
3276     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890hij"));
3277     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890hij"));
3278     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 10, 0, S("abcdehij"));
3279     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 10, 1, S("abcde1hij"));
3280     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 10, 5, S("abcde12345hij"));
3281     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 10, 9, S("abcde123456789hij"));
3282     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 10, 10, S("abcde1234567890hij"));
3283     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 10, 11, S("abcde1234567890hij"));
3284     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 19, 0, S("abcdehij"));
3285     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 19, 1, S("abcde0hij"));
3286     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 19, 2, S("abcde0hij"));
3287     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 20, 0, S("abcdehij"));
3288     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 20, 1, S("abcdehij"));
3289     test(S("abcdefghij"), 5, 2, SV("12345678901234567890"), 21, 0, S("can't happen"));
3290     test(S("abcdefghij"), 5, 4, SV(""), 0, 0, S("abcdej"));
3291     test(S("abcdefghij"), 5, 4, SV(""), 0, 1, S("abcdej"));
3292     test(S("abcdefghij"), 5, 4, SV(""), 1, 0, S("can't happen"));
3293     test(S("abcdefghij"), 5, 4, SV("12345"), 0, 0, S("abcdej"));
3294     test(S("abcdefghij"), 5, 4, SV("12345"), 0, 1, S("abcde1j"));
3295     test(S("abcdefghij"), 5, 4, SV("12345"), 0, 2, S("abcde12j"));
3296     test(S("abcdefghij"), 5, 4, SV("12345"), 0, 4, S("abcde1234j"));
3297     test(S("abcdefghij"), 5, 4, SV("12345"), 0, 5, S("abcde12345j"));
3298     test(S("abcdefghij"), 5, 4, SV("12345"), 0, 6, S("abcde12345j"));
3299     test(S("abcdefghij"), 5, 4, SV("12345"), 1, 0, S("abcdej"));
3300     test(S("abcdefghij"), 5, 4, SV("12345"), 1, 1, S("abcde2j"));
3301     test(S("abcdefghij"), 5, 4, SV("12345"), 1, 2, S("abcde23j"));
3302     test(S("abcdefghij"), 5, 4, SV("12345"), 1, 3, S("abcde234j"));
3303     test(S("abcdefghij"), 5, 4, SV("12345"), 1, 4, S("abcde2345j"));
3304     test(S("abcdefghij"), 5, 4, SV("12345"), 1, 5, S("abcde2345j"));
3305     test(S("abcdefghij"), 5, 4, SV("12345"), 2, 0, S("abcdej"));
3306     test(S("abcdefghij"), 5, 4, SV("12345"), 2, 1, S("abcde3j"));
3307     test(S("abcdefghij"), 5, 4, SV("12345"), 2, 2, S("abcde34j"));
3308     test(S("abcdefghij"), 5, 4, SV("12345"), 2, 3, S("abcde345j"));
3309     test(S("abcdefghij"), 5, 4, SV("12345"), 2, 4, S("abcde345j"));
3310     test(S("abcdefghij"), 5, 4, SV("12345"), 4, 0, S("abcdej"));
3311     test(S("abcdefghij"), 5, 4, SV("12345"), 4, 1, S("abcde5j"));
3312     test(S("abcdefghij"), 5, 4, SV("12345"), 4, 2, S("abcde5j"));
3313     test(S("abcdefghij"), 5, 4, SV("12345"), 5, 0, S("abcdej"));
3314     test(S("abcdefghij"), 5, 4, SV("12345"), 5, 1, S("abcdej"));
3315     test(S("abcdefghij"), 5, 4, SV("12345"), 6, 0, S("can't happen"));
3316     test(S("abcdefghij"), 5, 4, SV("1234567890"), 0, 0, S("abcdej"));
3317     test(S("abcdefghij"), 5, 4, SV("1234567890"), 0, 1, S("abcde1j"));
3318     test(S("abcdefghij"), 5, 4, SV("1234567890"), 0, 5, S("abcde12345j"));
3319     test(S("abcdefghij"), 5, 4, SV("1234567890"), 0, 9, S("abcde123456789j"));
3320     test(S("abcdefghij"), 5, 4, SV("1234567890"), 0, 10, S("abcde1234567890j"));
3321     test(S("abcdefghij"), 5, 4, SV("1234567890"), 0, 11, S("abcde1234567890j"));
3322     test(S("abcdefghij"), 5, 4, SV("1234567890"), 1, 0, S("abcdej"));
3323     test(S("abcdefghij"), 5, 4, SV("1234567890"), 1, 1, S("abcde2j"));
3324     test(S("abcdefghij"), 5, 4, SV("1234567890"), 1, 4, S("abcde2345j"));
3325     test(S("abcdefghij"), 5, 4, SV("1234567890"), 1, 8, S("abcde23456789j"));
3326     test(S("abcdefghij"), 5, 4, SV("1234567890"), 1, 9, S("abcde234567890j"));
3327     test(S("abcdefghij"), 5, 4, SV("1234567890"), 1, 10, S("abcde234567890j"));
3328     test(S("abcdefghij"), 5, 4, SV("1234567890"), 5, 0, S("abcdej"));
3329     test(S("abcdefghij"), 5, 4, SV("1234567890"), 5, 1, S("abcde6j"));
3330     test(S("abcdefghij"), 5, 4, SV("1234567890"), 5, 2, S("abcde67j"));
3331     test(S("abcdefghij"), 5, 4, SV("1234567890"), 5, 4, S("abcde6789j"));
3332     test(S("abcdefghij"), 5, 4, SV("1234567890"), 5, 5, S("abcde67890j"));
3333     test(S("abcdefghij"), 5, 4, SV("1234567890"), 5, 6, S("abcde67890j"));
3334     test(S("abcdefghij"), 5, 4, SV("1234567890"), 9, 0, S("abcdej"));
3335     test(S("abcdefghij"), 5, 4, SV("1234567890"), 9, 1, S("abcde0j"));
3336     test(S("abcdefghij"), 5, 4, SV("1234567890"), 9, 2, S("abcde0j"));
3337     test(S("abcdefghij"), 5, 4, SV("1234567890"), 10, 0, S("abcdej"));
3338     test(S("abcdefghij"), 5, 4, SV("1234567890"), 10, 1, S("abcdej"));
3339     test(S("abcdefghij"), 5, 4, SV("1234567890"), 11, 0, S("can't happen"));
3340     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 0, 0, S("abcdej"));
3341     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 0, 1, S("abcde1j"));
3342     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 0, 10, S("abcde1234567890j"));
3343     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789j"));
3344     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890j"));
3345     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890j"));
3346     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 1, 0, S("abcdej"));
3347     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 1, 1, S("abcde2j"));
3348     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 1, 9, S("abcde234567890j"));
3349     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789j"));
3350     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890j"));
3351     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890j"));
3352     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 10, 0, S("abcdej"));
3353     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 10, 1, S("abcde1j"));
3354     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 10, 5, S("abcde12345j"));
3355     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 10, 9, S("abcde123456789j"));
3356 }
3357 
3358 template <class S, class SV>
test31()3359 void test31()
3360 {
3361     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 10, 10, S("abcde1234567890j"));
3362     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 10, 11, S("abcde1234567890j"));
3363     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 19, 0, S("abcdej"));
3364     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 19, 1, S("abcde0j"));
3365     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 19, 2, S("abcde0j"));
3366     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 20, 0, S("abcdej"));
3367     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 20, 1, S("abcdej"));
3368     test(S("abcdefghij"), 5, 4, SV("12345678901234567890"), 21, 0, S("can't happen"));
3369     test(S("abcdefghij"), 5, 5, SV(""), 0, 0, S("abcde"));
3370     test(S("abcdefghij"), 5, 5, SV(""), 0, 1, S("abcde"));
3371     test(S("abcdefghij"), 5, 5, SV(""), 1, 0, S("can't happen"));
3372     test(S("abcdefghij"), 5, 5, SV("12345"), 0, 0, S("abcde"));
3373     test(S("abcdefghij"), 5, 5, SV("12345"), 0, 1, S("abcde1"));
3374     test(S("abcdefghij"), 5, 5, SV("12345"), 0, 2, S("abcde12"));
3375     test(S("abcdefghij"), 5, 5, SV("12345"), 0, 4, S("abcde1234"));
3376     test(S("abcdefghij"), 5, 5, SV("12345"), 0, 5, S("abcde12345"));
3377     test(S("abcdefghij"), 5, 5, SV("12345"), 0, 6, S("abcde12345"));
3378     test(S("abcdefghij"), 5, 5, SV("12345"), 1, 0, S("abcde"));
3379     test(S("abcdefghij"), 5, 5, SV("12345"), 1, 1, S("abcde2"));
3380     test(S("abcdefghij"), 5, 5, SV("12345"), 1, 2, S("abcde23"));
3381     test(S("abcdefghij"), 5, 5, SV("12345"), 1, 3, S("abcde234"));
3382     test(S("abcdefghij"), 5, 5, SV("12345"), 1, 4, S("abcde2345"));
3383     test(S("abcdefghij"), 5, 5, SV("12345"), 1, 5, S("abcde2345"));
3384     test(S("abcdefghij"), 5, 5, SV("12345"), 2, 0, S("abcde"));
3385     test(S("abcdefghij"), 5, 5, SV("12345"), 2, 1, S("abcde3"));
3386     test(S("abcdefghij"), 5, 5, SV("12345"), 2, 2, S("abcde34"));
3387     test(S("abcdefghij"), 5, 5, SV("12345"), 2, 3, S("abcde345"));
3388     test(S("abcdefghij"), 5, 5, SV("12345"), 2, 4, S("abcde345"));
3389     test(S("abcdefghij"), 5, 5, SV("12345"), 4, 0, S("abcde"));
3390     test(S("abcdefghij"), 5, 5, SV("12345"), 4, 1, S("abcde5"));
3391     test(S("abcdefghij"), 5, 5, SV("12345"), 4, 2, S("abcde5"));
3392     test(S("abcdefghij"), 5, 5, SV("12345"), 5, 0, S("abcde"));
3393     test(S("abcdefghij"), 5, 5, SV("12345"), 5, 1, S("abcde"));
3394     test(S("abcdefghij"), 5, 5, SV("12345"), 6, 0, S("can't happen"));
3395     test(S("abcdefghij"), 5, 5, SV("1234567890"), 0, 0, S("abcde"));
3396     test(S("abcdefghij"), 5, 5, SV("1234567890"), 0, 1, S("abcde1"));
3397     test(S("abcdefghij"), 5, 5, SV("1234567890"), 0, 5, S("abcde12345"));
3398     test(S("abcdefghij"), 5, 5, SV("1234567890"), 0, 9, S("abcde123456789"));
3399     test(S("abcdefghij"), 5, 5, SV("1234567890"), 0, 10, S("abcde1234567890"));
3400     test(S("abcdefghij"), 5, 5, SV("1234567890"), 0, 11, S("abcde1234567890"));
3401     test(S("abcdefghij"), 5, 5, SV("1234567890"), 1, 0, S("abcde"));
3402     test(S("abcdefghij"), 5, 5, SV("1234567890"), 1, 1, S("abcde2"));
3403     test(S("abcdefghij"), 5, 5, SV("1234567890"), 1, 4, S("abcde2345"));
3404     test(S("abcdefghij"), 5, 5, SV("1234567890"), 1, 8, S("abcde23456789"));
3405     test(S("abcdefghij"), 5, 5, SV("1234567890"), 1, 9, S("abcde234567890"));
3406     test(S("abcdefghij"), 5, 5, SV("1234567890"), 1, 10, S("abcde234567890"));
3407     test(S("abcdefghij"), 5, 5, SV("1234567890"), 5, 0, S("abcde"));
3408     test(S("abcdefghij"), 5, 5, SV("1234567890"), 5, 1, S("abcde6"));
3409     test(S("abcdefghij"), 5, 5, SV("1234567890"), 5, 2, S("abcde67"));
3410     test(S("abcdefghij"), 5, 5, SV("1234567890"), 5, 4, S("abcde6789"));
3411     test(S("abcdefghij"), 5, 5, SV("1234567890"), 5, 5, S("abcde67890"));
3412     test(S("abcdefghij"), 5, 5, SV("1234567890"), 5, 6, S("abcde67890"));
3413     test(S("abcdefghij"), 5, 5, SV("1234567890"), 9, 0, S("abcde"));
3414     test(S("abcdefghij"), 5, 5, SV("1234567890"), 9, 1, S("abcde0"));
3415     test(S("abcdefghij"), 5, 5, SV("1234567890"), 9, 2, S("abcde0"));
3416     test(S("abcdefghij"), 5, 5, SV("1234567890"), 10, 0, S("abcde"));
3417     test(S("abcdefghij"), 5, 5, SV("1234567890"), 10, 1, S("abcde"));
3418     test(S("abcdefghij"), 5, 5, SV("1234567890"), 11, 0, S("can't happen"));
3419     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 0, 0, S("abcde"));
3420     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 0, 1, S("abcde1"));
3421     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 0, 10, S("abcde1234567890"));
3422     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
3423     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
3424     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
3425     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 1, 0, S("abcde"));
3426     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 1, 1, S("abcde2"));
3427     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 1, 9, S("abcde234567890"));
3428     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
3429     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
3430     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
3431     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 10, 0, S("abcde"));
3432     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 10, 1, S("abcde1"));
3433     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 10, 5, S("abcde12345"));
3434     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 10, 9, S("abcde123456789"));
3435     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 10, 10, S("abcde1234567890"));
3436     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 10, 11, S("abcde1234567890"));
3437     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 19, 0, S("abcde"));
3438     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 19, 1, S("abcde0"));
3439     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 19, 2, S("abcde0"));
3440     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 20, 0, S("abcde"));
3441     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 20, 1, S("abcde"));
3442     test(S("abcdefghij"), 5, 5, SV("12345678901234567890"), 21, 0, S("can't happen"));
3443     test(S("abcdefghij"), 5, 6, SV(""), 0, 0, S("abcde"));
3444     test(S("abcdefghij"), 5, 6, SV(""), 0, 1, S("abcde"));
3445     test(S("abcdefghij"), 5, 6, SV(""), 1, 0, S("can't happen"));
3446     test(S("abcdefghij"), 5, 6, SV("12345"), 0, 0, S("abcde"));
3447     test(S("abcdefghij"), 5, 6, SV("12345"), 0, 1, S("abcde1"));
3448     test(S("abcdefghij"), 5, 6, SV("12345"), 0, 2, S("abcde12"));
3449     test(S("abcdefghij"), 5, 6, SV("12345"), 0, 4, S("abcde1234"));
3450     test(S("abcdefghij"), 5, 6, SV("12345"), 0, 5, S("abcde12345"));
3451     test(S("abcdefghij"), 5, 6, SV("12345"), 0, 6, S("abcde12345"));
3452     test(S("abcdefghij"), 5, 6, SV("12345"), 1, 0, S("abcde"));
3453     test(S("abcdefghij"), 5, 6, SV("12345"), 1, 1, S("abcde2"));
3454     test(S("abcdefghij"), 5, 6, SV("12345"), 1, 2, S("abcde23"));
3455     test(S("abcdefghij"), 5, 6, SV("12345"), 1, 3, S("abcde234"));
3456     test(S("abcdefghij"), 5, 6, SV("12345"), 1, 4, S("abcde2345"));
3457     test(S("abcdefghij"), 5, 6, SV("12345"), 1, 5, S("abcde2345"));
3458     test(S("abcdefghij"), 5, 6, SV("12345"), 2, 0, S("abcde"));
3459     test(S("abcdefghij"), 5, 6, SV("12345"), 2, 1, S("abcde3"));
3460     test(S("abcdefghij"), 5, 6, SV("12345"), 2, 2, S("abcde34"));
3461 }
3462 
3463 template <class S, class SV>
test32()3464 void test32()
3465 {
3466     test(S("abcdefghij"), 5, 6, SV("12345"), 2, 3, S("abcde345"));
3467     test(S("abcdefghij"), 5, 6, SV("12345"), 2, 4, S("abcde345"));
3468     test(S("abcdefghij"), 5, 6, SV("12345"), 4, 0, S("abcde"));
3469     test(S("abcdefghij"), 5, 6, SV("12345"), 4, 1, S("abcde5"));
3470     test(S("abcdefghij"), 5, 6, SV("12345"), 4, 2, S("abcde5"));
3471     test(S("abcdefghij"), 5, 6, SV("12345"), 5, 0, S("abcde"));
3472     test(S("abcdefghij"), 5, 6, SV("12345"), 5, 1, S("abcde"));
3473     test(S("abcdefghij"), 5, 6, SV("12345"), 6, 0, S("can't happen"));
3474     test(S("abcdefghij"), 5, 6, SV("1234567890"), 0, 0, S("abcde"));
3475     test(S("abcdefghij"), 5, 6, SV("1234567890"), 0, 1, S("abcde1"));
3476     test(S("abcdefghij"), 5, 6, SV("1234567890"), 0, 5, S("abcde12345"));
3477     test(S("abcdefghij"), 5, 6, SV("1234567890"), 0, 9, S("abcde123456789"));
3478     test(S("abcdefghij"), 5, 6, SV("1234567890"), 0, 10, S("abcde1234567890"));
3479     test(S("abcdefghij"), 5, 6, SV("1234567890"), 0, 11, S("abcde1234567890"));
3480     test(S("abcdefghij"), 5, 6, SV("1234567890"), 1, 0, S("abcde"));
3481     test(S("abcdefghij"), 5, 6, SV("1234567890"), 1, 1, S("abcde2"));
3482     test(S("abcdefghij"), 5, 6, SV("1234567890"), 1, 4, S("abcde2345"));
3483     test(S("abcdefghij"), 5, 6, SV("1234567890"), 1, 8, S("abcde23456789"));
3484     test(S("abcdefghij"), 5, 6, SV("1234567890"), 1, 9, S("abcde234567890"));
3485     test(S("abcdefghij"), 5, 6, SV("1234567890"), 1, 10, S("abcde234567890"));
3486     test(S("abcdefghij"), 5, 6, SV("1234567890"), 5, 0, S("abcde"));
3487     test(S("abcdefghij"), 5, 6, SV("1234567890"), 5, 1, S("abcde6"));
3488     test(S("abcdefghij"), 5, 6, SV("1234567890"), 5, 2, S("abcde67"));
3489     test(S("abcdefghij"), 5, 6, SV("1234567890"), 5, 4, S("abcde6789"));
3490     test(S("abcdefghij"), 5, 6, SV("1234567890"), 5, 5, S("abcde67890"));
3491     test(S("abcdefghij"), 5, 6, SV("1234567890"), 5, 6, S("abcde67890"));
3492     test(S("abcdefghij"), 5, 6, SV("1234567890"), 9, 0, S("abcde"));
3493     test(S("abcdefghij"), 5, 6, SV("1234567890"), 9, 1, S("abcde0"));
3494     test(S("abcdefghij"), 5, 6, SV("1234567890"), 9, 2, S("abcde0"));
3495     test(S("abcdefghij"), 5, 6, SV("1234567890"), 10, 0, S("abcde"));
3496     test(S("abcdefghij"), 5, 6, SV("1234567890"), 10, 1, S("abcde"));
3497     test(S("abcdefghij"), 5, 6, SV("1234567890"), 11, 0, S("can't happen"));
3498     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 0, 0, S("abcde"));
3499     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 0, 1, S("abcde1"));
3500     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 0, 10, S("abcde1234567890"));
3501     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
3502     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
3503     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
3504     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 1, 0, S("abcde"));
3505     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 1, 1, S("abcde2"));
3506     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 1, 9, S("abcde234567890"));
3507     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
3508     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
3509     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
3510     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 10, 0, S("abcde"));
3511     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 10, 1, S("abcde1"));
3512     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 10, 5, S("abcde12345"));
3513     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 10, 9, S("abcde123456789"));
3514     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 10, 10, S("abcde1234567890"));
3515     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 10, 11, S("abcde1234567890"));
3516     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 19, 0, S("abcde"));
3517     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 19, 1, S("abcde0"));
3518     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 19, 2, S("abcde0"));
3519     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 20, 0, S("abcde"));
3520     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 20, 1, S("abcde"));
3521     test(S("abcdefghij"), 5, 6, SV("12345678901234567890"), 21, 0, S("can't happen"));
3522     test(S("abcdefghij"), 9, 0, SV(""), 0, 0, S("abcdefghij"));
3523     test(S("abcdefghij"), 9, 0, SV(""), 0, 1, S("abcdefghij"));
3524     test(S("abcdefghij"), 9, 0, SV(""), 1, 0, S("can't happen"));
3525     test(S("abcdefghij"), 9, 0, SV("12345"), 0, 0, S("abcdefghij"));
3526     test(S("abcdefghij"), 9, 0, SV("12345"), 0, 1, S("abcdefghi1j"));
3527     test(S("abcdefghij"), 9, 0, SV("12345"), 0, 2, S("abcdefghi12j"));
3528     test(S("abcdefghij"), 9, 0, SV("12345"), 0, 4, S("abcdefghi1234j"));
3529     test(S("abcdefghij"), 9, 0, SV("12345"), 0, 5, S("abcdefghi12345j"));
3530     test(S("abcdefghij"), 9, 0, SV("12345"), 0, 6, S("abcdefghi12345j"));
3531     test(S("abcdefghij"), 9, 0, SV("12345"), 1, 0, S("abcdefghij"));
3532     test(S("abcdefghij"), 9, 0, SV("12345"), 1, 1, S("abcdefghi2j"));
3533     test(S("abcdefghij"), 9, 0, SV("12345"), 1, 2, S("abcdefghi23j"));
3534     test(S("abcdefghij"), 9, 0, SV("12345"), 1, 3, S("abcdefghi234j"));
3535     test(S("abcdefghij"), 9, 0, SV("12345"), 1, 4, S("abcdefghi2345j"));
3536     test(S("abcdefghij"), 9, 0, SV("12345"), 1, 5, S("abcdefghi2345j"));
3537     test(S("abcdefghij"), 9, 0, SV("12345"), 2, 0, S("abcdefghij"));
3538     test(S("abcdefghij"), 9, 0, SV("12345"), 2, 1, S("abcdefghi3j"));
3539     test(S("abcdefghij"), 9, 0, SV("12345"), 2, 2, S("abcdefghi34j"));
3540     test(S("abcdefghij"), 9, 0, SV("12345"), 2, 3, S("abcdefghi345j"));
3541     test(S("abcdefghij"), 9, 0, SV("12345"), 2, 4, S("abcdefghi345j"));
3542     test(S("abcdefghij"), 9, 0, SV("12345"), 4, 0, S("abcdefghij"));
3543     test(S("abcdefghij"), 9, 0, SV("12345"), 4, 1, S("abcdefghi5j"));
3544     test(S("abcdefghij"), 9, 0, SV("12345"), 4, 2, S("abcdefghi5j"));
3545     test(S("abcdefghij"), 9, 0, SV("12345"), 5, 0, S("abcdefghij"));
3546     test(S("abcdefghij"), 9, 0, SV("12345"), 5, 1, S("abcdefghij"));
3547     test(S("abcdefghij"), 9, 0, SV("12345"), 6, 0, S("can't happen"));
3548     test(S("abcdefghij"), 9, 0, SV("1234567890"), 0, 0, S("abcdefghij"));
3549     test(S("abcdefghij"), 9, 0, SV("1234567890"), 0, 1, S("abcdefghi1j"));
3550     test(S("abcdefghij"), 9, 0, SV("1234567890"), 0, 5, S("abcdefghi12345j"));
3551     test(S("abcdefghij"), 9, 0, SV("1234567890"), 0, 9, S("abcdefghi123456789j"));
3552     test(S("abcdefghij"), 9, 0, SV("1234567890"), 0, 10, S("abcdefghi1234567890j"));
3553     test(S("abcdefghij"), 9, 0, SV("1234567890"), 0, 11, S("abcdefghi1234567890j"));
3554     test(S("abcdefghij"), 9, 0, SV("1234567890"), 1, 0, S("abcdefghij"));
3555     test(S("abcdefghij"), 9, 0, SV("1234567890"), 1, 1, S("abcdefghi2j"));
3556     test(S("abcdefghij"), 9, 0, SV("1234567890"), 1, 4, S("abcdefghi2345j"));
3557     test(S("abcdefghij"), 9, 0, SV("1234567890"), 1, 8, S("abcdefghi23456789j"));
3558     test(S("abcdefghij"), 9, 0, SV("1234567890"), 1, 9, S("abcdefghi234567890j"));
3559     test(S("abcdefghij"), 9, 0, SV("1234567890"), 1, 10, S("abcdefghi234567890j"));
3560     test(S("abcdefghij"), 9, 0, SV("1234567890"), 5, 0, S("abcdefghij"));
3561     test(S("abcdefghij"), 9, 0, SV("1234567890"), 5, 1, S("abcdefghi6j"));
3562     test(S("abcdefghij"), 9, 0, SV("1234567890"), 5, 2, S("abcdefghi67j"));
3563     test(S("abcdefghij"), 9, 0, SV("1234567890"), 5, 4, S("abcdefghi6789j"));
3564     test(S("abcdefghij"), 9, 0, SV("1234567890"), 5, 5, S("abcdefghi67890j"));
3565     test(S("abcdefghij"), 9, 0, SV("1234567890"), 5, 6, S("abcdefghi67890j"));
3566 }
3567 
3568 template <class S, class SV>
test33()3569 void test33()
3570 {
3571     test(S("abcdefghij"), 9, 0, SV("1234567890"), 9, 0, S("abcdefghij"));
3572     test(S("abcdefghij"), 9, 0, SV("1234567890"), 9, 1, S("abcdefghi0j"));
3573     test(S("abcdefghij"), 9, 0, SV("1234567890"), 9, 2, S("abcdefghi0j"));
3574     test(S("abcdefghij"), 9, 0, SV("1234567890"), 10, 0, S("abcdefghij"));
3575     test(S("abcdefghij"), 9, 0, SV("1234567890"), 10, 1, S("abcdefghij"));
3576     test(S("abcdefghij"), 9, 0, SV("1234567890"), 11, 0, S("can't happen"));
3577     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
3578     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 0, 1, S("abcdefghi1j"));
3579     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 0, 10, S("abcdefghi1234567890j"));
3580     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789j"));
3581     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890j"));
3582     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890j"));
3583     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
3584     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 1, 1, S("abcdefghi2j"));
3585     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 1, 9, S("abcdefghi234567890j"));
3586     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789j"));
3587     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890j"));
3588     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890j"));
3589     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
3590     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 10, 1, S("abcdefghi1j"));
3591     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 10, 5, S("abcdefghi12345j"));
3592     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 10, 9, S("abcdefghi123456789j"));
3593     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 10, 10, S("abcdefghi1234567890j"));
3594     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 10, 11, S("abcdefghi1234567890j"));
3595     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
3596     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 19, 1, S("abcdefghi0j"));
3597     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 19, 2, S("abcdefghi0j"));
3598     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
3599     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
3600     test(S("abcdefghij"), 9, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
3601     test(S("abcdefghij"), 9, 1, SV(""), 0, 0, S("abcdefghi"));
3602     test(S("abcdefghij"), 9, 1, SV(""), 0, 1, S("abcdefghi"));
3603     test(S("abcdefghij"), 9, 1, SV(""), 1, 0, S("can't happen"));
3604     test(S("abcdefghij"), 9, 1, SV("12345"), 0, 0, S("abcdefghi"));
3605     test(S("abcdefghij"), 9, 1, SV("12345"), 0, 1, S("abcdefghi1"));
3606     test(S("abcdefghij"), 9, 1, SV("12345"), 0, 2, S("abcdefghi12"));
3607     test(S("abcdefghij"), 9, 1, SV("12345"), 0, 4, S("abcdefghi1234"));
3608     test(S("abcdefghij"), 9, 1, SV("12345"), 0, 5, S("abcdefghi12345"));
3609     test(S("abcdefghij"), 9, 1, SV("12345"), 0, 6, S("abcdefghi12345"));
3610     test(S("abcdefghij"), 9, 1, SV("12345"), 1, 0, S("abcdefghi"));
3611     test(S("abcdefghij"), 9, 1, SV("12345"), 1, 1, S("abcdefghi2"));
3612     test(S("abcdefghij"), 9, 1, SV("12345"), 1, 2, S("abcdefghi23"));
3613     test(S("abcdefghij"), 9, 1, SV("12345"), 1, 3, S("abcdefghi234"));
3614     test(S("abcdefghij"), 9, 1, SV("12345"), 1, 4, S("abcdefghi2345"));
3615     test(S("abcdefghij"), 9, 1, SV("12345"), 1, 5, S("abcdefghi2345"));
3616     test(S("abcdefghij"), 9, 1, SV("12345"), 2, 0, S("abcdefghi"));
3617     test(S("abcdefghij"), 9, 1, SV("12345"), 2, 1, S("abcdefghi3"));
3618     test(S("abcdefghij"), 9, 1, SV("12345"), 2, 2, S("abcdefghi34"));
3619     test(S("abcdefghij"), 9, 1, SV("12345"), 2, 3, S("abcdefghi345"));
3620     test(S("abcdefghij"), 9, 1, SV("12345"), 2, 4, S("abcdefghi345"));
3621     test(S("abcdefghij"), 9, 1, SV("12345"), 4, 0, S("abcdefghi"));
3622     test(S("abcdefghij"), 9, 1, SV("12345"), 4, 1, S("abcdefghi5"));
3623     test(S("abcdefghij"), 9, 1, SV("12345"), 4, 2, S("abcdefghi5"));
3624     test(S("abcdefghij"), 9, 1, SV("12345"), 5, 0, S("abcdefghi"));
3625     test(S("abcdefghij"), 9, 1, SV("12345"), 5, 1, S("abcdefghi"));
3626     test(S("abcdefghij"), 9, 1, SV("12345"), 6, 0, S("can't happen"));
3627     test(S("abcdefghij"), 9, 1, SV("1234567890"), 0, 0, S("abcdefghi"));
3628     test(S("abcdefghij"), 9, 1, SV("1234567890"), 0, 1, S("abcdefghi1"));
3629     test(S("abcdefghij"), 9, 1, SV("1234567890"), 0, 5, S("abcdefghi12345"));
3630     test(S("abcdefghij"), 9, 1, SV("1234567890"), 0, 9, S("abcdefghi123456789"));
3631     test(S("abcdefghij"), 9, 1, SV("1234567890"), 0, 10, S("abcdefghi1234567890"));
3632     test(S("abcdefghij"), 9, 1, SV("1234567890"), 0, 11, S("abcdefghi1234567890"));
3633     test(S("abcdefghij"), 9, 1, SV("1234567890"), 1, 0, S("abcdefghi"));
3634     test(S("abcdefghij"), 9, 1, SV("1234567890"), 1, 1, S("abcdefghi2"));
3635     test(S("abcdefghij"), 9, 1, SV("1234567890"), 1, 4, S("abcdefghi2345"));
3636     test(S("abcdefghij"), 9, 1, SV("1234567890"), 1, 8, S("abcdefghi23456789"));
3637     test(S("abcdefghij"), 9, 1, SV("1234567890"), 1, 9, S("abcdefghi234567890"));
3638     test(S("abcdefghij"), 9, 1, SV("1234567890"), 1, 10, S("abcdefghi234567890"));
3639     test(S("abcdefghij"), 9, 1, SV("1234567890"), 5, 0, S("abcdefghi"));
3640     test(S("abcdefghij"), 9, 1, SV("1234567890"), 5, 1, S("abcdefghi6"));
3641     test(S("abcdefghij"), 9, 1, SV("1234567890"), 5, 2, S("abcdefghi67"));
3642     test(S("abcdefghij"), 9, 1, SV("1234567890"), 5, 4, S("abcdefghi6789"));
3643     test(S("abcdefghij"), 9, 1, SV("1234567890"), 5, 5, S("abcdefghi67890"));
3644     test(S("abcdefghij"), 9, 1, SV("1234567890"), 5, 6, S("abcdefghi67890"));
3645     test(S("abcdefghij"), 9, 1, SV("1234567890"), 9, 0, S("abcdefghi"));
3646     test(S("abcdefghij"), 9, 1, SV("1234567890"), 9, 1, S("abcdefghi0"));
3647     test(S("abcdefghij"), 9, 1, SV("1234567890"), 9, 2, S("abcdefghi0"));
3648     test(S("abcdefghij"), 9, 1, SV("1234567890"), 10, 0, S("abcdefghi"));
3649     test(S("abcdefghij"), 9, 1, SV("1234567890"), 10, 1, S("abcdefghi"));
3650     test(S("abcdefghij"), 9, 1, SV("1234567890"), 11, 0, S("can't happen"));
3651     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 0, 0, S("abcdefghi"));
3652     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 0, 1, S("abcdefghi1"));
3653     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 0, 10, S("abcdefghi1234567890"));
3654     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789"));
3655     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890"));
3656     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890"));
3657     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 1, 0, S("abcdefghi"));
3658     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 1, 1, S("abcdefghi2"));
3659     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 1, 9, S("abcdefghi234567890"));
3660     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789"));
3661     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890"));
3662     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890"));
3663     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 10, 0, S("abcdefghi"));
3664     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 10, 1, S("abcdefghi1"));
3665     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 10, 5, S("abcdefghi12345"));
3666     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 10, 9, S("abcdefghi123456789"));
3667     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 10, 10, S("abcdefghi1234567890"));
3668     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 10, 11, S("abcdefghi1234567890"));
3669     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 19, 0, S("abcdefghi"));
3670     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 19, 1, S("abcdefghi0"));
3671 }
3672 
3673 template <class S, class SV>
test34()3674 void test34()
3675 {
3676     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 19, 2, S("abcdefghi0"));
3677     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 20, 0, S("abcdefghi"));
3678     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 20, 1, S("abcdefghi"));
3679     test(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
3680     test(S("abcdefghij"), 9, 2, SV(""), 0, 0, S("abcdefghi"));
3681     test(S("abcdefghij"), 9, 2, SV(""), 0, 1, S("abcdefghi"));
3682     test(S("abcdefghij"), 9, 2, SV(""), 1, 0, S("can't happen"));
3683     test(S("abcdefghij"), 9, 2, SV("12345"), 0, 0, S("abcdefghi"));
3684     test(S("abcdefghij"), 9, 2, SV("12345"), 0, 1, S("abcdefghi1"));
3685     test(S("abcdefghij"), 9, 2, SV("12345"), 0, 2, S("abcdefghi12"));
3686     test(S("abcdefghij"), 9, 2, SV("12345"), 0, 4, S("abcdefghi1234"));
3687     test(S("abcdefghij"), 9, 2, SV("12345"), 0, 5, S("abcdefghi12345"));
3688     test(S("abcdefghij"), 9, 2, SV("12345"), 0, 6, S("abcdefghi12345"));
3689     test(S("abcdefghij"), 9, 2, SV("12345"), 1, 0, S("abcdefghi"));
3690     test(S("abcdefghij"), 9, 2, SV("12345"), 1, 1, S("abcdefghi2"));
3691     test(S("abcdefghij"), 9, 2, SV("12345"), 1, 2, S("abcdefghi23"));
3692     test(S("abcdefghij"), 9, 2, SV("12345"), 1, 3, S("abcdefghi234"));
3693     test(S("abcdefghij"), 9, 2, SV("12345"), 1, 4, S("abcdefghi2345"));
3694     test(S("abcdefghij"), 9, 2, SV("12345"), 1, 5, S("abcdefghi2345"));
3695     test(S("abcdefghij"), 9, 2, SV("12345"), 2, 0, S("abcdefghi"));
3696     test(S("abcdefghij"), 9, 2, SV("12345"), 2, 1, S("abcdefghi3"));
3697     test(S("abcdefghij"), 9, 2, SV("12345"), 2, 2, S("abcdefghi34"));
3698     test(S("abcdefghij"), 9, 2, SV("12345"), 2, 3, S("abcdefghi345"));
3699     test(S("abcdefghij"), 9, 2, SV("12345"), 2, 4, S("abcdefghi345"));
3700     test(S("abcdefghij"), 9, 2, SV("12345"), 4, 0, S("abcdefghi"));
3701     test(S("abcdefghij"), 9, 2, SV("12345"), 4, 1, S("abcdefghi5"));
3702     test(S("abcdefghij"), 9, 2, SV("12345"), 4, 2, S("abcdefghi5"));
3703     test(S("abcdefghij"), 9, 2, SV("12345"), 5, 0, S("abcdefghi"));
3704     test(S("abcdefghij"), 9, 2, SV("12345"), 5, 1, S("abcdefghi"));
3705     test(S("abcdefghij"), 9, 2, SV("12345"), 6, 0, S("can't happen"));
3706     test(S("abcdefghij"), 9, 2, SV("1234567890"), 0, 0, S("abcdefghi"));
3707     test(S("abcdefghij"), 9, 2, SV("1234567890"), 0, 1, S("abcdefghi1"));
3708     test(S("abcdefghij"), 9, 2, SV("1234567890"), 0, 5, S("abcdefghi12345"));
3709     test(S("abcdefghij"), 9, 2, SV("1234567890"), 0, 9, S("abcdefghi123456789"));
3710     test(S("abcdefghij"), 9, 2, SV("1234567890"), 0, 10, S("abcdefghi1234567890"));
3711     test(S("abcdefghij"), 9, 2, SV("1234567890"), 0, 11, S("abcdefghi1234567890"));
3712     test(S("abcdefghij"), 9, 2, SV("1234567890"), 1, 0, S("abcdefghi"));
3713     test(S("abcdefghij"), 9, 2, SV("1234567890"), 1, 1, S("abcdefghi2"));
3714     test(S("abcdefghij"), 9, 2, SV("1234567890"), 1, 4, S("abcdefghi2345"));
3715     test(S("abcdefghij"), 9, 2, SV("1234567890"), 1, 8, S("abcdefghi23456789"));
3716     test(S("abcdefghij"), 9, 2, SV("1234567890"), 1, 9, S("abcdefghi234567890"));
3717     test(S("abcdefghij"), 9, 2, SV("1234567890"), 1, 10, S("abcdefghi234567890"));
3718     test(S("abcdefghij"), 9, 2, SV("1234567890"), 5, 0, S("abcdefghi"));
3719     test(S("abcdefghij"), 9, 2, SV("1234567890"), 5, 1, S("abcdefghi6"));
3720     test(S("abcdefghij"), 9, 2, SV("1234567890"), 5, 2, S("abcdefghi67"));
3721     test(S("abcdefghij"), 9, 2, SV("1234567890"), 5, 4, S("abcdefghi6789"));
3722     test(S("abcdefghij"), 9, 2, SV("1234567890"), 5, 5, S("abcdefghi67890"));
3723     test(S("abcdefghij"), 9, 2, SV("1234567890"), 5, 6, S("abcdefghi67890"));
3724     test(S("abcdefghij"), 9, 2, SV("1234567890"), 9, 0, S("abcdefghi"));
3725     test(S("abcdefghij"), 9, 2, SV("1234567890"), 9, 1, S("abcdefghi0"));
3726     test(S("abcdefghij"), 9, 2, SV("1234567890"), 9, 2, S("abcdefghi0"));
3727     test(S("abcdefghij"), 9, 2, SV("1234567890"), 10, 0, S("abcdefghi"));
3728     test(S("abcdefghij"), 9, 2, SV("1234567890"), 10, 1, S("abcdefghi"));
3729     test(S("abcdefghij"), 9, 2, SV("1234567890"), 11, 0, S("can't happen"));
3730     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 0, 0, S("abcdefghi"));
3731     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 0, 1, S("abcdefghi1"));
3732     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 0, 10, S("abcdefghi1234567890"));
3733     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789"));
3734     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890"));
3735     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890"));
3736     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 1, 0, S("abcdefghi"));
3737     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 1, 1, S("abcdefghi2"));
3738     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 1, 9, S("abcdefghi234567890"));
3739     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789"));
3740     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890"));
3741     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890"));
3742     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 10, 0, S("abcdefghi"));
3743     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 10, 1, S("abcdefghi1"));
3744     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 10, 5, S("abcdefghi12345"));
3745     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 10, 9, S("abcdefghi123456789"));
3746     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 10, 10, S("abcdefghi1234567890"));
3747     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 10, 11, S("abcdefghi1234567890"));
3748     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 19, 0, S("abcdefghi"));
3749     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 19, 1, S("abcdefghi0"));
3750     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 19, 2, S("abcdefghi0"));
3751     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 20, 0, S("abcdefghi"));
3752     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 20, 1, S("abcdefghi"));
3753     test(S("abcdefghij"), 9, 2, SV("12345678901234567890"), 21, 0, S("can't happen"));
3754     test(S("abcdefghij"), 10, 0, SV(""), 0, 0, S("abcdefghij"));
3755     test(S("abcdefghij"), 10, 0, SV(""), 0, 1, S("abcdefghij"));
3756     test(S("abcdefghij"), 10, 0, SV(""), 1, 0, S("can't happen"));
3757     test(S("abcdefghij"), 10, 0, SV("12345"), 0, 0, S("abcdefghij"));
3758     test(S("abcdefghij"), 10, 0, SV("12345"), 0, 1, S("abcdefghij1"));
3759     test(S("abcdefghij"), 10, 0, SV("12345"), 0, 2, S("abcdefghij12"));
3760     test(S("abcdefghij"), 10, 0, SV("12345"), 0, 4, S("abcdefghij1234"));
3761     test(S("abcdefghij"), 10, 0, SV("12345"), 0, 5, S("abcdefghij12345"));
3762     test(S("abcdefghij"), 10, 0, SV("12345"), 0, 6, S("abcdefghij12345"));
3763     test(S("abcdefghij"), 10, 0, SV("12345"), 1, 0, S("abcdefghij"));
3764     test(S("abcdefghij"), 10, 0, SV("12345"), 1, 1, S("abcdefghij2"));
3765     test(S("abcdefghij"), 10, 0, SV("12345"), 1, 2, S("abcdefghij23"));
3766     test(S("abcdefghij"), 10, 0, SV("12345"), 1, 3, S("abcdefghij234"));
3767     test(S("abcdefghij"), 10, 0, SV("12345"), 1, 4, S("abcdefghij2345"));
3768     test(S("abcdefghij"), 10, 0, SV("12345"), 1, 5, S("abcdefghij2345"));
3769     test(S("abcdefghij"), 10, 0, SV("12345"), 2, 0, S("abcdefghij"));
3770     test(S("abcdefghij"), 10, 0, SV("12345"), 2, 1, S("abcdefghij3"));
3771     test(S("abcdefghij"), 10, 0, SV("12345"), 2, 2, S("abcdefghij34"));
3772     test(S("abcdefghij"), 10, 0, SV("12345"), 2, 3, S("abcdefghij345"));
3773     test(S("abcdefghij"), 10, 0, SV("12345"), 2, 4, S("abcdefghij345"));
3774     test(S("abcdefghij"), 10, 0, SV("12345"), 4, 0, S("abcdefghij"));
3775     test(S("abcdefghij"), 10, 0, SV("12345"), 4, 1, S("abcdefghij5"));
3776 }
3777 
3778 template <class S, class SV>
test35()3779 void test35()
3780 {
3781     test(S("abcdefghij"), 10, 0, SV("12345"), 4, 2, S("abcdefghij5"));
3782     test(S("abcdefghij"), 10, 0, SV("12345"), 5, 0, S("abcdefghij"));
3783     test(S("abcdefghij"), 10, 0, SV("12345"), 5, 1, S("abcdefghij"));
3784     test(S("abcdefghij"), 10, 0, SV("12345"), 6, 0, S("can't happen"));
3785     test(S("abcdefghij"), 10, 0, SV("1234567890"), 0, 0, S("abcdefghij"));
3786     test(S("abcdefghij"), 10, 0, SV("1234567890"), 0, 1, S("abcdefghij1"));
3787     test(S("abcdefghij"), 10, 0, SV("1234567890"), 0, 5, S("abcdefghij12345"));
3788     test(S("abcdefghij"), 10, 0, SV("1234567890"), 0, 9, S("abcdefghij123456789"));
3789     test(S("abcdefghij"), 10, 0, SV("1234567890"), 0, 10, S("abcdefghij1234567890"));
3790     test(S("abcdefghij"), 10, 0, SV("1234567890"), 0, 11, S("abcdefghij1234567890"));
3791     test(S("abcdefghij"), 10, 0, SV("1234567890"), 1, 0, S("abcdefghij"));
3792     test(S("abcdefghij"), 10, 0, SV("1234567890"), 1, 1, S("abcdefghij2"));
3793     test(S("abcdefghij"), 10, 0, SV("1234567890"), 1, 4, S("abcdefghij2345"));
3794     test(S("abcdefghij"), 10, 0, SV("1234567890"), 1, 8, S("abcdefghij23456789"));
3795     test(S("abcdefghij"), 10, 0, SV("1234567890"), 1, 9, S("abcdefghij234567890"));
3796     test(S("abcdefghij"), 10, 0, SV("1234567890"), 1, 10, S("abcdefghij234567890"));
3797     test(S("abcdefghij"), 10, 0, SV("1234567890"), 5, 0, S("abcdefghij"));
3798     test(S("abcdefghij"), 10, 0, SV("1234567890"), 5, 1, S("abcdefghij6"));
3799     test(S("abcdefghij"), 10, 0, SV("1234567890"), 5, 2, S("abcdefghij67"));
3800     test(S("abcdefghij"), 10, 0, SV("1234567890"), 5, 4, S("abcdefghij6789"));
3801     test(S("abcdefghij"), 10, 0, SV("1234567890"), 5, 5, S("abcdefghij67890"));
3802     test(S("abcdefghij"), 10, 0, SV("1234567890"), 5, 6, S("abcdefghij67890"));
3803     test(S("abcdefghij"), 10, 0, SV("1234567890"), 9, 0, S("abcdefghij"));
3804     test(S("abcdefghij"), 10, 0, SV("1234567890"), 9, 1, S("abcdefghij0"));
3805     test(S("abcdefghij"), 10, 0, SV("1234567890"), 9, 2, S("abcdefghij0"));
3806     test(S("abcdefghij"), 10, 0, SV("1234567890"), 10, 0, S("abcdefghij"));
3807     test(S("abcdefghij"), 10, 0, SV("1234567890"), 10, 1, S("abcdefghij"));
3808     test(S("abcdefghij"), 10, 0, SV("1234567890"), 11, 0, S("can't happen"));
3809     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
3810     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 0, 1, S("abcdefghij1"));
3811     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
3812     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
3813     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
3814     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
3815     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
3816     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 1, 1, S("abcdefghij2"));
3817     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
3818     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
3819     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
3820     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
3821     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
3822     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 10, 1, S("abcdefghij1"));
3823     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 10, 5, S("abcdefghij12345"));
3824     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
3825     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
3826     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
3827     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
3828     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 19, 1, S("abcdefghij0"));
3829     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 19, 2, S("abcdefghij0"));
3830     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
3831     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
3832     test(S("abcdefghij"), 10, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
3833     test(S("abcdefghij"), 10, 1, SV(""), 0, 0, S("abcdefghij"));
3834     test(S("abcdefghij"), 10, 1, SV(""), 0, 1, S("abcdefghij"));
3835     test(S("abcdefghij"), 10, 1, SV(""), 1, 0, S("can't happen"));
3836     test(S("abcdefghij"), 10, 1, SV("12345"), 0, 0, S("abcdefghij"));
3837     test(S("abcdefghij"), 10, 1, SV("12345"), 0, 1, S("abcdefghij1"));
3838     test(S("abcdefghij"), 10, 1, SV("12345"), 0, 2, S("abcdefghij12"));
3839     test(S("abcdefghij"), 10, 1, SV("12345"), 0, 4, S("abcdefghij1234"));
3840     test(S("abcdefghij"), 10, 1, SV("12345"), 0, 5, S("abcdefghij12345"));
3841     test(S("abcdefghij"), 10, 1, SV("12345"), 0, 6, S("abcdefghij12345"));
3842     test(S("abcdefghij"), 10, 1, SV("12345"), 1, 0, S("abcdefghij"));
3843     test(S("abcdefghij"), 10, 1, SV("12345"), 1, 1, S("abcdefghij2"));
3844     test(S("abcdefghij"), 10, 1, SV("12345"), 1, 2, S("abcdefghij23"));
3845     test(S("abcdefghij"), 10, 1, SV("12345"), 1, 3, S("abcdefghij234"));
3846     test(S("abcdefghij"), 10, 1, SV("12345"), 1, 4, S("abcdefghij2345"));
3847     test(S("abcdefghij"), 10, 1, SV("12345"), 1, 5, S("abcdefghij2345"));
3848     test(S("abcdefghij"), 10, 1, SV("12345"), 2, 0, S("abcdefghij"));
3849     test(S("abcdefghij"), 10, 1, SV("12345"), 2, 1, S("abcdefghij3"));
3850     test(S("abcdefghij"), 10, 1, SV("12345"), 2, 2, S("abcdefghij34"));
3851     test(S("abcdefghij"), 10, 1, SV("12345"), 2, 3, S("abcdefghij345"));
3852     test(S("abcdefghij"), 10, 1, SV("12345"), 2, 4, S("abcdefghij345"));
3853     test(S("abcdefghij"), 10, 1, SV("12345"), 4, 0, S("abcdefghij"));
3854     test(S("abcdefghij"), 10, 1, SV("12345"), 4, 1, S("abcdefghij5"));
3855     test(S("abcdefghij"), 10, 1, SV("12345"), 4, 2, S("abcdefghij5"));
3856     test(S("abcdefghij"), 10, 1, SV("12345"), 5, 0, S("abcdefghij"));
3857     test(S("abcdefghij"), 10, 1, SV("12345"), 5, 1, S("abcdefghij"));
3858     test(S("abcdefghij"), 10, 1, SV("12345"), 6, 0, S("can't happen"));
3859     test(S("abcdefghij"), 10, 1, SV("1234567890"), 0, 0, S("abcdefghij"));
3860     test(S("abcdefghij"), 10, 1, SV("1234567890"), 0, 1, S("abcdefghij1"));
3861     test(S("abcdefghij"), 10, 1, SV("1234567890"), 0, 5, S("abcdefghij12345"));
3862     test(S("abcdefghij"), 10, 1, SV("1234567890"), 0, 9, S("abcdefghij123456789"));
3863     test(S("abcdefghij"), 10, 1, SV("1234567890"), 0, 10, S("abcdefghij1234567890"));
3864     test(S("abcdefghij"), 10, 1, SV("1234567890"), 0, 11, S("abcdefghij1234567890"));
3865     test(S("abcdefghij"), 10, 1, SV("1234567890"), 1, 0, S("abcdefghij"));
3866     test(S("abcdefghij"), 10, 1, SV("1234567890"), 1, 1, S("abcdefghij2"));
3867     test(S("abcdefghij"), 10, 1, SV("1234567890"), 1, 4, S("abcdefghij2345"));
3868     test(S("abcdefghij"), 10, 1, SV("1234567890"), 1, 8, S("abcdefghij23456789"));
3869     test(S("abcdefghij"), 10, 1, SV("1234567890"), 1, 9, S("abcdefghij234567890"));
3870     test(S("abcdefghij"), 10, 1, SV("1234567890"), 1, 10, S("abcdefghij234567890"));
3871     test(S("abcdefghij"), 10, 1, SV("1234567890"), 5, 0, S("abcdefghij"));
3872     test(S("abcdefghij"), 10, 1, SV("1234567890"), 5, 1, S("abcdefghij6"));
3873     test(S("abcdefghij"), 10, 1, SV("1234567890"), 5, 2, S("abcdefghij67"));
3874     test(S("abcdefghij"), 10, 1, SV("1234567890"), 5, 4, S("abcdefghij6789"));
3875     test(S("abcdefghij"), 10, 1, SV("1234567890"), 5, 5, S("abcdefghij67890"));
3876     test(S("abcdefghij"), 10, 1, SV("1234567890"), 5, 6, S("abcdefghij67890"));
3877     test(S("abcdefghij"), 10, 1, SV("1234567890"), 9, 0, S("abcdefghij"));
3878     test(S("abcdefghij"), 10, 1, SV("1234567890"), 9, 1, S("abcdefghij0"));
3879     test(S("abcdefghij"), 10, 1, SV("1234567890"), 9, 2, S("abcdefghij0"));
3880     test(S("abcdefghij"), 10, 1, SV("1234567890"), 10, 0, S("abcdefghij"));
3881 }
3882 
3883 template <class S, class SV>
test36()3884 void test36()
3885 {
3886     test(S("abcdefghij"), 10, 1, SV("1234567890"), 10, 1, S("abcdefghij"));
3887     test(S("abcdefghij"), 10, 1, SV("1234567890"), 11, 0, S("can't happen"));
3888     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
3889     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 0, 1, S("abcdefghij1"));
3890     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
3891     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
3892     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
3893     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
3894     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
3895     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 1, 1, S("abcdefghij2"));
3896     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
3897     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
3898     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
3899     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
3900     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
3901     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 10, 1, S("abcdefghij1"));
3902     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 10, 5, S("abcdefghij12345"));
3903     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
3904     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
3905     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
3906     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
3907     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 19, 1, S("abcdefghij0"));
3908     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 19, 2, S("abcdefghij0"));
3909     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
3910     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
3911     test(S("abcdefghij"), 10, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
3912     test(S("abcdefghij"), 11, 0, SV(""), 0, 0, S("can't happen"));
3913     test(S("abcdefghij"), 11, 0, SV(""), 0, 1, S("can't happen"));
3914     test(S("abcdefghij"), 11, 0, SV(""), 1, 0, S("can't happen"));
3915     test(S("abcdefghij"), 11, 0, SV("12345"), 0, 0, S("can't happen"));
3916     test(S("abcdefghij"), 11, 0, SV("12345"), 0, 1, S("can't happen"));
3917     test(S("abcdefghij"), 11, 0, SV("12345"), 0, 2, S("can't happen"));
3918     test(S("abcdefghij"), 11, 0, SV("12345"), 0, 4, S("can't happen"));
3919     test(S("abcdefghij"), 11, 0, SV("12345"), 0, 5, S("can't happen"));
3920     test(S("abcdefghij"), 11, 0, SV("12345"), 0, 6, S("can't happen"));
3921     test(S("abcdefghij"), 11, 0, SV("12345"), 1, 0, S("can't happen"));
3922     test(S("abcdefghij"), 11, 0, SV("12345"), 1, 1, S("can't happen"));
3923     test(S("abcdefghij"), 11, 0, SV("12345"), 1, 2, S("can't happen"));
3924     test(S("abcdefghij"), 11, 0, SV("12345"), 1, 3, S("can't happen"));
3925     test(S("abcdefghij"), 11, 0, SV("12345"), 1, 4, S("can't happen"));
3926     test(S("abcdefghij"), 11, 0, SV("12345"), 1, 5, S("can't happen"));
3927     test(S("abcdefghij"), 11, 0, SV("12345"), 2, 0, S("can't happen"));
3928     test(S("abcdefghij"), 11, 0, SV("12345"), 2, 1, S("can't happen"));
3929     test(S("abcdefghij"), 11, 0, SV("12345"), 2, 2, S("can't happen"));
3930     test(S("abcdefghij"), 11, 0, SV("12345"), 2, 3, S("can't happen"));
3931     test(S("abcdefghij"), 11, 0, SV("12345"), 2, 4, S("can't happen"));
3932     test(S("abcdefghij"), 11, 0, SV("12345"), 4, 0, S("can't happen"));
3933     test(S("abcdefghij"), 11, 0, SV("12345"), 4, 1, S("can't happen"));
3934     test(S("abcdefghij"), 11, 0, SV("12345"), 4, 2, S("can't happen"));
3935     test(S("abcdefghij"), 11, 0, SV("12345"), 5, 0, S("can't happen"));
3936     test(S("abcdefghij"), 11, 0, SV("12345"), 5, 1, S("can't happen"));
3937     test(S("abcdefghij"), 11, 0, SV("12345"), 6, 0, S("can't happen"));
3938     test(S("abcdefghij"), 11, 0, SV("1234567890"), 0, 0, S("can't happen"));
3939     test(S("abcdefghij"), 11, 0, SV("1234567890"), 0, 1, S("can't happen"));
3940     test(S("abcdefghij"), 11, 0, SV("1234567890"), 0, 5, S("can't happen"));
3941     test(S("abcdefghij"), 11, 0, SV("1234567890"), 0, 9, S("can't happen"));
3942     test(S("abcdefghij"), 11, 0, SV("1234567890"), 0, 10, S("can't happen"));
3943     test(S("abcdefghij"), 11, 0, SV("1234567890"), 0, 11, S("can't happen"));
3944     test(S("abcdefghij"), 11, 0, SV("1234567890"), 1, 0, S("can't happen"));
3945     test(S("abcdefghij"), 11, 0, SV("1234567890"), 1, 1, S("can't happen"));
3946     test(S("abcdefghij"), 11, 0, SV("1234567890"), 1, 4, S("can't happen"));
3947     test(S("abcdefghij"), 11, 0, SV("1234567890"), 1, 8, S("can't happen"));
3948     test(S("abcdefghij"), 11, 0, SV("1234567890"), 1, 9, S("can't happen"));
3949     test(S("abcdefghij"), 11, 0, SV("1234567890"), 1, 10, S("can't happen"));
3950     test(S("abcdefghij"), 11, 0, SV("1234567890"), 5, 0, S("can't happen"));
3951     test(S("abcdefghij"), 11, 0, SV("1234567890"), 5, 1, S("can't happen"));
3952     test(S("abcdefghij"), 11, 0, SV("1234567890"), 5, 2, S("can't happen"));
3953     test(S("abcdefghij"), 11, 0, SV("1234567890"), 5, 4, S("can't happen"));
3954     test(S("abcdefghij"), 11, 0, SV("1234567890"), 5, 5, S("can't happen"));
3955     test(S("abcdefghij"), 11, 0, SV("1234567890"), 5, 6, S("can't happen"));
3956     test(S("abcdefghij"), 11, 0, SV("1234567890"), 9, 0, S("can't happen"));
3957     test(S("abcdefghij"), 11, 0, SV("1234567890"), 9, 1, S("can't happen"));
3958     test(S("abcdefghij"), 11, 0, SV("1234567890"), 9, 2, S("can't happen"));
3959     test(S("abcdefghij"), 11, 0, SV("1234567890"), 10, 0, S("can't happen"));
3960     test(S("abcdefghij"), 11, 0, SV("1234567890"), 10, 1, S("can't happen"));
3961     test(S("abcdefghij"), 11, 0, SV("1234567890"), 11, 0, S("can't happen"));
3962     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 0, 0, S("can't happen"));
3963     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 0, 1, S("can't happen"));
3964     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 0, 10, S("can't happen"));
3965     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 0, 19, S("can't happen"));
3966     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 0, 20, S("can't happen"));
3967     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 0, 21, S("can't happen"));
3968     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 1, 0, S("can't happen"));
3969     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 1, 1, S("can't happen"));
3970     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 1, 9, S("can't happen"));
3971     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 1, 18, S("can't happen"));
3972     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 1, 19, S("can't happen"));
3973     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 1, 20, S("can't happen"));
3974     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 10, 0, S("can't happen"));
3975     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 10, 1, S("can't happen"));
3976     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 10, 5, S("can't happen"));
3977     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 10, 9, S("can't happen"));
3978     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 10, 10, S("can't happen"));
3979     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 10, 11, S("can't happen"));
3980     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 19, 0, S("can't happen"));
3981     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 19, 1, S("can't happen"));
3982     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 19, 2, S("can't happen"));
3983     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 20, 0, S("can't happen"));
3984     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 20, 1, S("can't happen"));
3985     test(S("abcdefghij"), 11, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
3986 }
3987 
3988 template <class S, class SV>
test37()3989 void test37()
3990 {
3991     test(S("abcdefghijklmnopqrst"), 0, 0, SV(""), 0, 0, S("abcdefghijklmnopqrst"));
3992     test(S("abcdefghijklmnopqrst"), 0, 0, SV(""), 0, 1, S("abcdefghijklmnopqrst"));
3993     test(S("abcdefghijklmnopqrst"), 0, 0, SV(""), 1, 0, S("can't happen"));
3994     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 0, 0, S("abcdefghijklmnopqrst"));
3995     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 0, 1, S("1abcdefghijklmnopqrst"));
3996     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 0, 2, S("12abcdefghijklmnopqrst"));
3997     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 0, 4, S("1234abcdefghijklmnopqrst"));
3998     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 0, 5, S("12345abcdefghijklmnopqrst"));
3999     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 0, 6, S("12345abcdefghijklmnopqrst"));
4000     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 1, 0, S("abcdefghijklmnopqrst"));
4001     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 1, 1, S("2abcdefghijklmnopqrst"));
4002     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 1, 2, S("23abcdefghijklmnopqrst"));
4003     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 1, 3, S("234abcdefghijklmnopqrst"));
4004     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 1, 4, S("2345abcdefghijklmnopqrst"));
4005     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 1, 5, S("2345abcdefghijklmnopqrst"));
4006     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
4007     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 2, 1, S("3abcdefghijklmnopqrst"));
4008     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 2, 2, S("34abcdefghijklmnopqrst"));
4009     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 2, 3, S("345abcdefghijklmnopqrst"));
4010     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 2, 4, S("345abcdefghijklmnopqrst"));
4011     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 4, 0, S("abcdefghijklmnopqrst"));
4012     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 4, 1, S("5abcdefghijklmnopqrst"));
4013     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 4, 2, S("5abcdefghijklmnopqrst"));
4014     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 5, 0, S("abcdefghijklmnopqrst"));
4015     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 5, 1, S("abcdefghijklmnopqrst"));
4016     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345"), 6, 0, S("can't happen"));
4017     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4018     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
4019     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 0, 5, S("12345abcdefghijklmnopqrst"));
4020     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 0, 9, S("123456789abcdefghijklmnopqrst"));
4021     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
4022     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 0, 11, S("1234567890abcdefghijklmnopqrst"));
4023     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4024     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
4025     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 1, 4, S("2345abcdefghijklmnopqrst"));
4026     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 1, 8, S("23456789abcdefghijklmnopqrst"));
4027     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
4028     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 1, 10, S("234567890abcdefghijklmnopqrst"));
4029     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
4030     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 5, 1, S("6abcdefghijklmnopqrst"));
4031     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 5, 2, S("67abcdefghijklmnopqrst"));
4032     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 5, 4, S("6789abcdefghijklmnopqrst"));
4033     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 5, 5, S("67890abcdefghijklmnopqrst"));
4034     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 5, 6, S("67890abcdefghijklmnopqrst"));
4035     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
4036     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 9, 1, S("0abcdefghijklmnopqrst"));
4037     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 9, 2, S("0abcdefghijklmnopqrst"));
4038     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4039     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
4040     test(S("abcdefghijklmnopqrst"), 0, 0, SV("1234567890"), 11, 0, S("can't happen"));
4041     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4042     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
4043     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
4044     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghijklmnopqrst"));
4045     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghijklmnopqrst"));
4046     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghijklmnopqrst"));
4047     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4048     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
4049     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
4050     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 1, 18, S("234567890123456789abcdefghijklmnopqrst"));
4051     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghijklmnopqrst"));
4052     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghijklmnopqrst"));
4053     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4054     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 10, 1, S("1abcdefghijklmnopqrst"));
4055     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 10, 5, S("12345abcdefghijklmnopqrst"));
4056     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 10, 9, S("123456789abcdefghijklmnopqrst"));
4057     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 10, 10, S("1234567890abcdefghijklmnopqrst"));
4058     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 10, 11, S("1234567890abcdefghijklmnopqrst"));
4059     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
4060     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 19, 1, S("0abcdefghijklmnopqrst"));
4061     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 19, 2, S("0abcdefghijklmnopqrst"));
4062     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
4063     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
4064     test(S("abcdefghijklmnopqrst"), 0, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
4065     test(S("abcdefghijklmnopqrst"), 0, 1, SV(""), 0, 0, S("bcdefghijklmnopqrst"));
4066     test(S("abcdefghijklmnopqrst"), 0, 1, SV(""), 0, 1, S("bcdefghijklmnopqrst"));
4067     test(S("abcdefghijklmnopqrst"), 0, 1, SV(""), 1, 0, S("can't happen"));
4068     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 0, 0, S("bcdefghijklmnopqrst"));
4069     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 0, 1, S("1bcdefghijklmnopqrst"));
4070     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 0, 2, S("12bcdefghijklmnopqrst"));
4071     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 0, 4, S("1234bcdefghijklmnopqrst"));
4072     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 0, 5, S("12345bcdefghijklmnopqrst"));
4073     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 0, 6, S("12345bcdefghijklmnopqrst"));
4074     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 1, 0, S("bcdefghijklmnopqrst"));
4075     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 1, 1, S("2bcdefghijklmnopqrst"));
4076     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 1, 2, S("23bcdefghijklmnopqrst"));
4077     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 1, 3, S("234bcdefghijklmnopqrst"));
4078     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 1, 4, S("2345bcdefghijklmnopqrst"));
4079     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 1, 5, S("2345bcdefghijklmnopqrst"));
4080     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 2, 0, S("bcdefghijklmnopqrst"));
4081     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 2, 1, S("3bcdefghijklmnopqrst"));
4082     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 2, 2, S("34bcdefghijklmnopqrst"));
4083     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 2, 3, S("345bcdefghijklmnopqrst"));
4084     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 2, 4, S("345bcdefghijklmnopqrst"));
4085     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 4, 0, S("bcdefghijklmnopqrst"));
4086     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 4, 1, S("5bcdefghijklmnopqrst"));
4087     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 4, 2, S("5bcdefghijklmnopqrst"));
4088     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 5, 0, S("bcdefghijklmnopqrst"));
4089     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 5, 1, S("bcdefghijklmnopqrst"));
4090     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345"), 6, 0, S("can't happen"));
4091 }
4092 
4093 template <class S, class SV>
test38()4094 void test38()
4095 {
4096     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 0, 0, S("bcdefghijklmnopqrst"));
4097     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 0, 1, S("1bcdefghijklmnopqrst"));
4098     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 0, 5, S("12345bcdefghijklmnopqrst"));
4099     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 0, 9, S("123456789bcdefghijklmnopqrst"));
4100     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 0, 10, S("1234567890bcdefghijklmnopqrst"));
4101     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 0, 11, S("1234567890bcdefghijklmnopqrst"));
4102     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 1, 0, S("bcdefghijklmnopqrst"));
4103     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 1, 1, S("2bcdefghijklmnopqrst"));
4104     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 1, 4, S("2345bcdefghijklmnopqrst"));
4105     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 1, 8, S("23456789bcdefghijklmnopqrst"));
4106     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 1, 9, S("234567890bcdefghijklmnopqrst"));
4107     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 1, 10, S("234567890bcdefghijklmnopqrst"));
4108     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 5, 0, S("bcdefghijklmnopqrst"));
4109     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 5, 1, S("6bcdefghijklmnopqrst"));
4110     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 5, 2, S("67bcdefghijklmnopqrst"));
4111     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 5, 4, S("6789bcdefghijklmnopqrst"));
4112     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 5, 5, S("67890bcdefghijklmnopqrst"));
4113     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 5, 6, S("67890bcdefghijklmnopqrst"));
4114     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 9, 0, S("bcdefghijklmnopqrst"));
4115     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 9, 1, S("0bcdefghijklmnopqrst"));
4116     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 9, 2, S("0bcdefghijklmnopqrst"));
4117     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 10, 0, S("bcdefghijklmnopqrst"));
4118     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 10, 1, S("bcdefghijklmnopqrst"));
4119     test(S("abcdefghijklmnopqrst"), 0, 1, SV("1234567890"), 11, 0, S("can't happen"));
4120     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 0, 0, S("bcdefghijklmnopqrst"));
4121     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 0, 1, S("1bcdefghijklmnopqrst"));
4122     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 0, 10, S("1234567890bcdefghijklmnopqrst"));
4123     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 0, 19, S("1234567890123456789bcdefghijklmnopqrst"));
4124     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 0, 20, S("12345678901234567890bcdefghijklmnopqrst"));
4125     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 0, 21, S("12345678901234567890bcdefghijklmnopqrst"));
4126     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 1, 0, S("bcdefghijklmnopqrst"));
4127     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 1, 1, S("2bcdefghijklmnopqrst"));
4128     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 1, 9, S("234567890bcdefghijklmnopqrst"));
4129     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 1, 18, S("234567890123456789bcdefghijklmnopqrst"));
4130     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 1, 19, S("2345678901234567890bcdefghijklmnopqrst"));
4131     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 1, 20, S("2345678901234567890bcdefghijklmnopqrst"));
4132     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 10, 0, S("bcdefghijklmnopqrst"));
4133     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 10, 1, S("1bcdefghijklmnopqrst"));
4134     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 10, 5, S("12345bcdefghijklmnopqrst"));
4135     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 10, 9, S("123456789bcdefghijklmnopqrst"));
4136     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 10, 10, S("1234567890bcdefghijklmnopqrst"));
4137     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 10, 11, S("1234567890bcdefghijklmnopqrst"));
4138     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 19, 0, S("bcdefghijklmnopqrst"));
4139     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 19, 1, S("0bcdefghijklmnopqrst"));
4140     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 19, 2, S("0bcdefghijklmnopqrst"));
4141     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 20, 0, S("bcdefghijklmnopqrst"));
4142     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 20, 1, S("bcdefghijklmnopqrst"));
4143     test(S("abcdefghijklmnopqrst"), 0, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
4144     test(S("abcdefghijklmnopqrst"), 0, 10, SV(""), 0, 0, S("klmnopqrst"));
4145     test(S("abcdefghijklmnopqrst"), 0, 10, SV(""), 0, 1, S("klmnopqrst"));
4146     test(S("abcdefghijklmnopqrst"), 0, 10, SV(""), 1, 0, S("can't happen"));
4147     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 0, 0, S("klmnopqrst"));
4148     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 0, 1, S("1klmnopqrst"));
4149     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 0, 2, S("12klmnopqrst"));
4150     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 0, 4, S("1234klmnopqrst"));
4151     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 0, 5, S("12345klmnopqrst"));
4152     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 0, 6, S("12345klmnopqrst"));
4153     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 1, 0, S("klmnopqrst"));
4154     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 1, 1, S("2klmnopqrst"));
4155     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 1, 2, S("23klmnopqrst"));
4156     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 1, 3, S("234klmnopqrst"));
4157     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 1, 4, S("2345klmnopqrst"));
4158     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 1, 5, S("2345klmnopqrst"));
4159     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 2, 0, S("klmnopqrst"));
4160     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 2, 1, S("3klmnopqrst"));
4161     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 2, 2, S("34klmnopqrst"));
4162     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 2, 3, S("345klmnopqrst"));
4163     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 2, 4, S("345klmnopqrst"));
4164     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 4, 0, S("klmnopqrst"));
4165     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 4, 1, S("5klmnopqrst"));
4166     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 4, 2, S("5klmnopqrst"));
4167     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 5, 0, S("klmnopqrst"));
4168     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 5, 1, S("klmnopqrst"));
4169     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345"), 6, 0, S("can't happen"));
4170     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 0, 0, S("klmnopqrst"));
4171     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 0, 1, S("1klmnopqrst"));
4172     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 0, 5, S("12345klmnopqrst"));
4173     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 0, 9, S("123456789klmnopqrst"));
4174     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 0, 10, S("1234567890klmnopqrst"));
4175     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 0, 11, S("1234567890klmnopqrst"));
4176     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 1, 0, S("klmnopqrst"));
4177     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 1, 1, S("2klmnopqrst"));
4178     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 1, 4, S("2345klmnopqrst"));
4179     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 1, 8, S("23456789klmnopqrst"));
4180     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 1, 9, S("234567890klmnopqrst"));
4181     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 1, 10, S("234567890klmnopqrst"));
4182     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 5, 0, S("klmnopqrst"));
4183     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 5, 1, S("6klmnopqrst"));
4184     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 5, 2, S("67klmnopqrst"));
4185     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 5, 4, S("6789klmnopqrst"));
4186     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 5, 5, S("67890klmnopqrst"));
4187     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 5, 6, S("67890klmnopqrst"));
4188     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 9, 0, S("klmnopqrst"));
4189     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 9, 1, S("0klmnopqrst"));
4190     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 9, 2, S("0klmnopqrst"));
4191     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 10, 0, S("klmnopqrst"));
4192     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 10, 1, S("klmnopqrst"));
4193     test(S("abcdefghijklmnopqrst"), 0, 10, SV("1234567890"), 11, 0, S("can't happen"));
4194     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 0, 0, S("klmnopqrst"));
4195     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 0, 1, S("1klmnopqrst"));
4196 }
4197 
4198 template <class S, class SV>
test39()4199 void test39()
4200 {
4201     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 0, 10, S("1234567890klmnopqrst"));
4202     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 0, 19, S("1234567890123456789klmnopqrst"));
4203     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 0, 20, S("12345678901234567890klmnopqrst"));
4204     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 0, 21, S("12345678901234567890klmnopqrst"));
4205     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 1, 0, S("klmnopqrst"));
4206     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 1, 1, S("2klmnopqrst"));
4207     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 1, 9, S("234567890klmnopqrst"));
4208     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 1, 18, S("234567890123456789klmnopqrst"));
4209     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 1, 19, S("2345678901234567890klmnopqrst"));
4210     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 1, 20, S("2345678901234567890klmnopqrst"));
4211     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 10, 0, S("klmnopqrst"));
4212     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 10, 1, S("1klmnopqrst"));
4213     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 10, 5, S("12345klmnopqrst"));
4214     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 10, 9, S("123456789klmnopqrst"));
4215     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 10, 10, S("1234567890klmnopqrst"));
4216     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 10, 11, S("1234567890klmnopqrst"));
4217     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 19, 0, S("klmnopqrst"));
4218     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 19, 1, S("0klmnopqrst"));
4219     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 19, 2, S("0klmnopqrst"));
4220     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 20, 0, S("klmnopqrst"));
4221     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 20, 1, S("klmnopqrst"));
4222     test(S("abcdefghijklmnopqrst"), 0, 10, SV("12345678901234567890"), 21, 0, S("can't happen"));
4223     test(S("abcdefghijklmnopqrst"), 0, 19, SV(""), 0, 0, S("t"));
4224     test(S("abcdefghijklmnopqrst"), 0, 19, SV(""), 0, 1, S("t"));
4225     test(S("abcdefghijklmnopqrst"), 0, 19, SV(""), 1, 0, S("can't happen"));
4226     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 0, 0, S("t"));
4227     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 0, 1, S("1t"));
4228     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 0, 2, S("12t"));
4229     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 0, 4, S("1234t"));
4230     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 0, 5, S("12345t"));
4231     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 0, 6, S("12345t"));
4232     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 1, 0, S("t"));
4233     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 1, 1, S("2t"));
4234     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 1, 2, S("23t"));
4235     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 1, 3, S("234t"));
4236     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 1, 4, S("2345t"));
4237     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 1, 5, S("2345t"));
4238     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 2, 0, S("t"));
4239     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 2, 1, S("3t"));
4240     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 2, 2, S("34t"));
4241     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 2, 3, S("345t"));
4242     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 2, 4, S("345t"));
4243     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 4, 0, S("t"));
4244     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 4, 1, S("5t"));
4245     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 4, 2, S("5t"));
4246     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 5, 0, S("t"));
4247     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 5, 1, S("t"));
4248     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345"), 6, 0, S("can't happen"));
4249     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 0, 0, S("t"));
4250     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 0, 1, S("1t"));
4251     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 0, 5, S("12345t"));
4252     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 0, 9, S("123456789t"));
4253     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 0, 10, S("1234567890t"));
4254     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 0, 11, S("1234567890t"));
4255     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 1, 0, S("t"));
4256     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 1, 1, S("2t"));
4257     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 1, 4, S("2345t"));
4258     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 1, 8, S("23456789t"));
4259     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 1, 9, S("234567890t"));
4260     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 1, 10, S("234567890t"));
4261     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 5, 0, S("t"));
4262     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 5, 1, S("6t"));
4263     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 5, 2, S("67t"));
4264     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 5, 4, S("6789t"));
4265     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 5, 5, S("67890t"));
4266     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 5, 6, S("67890t"));
4267     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 9, 0, S("t"));
4268     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 9, 1, S("0t"));
4269     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 9, 2, S("0t"));
4270     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 10, 0, S("t"));
4271     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 10, 1, S("t"));
4272     test(S("abcdefghijklmnopqrst"), 0, 19, SV("1234567890"), 11, 0, S("can't happen"));
4273     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 0, 0, S("t"));
4274     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 0, 1, S("1t"));
4275     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 0, 10, S("1234567890t"));
4276     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 0, 19, S("1234567890123456789t"));
4277     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 0, 20, S("12345678901234567890t"));
4278     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 0, 21, S("12345678901234567890t"));
4279     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 1, 0, S("t"));
4280     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 1, 1, S("2t"));
4281     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 1, 9, S("234567890t"));
4282     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 1, 18, S("234567890123456789t"));
4283     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 1, 19, S("2345678901234567890t"));
4284     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 1, 20, S("2345678901234567890t"));
4285     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 10, 0, S("t"));
4286     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 10, 1, S("1t"));
4287     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 10, 5, S("12345t"));
4288     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 10, 9, S("123456789t"));
4289     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 10, 10, S("1234567890t"));
4290     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 10, 11, S("1234567890t"));
4291     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 19, 0, S("t"));
4292     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 19, 1, S("0t"));
4293     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 19, 2, S("0t"));
4294     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 20, 0, S("t"));
4295     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 20, 1, S("t"));
4296     test(S("abcdefghijklmnopqrst"), 0, 19, SV("12345678901234567890"), 21, 0, S("can't happen"));
4297     test(S("abcdefghijklmnopqrst"), 0, 20, SV(""), 0, 0, S(""));
4298     test(S("abcdefghijklmnopqrst"), 0, 20, SV(""), 0, 1, S(""));
4299     test(S("abcdefghijklmnopqrst"), 0, 20, SV(""), 1, 0, S("can't happen"));
4300     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 0, 0, S(""));
4301 }
4302 
4303 template <class S, class SV>
test40()4304 void test40()
4305 {
4306     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 0, 1, S("1"));
4307     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 0, 2, S("12"));
4308     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 0, 4, S("1234"));
4309     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 0, 5, S("12345"));
4310     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 0, 6, S("12345"));
4311     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 1, 0, S(""));
4312     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 1, 1, S("2"));
4313     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 1, 2, S("23"));
4314     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 1, 3, S("234"));
4315     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 1, 4, S("2345"));
4316     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 1, 5, S("2345"));
4317     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 2, 0, S(""));
4318     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 2, 1, S("3"));
4319     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 2, 2, S("34"));
4320     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 2, 3, S("345"));
4321     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 2, 4, S("345"));
4322     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 4, 0, S(""));
4323     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 4, 1, S("5"));
4324     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 4, 2, S("5"));
4325     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 5, 0, S(""));
4326     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 5, 1, S(""));
4327     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345"), 6, 0, S("can't happen"));
4328     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 0, 0, S(""));
4329     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 0, 1, S("1"));
4330     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 0, 5, S("12345"));
4331     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 0, 9, S("123456789"));
4332     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 0, 10, S("1234567890"));
4333     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 0, 11, S("1234567890"));
4334     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 1, 0, S(""));
4335     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 1, 1, S("2"));
4336     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 1, 4, S("2345"));
4337     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 1, 8, S("23456789"));
4338     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 1, 9, S("234567890"));
4339     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 1, 10, S("234567890"));
4340     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 5, 0, S(""));
4341     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 5, 1, S("6"));
4342     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 5, 2, S("67"));
4343     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 5, 4, S("6789"));
4344     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 5, 5, S("67890"));
4345     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 5, 6, S("67890"));
4346     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 9, 0, S(""));
4347     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 9, 1, S("0"));
4348     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 9, 2, S("0"));
4349     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 10, 0, S(""));
4350     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 10, 1, S(""));
4351     test(S("abcdefghijklmnopqrst"), 0, 20, SV("1234567890"), 11, 0, S("can't happen"));
4352     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 0, 0, S(""));
4353     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 0, 1, S("1"));
4354     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 0, 10, S("1234567890"));
4355     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
4356     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
4357     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
4358     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 1, 0, S(""));
4359     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 1, 1, S("2"));
4360     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 1, 9, S("234567890"));
4361     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
4362     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
4363     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
4364     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 10, 0, S(""));
4365     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 10, 1, S("1"));
4366     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 10, 5, S("12345"));
4367     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 10, 9, S("123456789"));
4368     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 10, 10, S("1234567890"));
4369     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 10, 11, S("1234567890"));
4370     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 19, 0, S(""));
4371     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 19, 1, S("0"));
4372     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 19, 2, S("0"));
4373     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 20, 0, S(""));
4374     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 20, 1, S(""));
4375     test(S("abcdefghijklmnopqrst"), 0, 20, SV("12345678901234567890"), 21, 0, S("can't happen"));
4376     test(S("abcdefghijklmnopqrst"), 0, 21, SV(""), 0, 0, S(""));
4377     test(S("abcdefghijklmnopqrst"), 0, 21, SV(""), 0, 1, S(""));
4378     test(S("abcdefghijklmnopqrst"), 0, 21, SV(""), 1, 0, S("can't happen"));
4379     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 0, 0, S(""));
4380     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 0, 1, S("1"));
4381     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 0, 2, S("12"));
4382     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 0, 4, S("1234"));
4383     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 0, 5, S("12345"));
4384     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 0, 6, S("12345"));
4385     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 1, 0, S(""));
4386     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 1, 1, S("2"));
4387     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 1, 2, S("23"));
4388     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 1, 3, S("234"));
4389     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 1, 4, S("2345"));
4390     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 1, 5, S("2345"));
4391     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 2, 0, S(""));
4392     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 2, 1, S("3"));
4393     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 2, 2, S("34"));
4394     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 2, 3, S("345"));
4395     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 2, 4, S("345"));
4396     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 4, 0, S(""));
4397     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 4, 1, S("5"));
4398     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 4, 2, S("5"));
4399     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 5, 0, S(""));
4400     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 5, 1, S(""));
4401     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345"), 6, 0, S("can't happen"));
4402     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 0, 0, S(""));
4403     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 0, 1, S("1"));
4404     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 0, 5, S("12345"));
4405     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 0, 9, S("123456789"));
4406 }
4407 
4408 template <class S, class SV>
test41()4409 void test41()
4410 {
4411     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 0, 10, S("1234567890"));
4412     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 0, 11, S("1234567890"));
4413     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 1, 0, S(""));
4414     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 1, 1, S("2"));
4415     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 1, 4, S("2345"));
4416     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 1, 8, S("23456789"));
4417     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 1, 9, S("234567890"));
4418     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 1, 10, S("234567890"));
4419     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 5, 0, S(""));
4420     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 5, 1, S("6"));
4421     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 5, 2, S("67"));
4422     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 5, 4, S("6789"));
4423     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 5, 5, S("67890"));
4424     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 5, 6, S("67890"));
4425     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 9, 0, S(""));
4426     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 9, 1, S("0"));
4427     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 9, 2, S("0"));
4428     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 10, 0, S(""));
4429     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 10, 1, S(""));
4430     test(S("abcdefghijklmnopqrst"), 0, 21, SV("1234567890"), 11, 0, S("can't happen"));
4431     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 0, 0, S(""));
4432     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 0, 1, S("1"));
4433     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 0, 10, S("1234567890"));
4434     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 0, 19, S("1234567890123456789"));
4435     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 0, 20, S("12345678901234567890"));
4436     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 0, 21, S("12345678901234567890"));
4437     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 1, 0, S(""));
4438     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 1, 1, S("2"));
4439     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 1, 9, S("234567890"));
4440     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 1, 18, S("234567890123456789"));
4441     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 1, 19, S("2345678901234567890"));
4442     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 1, 20, S("2345678901234567890"));
4443     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 10, 0, S(""));
4444     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 10, 1, S("1"));
4445     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 10, 5, S("12345"));
4446     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 10, 9, S("123456789"));
4447     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 10, 10, S("1234567890"));
4448     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 10, 11, S("1234567890"));
4449     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 19, 0, S(""));
4450     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 19, 1, S("0"));
4451     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 19, 2, S("0"));
4452     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 20, 0, S(""));
4453     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 20, 1, S(""));
4454     test(S("abcdefghijklmnopqrst"), 0, 21, SV("12345678901234567890"), 21, 0, S("can't happen"));
4455     test(S("abcdefghijklmnopqrst"), 1, 0, SV(""), 0, 0, S("abcdefghijklmnopqrst"));
4456     test(S("abcdefghijklmnopqrst"), 1, 0, SV(""), 0, 1, S("abcdefghijklmnopqrst"));
4457     test(S("abcdefghijklmnopqrst"), 1, 0, SV(""), 1, 0, S("can't happen"));
4458     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 0, 0, S("abcdefghijklmnopqrst"));
4459     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 0, 1, S("a1bcdefghijklmnopqrst"));
4460     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 0, 2, S("a12bcdefghijklmnopqrst"));
4461     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 0, 4, S("a1234bcdefghijklmnopqrst"));
4462     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 0, 5, S("a12345bcdefghijklmnopqrst"));
4463     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 0, 6, S("a12345bcdefghijklmnopqrst"));
4464     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 1, 0, S("abcdefghijklmnopqrst"));
4465     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 1, 1, S("a2bcdefghijklmnopqrst"));
4466     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 1, 2, S("a23bcdefghijklmnopqrst"));
4467     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 1, 3, S("a234bcdefghijklmnopqrst"));
4468     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 1, 4, S("a2345bcdefghijklmnopqrst"));
4469     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 1, 5, S("a2345bcdefghijklmnopqrst"));
4470     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
4471     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 2, 1, S("a3bcdefghijklmnopqrst"));
4472     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 2, 2, S("a34bcdefghijklmnopqrst"));
4473     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 2, 3, S("a345bcdefghijklmnopqrst"));
4474     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 2, 4, S("a345bcdefghijklmnopqrst"));
4475     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 4, 0, S("abcdefghijklmnopqrst"));
4476     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 4, 1, S("a5bcdefghijklmnopqrst"));
4477     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 4, 2, S("a5bcdefghijklmnopqrst"));
4478     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 5, 0, S("abcdefghijklmnopqrst"));
4479     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 5, 1, S("abcdefghijklmnopqrst"));
4480     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345"), 6, 0, S("can't happen"));
4481     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4482     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
4483     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 0, 5, S("a12345bcdefghijklmnopqrst"));
4484     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 0, 9, S("a123456789bcdefghijklmnopqrst"));
4485     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
4486     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 0, 11, S("a1234567890bcdefghijklmnopqrst"));
4487     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4488     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
4489     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 1, 4, S("a2345bcdefghijklmnopqrst"));
4490     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 1, 8, S("a23456789bcdefghijklmnopqrst"));
4491     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
4492     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 1, 10, S("a234567890bcdefghijklmnopqrst"));
4493     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
4494     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 5, 1, S("a6bcdefghijklmnopqrst"));
4495     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 5, 2, S("a67bcdefghijklmnopqrst"));
4496     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 5, 4, S("a6789bcdefghijklmnopqrst"));
4497     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 5, 5, S("a67890bcdefghijklmnopqrst"));
4498     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 5, 6, S("a67890bcdefghijklmnopqrst"));
4499     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
4500     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 9, 1, S("a0bcdefghijklmnopqrst"));
4501     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 9, 2, S("a0bcdefghijklmnopqrst"));
4502     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4503     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
4504     test(S("abcdefghijklmnopqrst"), 1, 0, SV("1234567890"), 11, 0, S("can't happen"));
4505     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4506     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
4507     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
4508     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghijklmnopqrst"));
4509     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghijklmnopqrst"));
4510     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghijklmnopqrst"));
4511 }
4512 
4513 template <class S, class SV>
test42()4514 void test42()
4515 {
4516     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4517     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
4518     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
4519     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghijklmnopqrst"));
4520     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghijklmnopqrst"));
4521     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghijklmnopqrst"));
4522     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4523     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 10, 1, S("a1bcdefghijklmnopqrst"));
4524     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 10, 5, S("a12345bcdefghijklmnopqrst"));
4525     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 10, 9, S("a123456789bcdefghijklmnopqrst"));
4526     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 10, 10, S("a1234567890bcdefghijklmnopqrst"));
4527     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 10, 11, S("a1234567890bcdefghijklmnopqrst"));
4528     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
4529     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 19, 1, S("a0bcdefghijklmnopqrst"));
4530     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 19, 2, S("a0bcdefghijklmnopqrst"));
4531     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
4532     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
4533     test(S("abcdefghijklmnopqrst"), 1, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
4534     test(S("abcdefghijklmnopqrst"), 1, 1, SV(""), 0, 0, S("acdefghijklmnopqrst"));
4535     test(S("abcdefghijklmnopqrst"), 1, 1, SV(""), 0, 1, S("acdefghijklmnopqrst"));
4536     test(S("abcdefghijklmnopqrst"), 1, 1, SV(""), 1, 0, S("can't happen"));
4537     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 0, 0, S("acdefghijklmnopqrst"));
4538     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 0, 1, S("a1cdefghijklmnopqrst"));
4539     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 0, 2, S("a12cdefghijklmnopqrst"));
4540     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 0, 4, S("a1234cdefghijklmnopqrst"));
4541     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 0, 5, S("a12345cdefghijklmnopqrst"));
4542     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 0, 6, S("a12345cdefghijklmnopqrst"));
4543     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 1, 0, S("acdefghijklmnopqrst"));
4544     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 1, 1, S("a2cdefghijklmnopqrst"));
4545     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 1, 2, S("a23cdefghijklmnopqrst"));
4546     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 1, 3, S("a234cdefghijklmnopqrst"));
4547     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 1, 4, S("a2345cdefghijklmnopqrst"));
4548     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 1, 5, S("a2345cdefghijklmnopqrst"));
4549     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 2, 0, S("acdefghijklmnopqrst"));
4550     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 2, 1, S("a3cdefghijklmnopqrst"));
4551     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 2, 2, S("a34cdefghijklmnopqrst"));
4552     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 2, 3, S("a345cdefghijklmnopqrst"));
4553     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 2, 4, S("a345cdefghijklmnopqrst"));
4554     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 4, 0, S("acdefghijklmnopqrst"));
4555     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 4, 1, S("a5cdefghijklmnopqrst"));
4556     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 4, 2, S("a5cdefghijklmnopqrst"));
4557     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 5, 0, S("acdefghijklmnopqrst"));
4558     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 5, 1, S("acdefghijklmnopqrst"));
4559     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345"), 6, 0, S("can't happen"));
4560     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 0, 0, S("acdefghijklmnopqrst"));
4561     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 0, 1, S("a1cdefghijklmnopqrst"));
4562     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 0, 5, S("a12345cdefghijklmnopqrst"));
4563     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 0, 9, S("a123456789cdefghijklmnopqrst"));
4564     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 0, 10, S("a1234567890cdefghijklmnopqrst"));
4565     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 0, 11, S("a1234567890cdefghijklmnopqrst"));
4566     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 1, 0, S("acdefghijklmnopqrst"));
4567     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 1, 1, S("a2cdefghijklmnopqrst"));
4568     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 1, 4, S("a2345cdefghijklmnopqrst"));
4569     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 1, 8, S("a23456789cdefghijklmnopqrst"));
4570     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 1, 9, S("a234567890cdefghijklmnopqrst"));
4571     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 1, 10, S("a234567890cdefghijklmnopqrst"));
4572     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 5, 0, S("acdefghijklmnopqrst"));
4573     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 5, 1, S("a6cdefghijklmnopqrst"));
4574     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 5, 2, S("a67cdefghijklmnopqrst"));
4575     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 5, 4, S("a6789cdefghijklmnopqrst"));
4576     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 5, 5, S("a67890cdefghijklmnopqrst"));
4577     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 5, 6, S("a67890cdefghijklmnopqrst"));
4578     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 9, 0, S("acdefghijklmnopqrst"));
4579     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 9, 1, S("a0cdefghijklmnopqrst"));
4580     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 9, 2, S("a0cdefghijklmnopqrst"));
4581     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 10, 0, S("acdefghijklmnopqrst"));
4582     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 10, 1, S("acdefghijklmnopqrst"));
4583     test(S("abcdefghijklmnopqrst"), 1, 1, SV("1234567890"), 11, 0, S("can't happen"));
4584     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 0, 0, S("acdefghijklmnopqrst"));
4585     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 0, 1, S("a1cdefghijklmnopqrst"));
4586     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 0, 10, S("a1234567890cdefghijklmnopqrst"));
4587     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 0, 19, S("a1234567890123456789cdefghijklmnopqrst"));
4588     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 0, 20, S("a12345678901234567890cdefghijklmnopqrst"));
4589     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 0, 21, S("a12345678901234567890cdefghijklmnopqrst"));
4590     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 1, 0, S("acdefghijklmnopqrst"));
4591     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 1, 1, S("a2cdefghijklmnopqrst"));
4592     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 1, 9, S("a234567890cdefghijklmnopqrst"));
4593     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 1, 18, S("a234567890123456789cdefghijklmnopqrst"));
4594     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 1, 19, S("a2345678901234567890cdefghijklmnopqrst"));
4595     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 1, 20, S("a2345678901234567890cdefghijklmnopqrst"));
4596     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 10, 0, S("acdefghijklmnopqrst"));
4597     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 10, 1, S("a1cdefghijklmnopqrst"));
4598     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 10, 5, S("a12345cdefghijklmnopqrst"));
4599     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 10, 9, S("a123456789cdefghijklmnopqrst"));
4600     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 10, 10, S("a1234567890cdefghijklmnopqrst"));
4601     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 10, 11, S("a1234567890cdefghijklmnopqrst"));
4602     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 19, 0, S("acdefghijklmnopqrst"));
4603     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 19, 1, S("a0cdefghijklmnopqrst"));
4604     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 19, 2, S("a0cdefghijklmnopqrst"));
4605     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 20, 0, S("acdefghijklmnopqrst"));
4606     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 20, 1, S("acdefghijklmnopqrst"));
4607     test(S("abcdefghijklmnopqrst"), 1, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
4608     test(S("abcdefghijklmnopqrst"), 1, 9, SV(""), 0, 0, S("aklmnopqrst"));
4609     test(S("abcdefghijklmnopqrst"), 1, 9, SV(""), 0, 1, S("aklmnopqrst"));
4610     test(S("abcdefghijklmnopqrst"), 1, 9, SV(""), 1, 0, S("can't happen"));
4611     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 0, 0, S("aklmnopqrst"));
4612     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 0, 1, S("a1klmnopqrst"));
4613     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 0, 2, S("a12klmnopqrst"));
4614     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 0, 4, S("a1234klmnopqrst"));
4615     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 0, 5, S("a12345klmnopqrst"));
4616 }
4617 
4618 template <class S, class SV>
test43()4619 void test43()
4620 {
4621     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 0, 6, S("a12345klmnopqrst"));
4622     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 1, 0, S("aklmnopqrst"));
4623     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 1, 1, S("a2klmnopqrst"));
4624     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 1, 2, S("a23klmnopqrst"));
4625     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 1, 3, S("a234klmnopqrst"));
4626     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 1, 4, S("a2345klmnopqrst"));
4627     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 1, 5, S("a2345klmnopqrst"));
4628     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 2, 0, S("aklmnopqrst"));
4629     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 2, 1, S("a3klmnopqrst"));
4630     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 2, 2, S("a34klmnopqrst"));
4631     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 2, 3, S("a345klmnopqrst"));
4632     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 2, 4, S("a345klmnopqrst"));
4633     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 4, 0, S("aklmnopqrst"));
4634     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 4, 1, S("a5klmnopqrst"));
4635     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 4, 2, S("a5klmnopqrst"));
4636     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 5, 0, S("aklmnopqrst"));
4637     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 5, 1, S("aklmnopqrst"));
4638     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345"), 6, 0, S("can't happen"));
4639     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 0, 0, S("aklmnopqrst"));
4640     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 0, 1, S("a1klmnopqrst"));
4641     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 0, 5, S("a12345klmnopqrst"));
4642     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 0, 9, S("a123456789klmnopqrst"));
4643     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 0, 10, S("a1234567890klmnopqrst"));
4644     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 0, 11, S("a1234567890klmnopqrst"));
4645     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 1, 0, S("aklmnopqrst"));
4646     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 1, 1, S("a2klmnopqrst"));
4647     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 1, 4, S("a2345klmnopqrst"));
4648     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 1, 8, S("a23456789klmnopqrst"));
4649     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 1, 9, S("a234567890klmnopqrst"));
4650     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 1, 10, S("a234567890klmnopqrst"));
4651     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 5, 0, S("aklmnopqrst"));
4652     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 5, 1, S("a6klmnopqrst"));
4653     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 5, 2, S("a67klmnopqrst"));
4654     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 5, 4, S("a6789klmnopqrst"));
4655     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 5, 5, S("a67890klmnopqrst"));
4656     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 5, 6, S("a67890klmnopqrst"));
4657     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 9, 0, S("aklmnopqrst"));
4658     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 9, 1, S("a0klmnopqrst"));
4659     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 9, 2, S("a0klmnopqrst"));
4660     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 10, 0, S("aklmnopqrst"));
4661     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 10, 1, S("aklmnopqrst"));
4662     test(S("abcdefghijklmnopqrst"), 1, 9, SV("1234567890"), 11, 0, S("can't happen"));
4663     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 0, 0, S("aklmnopqrst"));
4664     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 0, 1, S("a1klmnopqrst"));
4665     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 0, 10, S("a1234567890klmnopqrst"));
4666     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 0, 19, S("a1234567890123456789klmnopqrst"));
4667     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 0, 20, S("a12345678901234567890klmnopqrst"));
4668     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 0, 21, S("a12345678901234567890klmnopqrst"));
4669     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 1, 0, S("aklmnopqrst"));
4670     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 1, 1, S("a2klmnopqrst"));
4671     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 1, 9, S("a234567890klmnopqrst"));
4672     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 1, 18, S("a234567890123456789klmnopqrst"));
4673     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 1, 19, S("a2345678901234567890klmnopqrst"));
4674     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 1, 20, S("a2345678901234567890klmnopqrst"));
4675     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 10, 0, S("aklmnopqrst"));
4676     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 10, 1, S("a1klmnopqrst"));
4677     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 10, 5, S("a12345klmnopqrst"));
4678     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 10, 9, S("a123456789klmnopqrst"));
4679     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 10, 10, S("a1234567890klmnopqrst"));
4680     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 10, 11, S("a1234567890klmnopqrst"));
4681     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 19, 0, S("aklmnopqrst"));
4682     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 19, 1, S("a0klmnopqrst"));
4683     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 19, 2, S("a0klmnopqrst"));
4684     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 20, 0, S("aklmnopqrst"));
4685     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 20, 1, S("aklmnopqrst"));
4686     test(S("abcdefghijklmnopqrst"), 1, 9, SV("12345678901234567890"), 21, 0, S("can't happen"));
4687     test(S("abcdefghijklmnopqrst"), 1, 18, SV(""), 0, 0, S("at"));
4688     test(S("abcdefghijklmnopqrst"), 1, 18, SV(""), 0, 1, S("at"));
4689     test(S("abcdefghijklmnopqrst"), 1, 18, SV(""), 1, 0, S("can't happen"));
4690     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 0, 0, S("at"));
4691     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 0, 1, S("a1t"));
4692     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 0, 2, S("a12t"));
4693     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 0, 4, S("a1234t"));
4694     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 0, 5, S("a12345t"));
4695     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 0, 6, S("a12345t"));
4696     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 1, 0, S("at"));
4697     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 1, 1, S("a2t"));
4698     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 1, 2, S("a23t"));
4699     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 1, 3, S("a234t"));
4700     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 1, 4, S("a2345t"));
4701     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 1, 5, S("a2345t"));
4702     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 2, 0, S("at"));
4703     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 2, 1, S("a3t"));
4704     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 2, 2, S("a34t"));
4705     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 2, 3, S("a345t"));
4706     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 2, 4, S("a345t"));
4707     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 4, 0, S("at"));
4708     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 4, 1, S("a5t"));
4709     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 4, 2, S("a5t"));
4710     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 5, 0, S("at"));
4711     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 5, 1, S("at"));
4712     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345"), 6, 0, S("can't happen"));
4713     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 0, 0, S("at"));
4714     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 0, 1, S("a1t"));
4715     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 0, 5, S("a12345t"));
4716     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 0, 9, S("a123456789t"));
4717     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 0, 10, S("a1234567890t"));
4718     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 0, 11, S("a1234567890t"));
4719     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 1, 0, S("at"));
4720     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 1, 1, S("a2t"));
4721 }
4722 
4723 template <class S, class SV>
test44()4724 void test44()
4725 {
4726     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 1, 4, S("a2345t"));
4727     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 1, 8, S("a23456789t"));
4728     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 1, 9, S("a234567890t"));
4729     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 1, 10, S("a234567890t"));
4730     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 5, 0, S("at"));
4731     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 5, 1, S("a6t"));
4732     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 5, 2, S("a67t"));
4733     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 5, 4, S("a6789t"));
4734     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 5, 5, S("a67890t"));
4735     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 5, 6, S("a67890t"));
4736     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 9, 0, S("at"));
4737     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 9, 1, S("a0t"));
4738     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 9, 2, S("a0t"));
4739     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 10, 0, S("at"));
4740     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 10, 1, S("at"));
4741     test(S("abcdefghijklmnopqrst"), 1, 18, SV("1234567890"), 11, 0, S("can't happen"));
4742     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 0, 0, S("at"));
4743     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 0, 1, S("a1t"));
4744     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 0, 10, S("a1234567890t"));
4745     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 0, 19, S("a1234567890123456789t"));
4746     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 0, 20, S("a12345678901234567890t"));
4747     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 0, 21, S("a12345678901234567890t"));
4748     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 1, 0, S("at"));
4749     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 1, 1, S("a2t"));
4750     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 1, 9, S("a234567890t"));
4751     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 1, 18, S("a234567890123456789t"));
4752     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 1, 19, S("a2345678901234567890t"));
4753     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 1, 20, S("a2345678901234567890t"));
4754     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 10, 0, S("at"));
4755     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 10, 1, S("a1t"));
4756     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 10, 5, S("a12345t"));
4757     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 10, 9, S("a123456789t"));
4758     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 10, 10, S("a1234567890t"));
4759     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 10, 11, S("a1234567890t"));
4760     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 19, 0, S("at"));
4761     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 19, 1, S("a0t"));
4762     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 19, 2, S("a0t"));
4763     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 20, 0, S("at"));
4764     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 20, 1, S("at"));
4765     test(S("abcdefghijklmnopqrst"), 1, 18, SV("12345678901234567890"), 21, 0, S("can't happen"));
4766     test(S("abcdefghijklmnopqrst"), 1, 19, SV(""), 0, 0, S("a"));
4767     test(S("abcdefghijklmnopqrst"), 1, 19, SV(""), 0, 1, S("a"));
4768     test(S("abcdefghijklmnopqrst"), 1, 19, SV(""), 1, 0, S("can't happen"));
4769     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 0, 0, S("a"));
4770     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 0, 1, S("a1"));
4771     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 0, 2, S("a12"));
4772     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 0, 4, S("a1234"));
4773     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 0, 5, S("a12345"));
4774     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 0, 6, S("a12345"));
4775     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 1, 0, S("a"));
4776     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 1, 1, S("a2"));
4777     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 1, 2, S("a23"));
4778     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 1, 3, S("a234"));
4779     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 1, 4, S("a2345"));
4780     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 1, 5, S("a2345"));
4781     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 2, 0, S("a"));
4782     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 2, 1, S("a3"));
4783     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 2, 2, S("a34"));
4784     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 2, 3, S("a345"));
4785     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 2, 4, S("a345"));
4786     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 4, 0, S("a"));
4787     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 4, 1, S("a5"));
4788     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 4, 2, S("a5"));
4789     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 5, 0, S("a"));
4790     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 5, 1, S("a"));
4791     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345"), 6, 0, S("can't happen"));
4792     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 0, 0, S("a"));
4793     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 0, 1, S("a1"));
4794     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 0, 5, S("a12345"));
4795     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 0, 9, S("a123456789"));
4796     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 0, 10, S("a1234567890"));
4797     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 0, 11, S("a1234567890"));
4798     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 1, 0, S("a"));
4799     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 1, 1, S("a2"));
4800     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 1, 4, S("a2345"));
4801     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 1, 8, S("a23456789"));
4802     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 1, 9, S("a234567890"));
4803     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 1, 10, S("a234567890"));
4804     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 5, 0, S("a"));
4805     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 5, 1, S("a6"));
4806     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 5, 2, S("a67"));
4807     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 5, 4, S("a6789"));
4808     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 5, 5, S("a67890"));
4809     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 5, 6, S("a67890"));
4810     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 9, 0, S("a"));
4811     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 9, 1, S("a0"));
4812     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 9, 2, S("a0"));
4813     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 10, 0, S("a"));
4814     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 10, 1, S("a"));
4815     test(S("abcdefghijklmnopqrst"), 1, 19, SV("1234567890"), 11, 0, S("can't happen"));
4816     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 0, 0, S("a"));
4817     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 0, 1, S("a1"));
4818     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 0, 10, S("a1234567890"));
4819     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 0, 19, S("a1234567890123456789"));
4820     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 0, 20, S("a12345678901234567890"));
4821     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 0, 21, S("a12345678901234567890"));
4822     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 1, 0, S("a"));
4823     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 1, 1, S("a2"));
4824     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 1, 9, S("a234567890"));
4825     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 1, 18, S("a234567890123456789"));
4826 }
4827 
4828 template <class S, class SV>
test45()4829 void test45()
4830 {
4831     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 1, 19, S("a2345678901234567890"));
4832     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 1, 20, S("a2345678901234567890"));
4833     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 10, 0, S("a"));
4834     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 10, 1, S("a1"));
4835     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 10, 5, S("a12345"));
4836     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 10, 9, S("a123456789"));
4837     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 10, 10, S("a1234567890"));
4838     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 10, 11, S("a1234567890"));
4839     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 19, 0, S("a"));
4840     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 19, 1, S("a0"));
4841     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 19, 2, S("a0"));
4842     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 20, 0, S("a"));
4843     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 20, 1, S("a"));
4844     test(S("abcdefghijklmnopqrst"), 1, 19, SV("12345678901234567890"), 21, 0, S("can't happen"));
4845     test(S("abcdefghijklmnopqrst"), 1, 20, SV(""), 0, 0, S("a"));
4846     test(S("abcdefghijklmnopqrst"), 1, 20, SV(""), 0, 1, S("a"));
4847     test(S("abcdefghijklmnopqrst"), 1, 20, SV(""), 1, 0, S("can't happen"));
4848     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 0, 0, S("a"));
4849     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 0, 1, S("a1"));
4850     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 0, 2, S("a12"));
4851     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 0, 4, S("a1234"));
4852     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 0, 5, S("a12345"));
4853     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 0, 6, S("a12345"));
4854     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 1, 0, S("a"));
4855     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 1, 1, S("a2"));
4856     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 1, 2, S("a23"));
4857     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 1, 3, S("a234"));
4858     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 1, 4, S("a2345"));
4859     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 1, 5, S("a2345"));
4860     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 2, 0, S("a"));
4861     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 2, 1, S("a3"));
4862     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 2, 2, S("a34"));
4863     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 2, 3, S("a345"));
4864     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 2, 4, S("a345"));
4865     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 4, 0, S("a"));
4866     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 4, 1, S("a5"));
4867     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 4, 2, S("a5"));
4868     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 5, 0, S("a"));
4869     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 5, 1, S("a"));
4870     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345"), 6, 0, S("can't happen"));
4871     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 0, 0, S("a"));
4872     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 0, 1, S("a1"));
4873     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 0, 5, S("a12345"));
4874     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 0, 9, S("a123456789"));
4875     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 0, 10, S("a1234567890"));
4876     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 0, 11, S("a1234567890"));
4877     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 1, 0, S("a"));
4878     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 1, 1, S("a2"));
4879     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 1, 4, S("a2345"));
4880     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 1, 8, S("a23456789"));
4881     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 1, 9, S("a234567890"));
4882     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 1, 10, S("a234567890"));
4883     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 5, 0, S("a"));
4884     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 5, 1, S("a6"));
4885     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 5, 2, S("a67"));
4886     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 5, 4, S("a6789"));
4887     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 5, 5, S("a67890"));
4888     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 5, 6, S("a67890"));
4889     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 9, 0, S("a"));
4890     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 9, 1, S("a0"));
4891     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 9, 2, S("a0"));
4892     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 10, 0, S("a"));
4893     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 10, 1, S("a"));
4894     test(S("abcdefghijklmnopqrst"), 1, 20, SV("1234567890"), 11, 0, S("can't happen"));
4895     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 0, 0, S("a"));
4896     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 0, 1, S("a1"));
4897     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 0, 10, S("a1234567890"));
4898     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 0, 19, S("a1234567890123456789"));
4899     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 0, 20, S("a12345678901234567890"));
4900     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 0, 21, S("a12345678901234567890"));
4901     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 1, 0, S("a"));
4902     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 1, 1, S("a2"));
4903     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 1, 9, S("a234567890"));
4904     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 1, 18, S("a234567890123456789"));
4905     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 1, 19, S("a2345678901234567890"));
4906     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 1, 20, S("a2345678901234567890"));
4907     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 10, 0, S("a"));
4908     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 10, 1, S("a1"));
4909     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 10, 5, S("a12345"));
4910     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 10, 9, S("a123456789"));
4911     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 10, 10, S("a1234567890"));
4912     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 10, 11, S("a1234567890"));
4913     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 19, 0, S("a"));
4914     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 19, 1, S("a0"));
4915     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 19, 2, S("a0"));
4916     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 20, 0, S("a"));
4917     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 20, 1, S("a"));
4918     test(S("abcdefghijklmnopqrst"), 1, 20, SV("12345678901234567890"), 21, 0, S("can't happen"));
4919     test(S("abcdefghijklmnopqrst"), 10, 0, SV(""), 0, 0, S("abcdefghijklmnopqrst"));
4920     test(S("abcdefghijklmnopqrst"), 10, 0, SV(""), 0, 1, S("abcdefghijklmnopqrst"));
4921     test(S("abcdefghijklmnopqrst"), 10, 0, SV(""), 1, 0, S("can't happen"));
4922     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 0, 0, S("abcdefghijklmnopqrst"));
4923     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 0, 1, S("abcdefghij1klmnopqrst"));
4924     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 0, 2, S("abcdefghij12klmnopqrst"));
4925     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 0, 4, S("abcdefghij1234klmnopqrst"));
4926     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 0, 5, S("abcdefghij12345klmnopqrst"));
4927     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 0, 6, S("abcdefghij12345klmnopqrst"));
4928     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 1, 0, S("abcdefghijklmnopqrst"));
4929     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 1, 1, S("abcdefghij2klmnopqrst"));
4930     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 1, 2, S("abcdefghij23klmnopqrst"));
4931 }
4932 
4933 template <class S, class SV>
test46()4934 void test46()
4935 {
4936     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 1, 3, S("abcdefghij234klmnopqrst"));
4937     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 1, 4, S("abcdefghij2345klmnopqrst"));
4938     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 1, 5, S("abcdefghij2345klmnopqrst"));
4939     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
4940     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 2, 1, S("abcdefghij3klmnopqrst"));
4941     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 2, 2, S("abcdefghij34klmnopqrst"));
4942     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 2, 3, S("abcdefghij345klmnopqrst"));
4943     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 2, 4, S("abcdefghij345klmnopqrst"));
4944     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 4, 0, S("abcdefghijklmnopqrst"));
4945     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 4, 1, S("abcdefghij5klmnopqrst"));
4946     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 4, 2, S("abcdefghij5klmnopqrst"));
4947     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 5, 0, S("abcdefghijklmnopqrst"));
4948     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 5, 1, S("abcdefghijklmnopqrst"));
4949     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345"), 6, 0, S("can't happen"));
4950     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4951     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
4952     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 0, 5, S("abcdefghij12345klmnopqrst"));
4953     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 0, 9, S("abcdefghij123456789klmnopqrst"));
4954     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
4955     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 0, 11, S("abcdefghij1234567890klmnopqrst"));
4956     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4957     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
4958     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 1, 4, S("abcdefghij2345klmnopqrst"));
4959     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 1, 8, S("abcdefghij23456789klmnopqrst"));
4960     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
4961     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 1, 10, S("abcdefghij234567890klmnopqrst"));
4962     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
4963     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 5, 1, S("abcdefghij6klmnopqrst"));
4964     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 5, 2, S("abcdefghij67klmnopqrst"));
4965     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 5, 4, S("abcdefghij6789klmnopqrst"));
4966     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 5, 5, S("abcdefghij67890klmnopqrst"));
4967     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 5, 6, S("abcdefghij67890klmnopqrst"));
4968     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
4969     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 9, 1, S("abcdefghij0klmnopqrst"));
4970     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 9, 2, S("abcdefghij0klmnopqrst"));
4971     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4972     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
4973     test(S("abcdefghijklmnopqrst"), 10, 0, SV("1234567890"), 11, 0, S("can't happen"));
4974     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4975     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
4976     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
4977     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789klmnopqrst"));
4978     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890klmnopqrst"));
4979     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890klmnopqrst"));
4980     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4981     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
4982     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
4983     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789klmnopqrst"));
4984     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890klmnopqrst"));
4985     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890klmnopqrst"));
4986     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4987     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 10, 1, S("abcdefghij1klmnopqrst"));
4988     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 10, 5, S("abcdefghij12345klmnopqrst"));
4989     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789klmnopqrst"));
4990     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890klmnopqrst"));
4991     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890klmnopqrst"));
4992     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
4993     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 19, 1, S("abcdefghij0klmnopqrst"));
4994     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 19, 2, S("abcdefghij0klmnopqrst"));
4995     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
4996     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
4997     test(S("abcdefghijklmnopqrst"), 10, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
4998     test(S("abcdefghijklmnopqrst"), 10, 1, SV(""), 0, 0, S("abcdefghijlmnopqrst"));
4999     test(S("abcdefghijklmnopqrst"), 10, 1, SV(""), 0, 1, S("abcdefghijlmnopqrst"));
5000     test(S("abcdefghijklmnopqrst"), 10, 1, SV(""), 1, 0, S("can't happen"));
5001     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 0, 0, S("abcdefghijlmnopqrst"));
5002     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 0, 1, S("abcdefghij1lmnopqrst"));
5003     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 0, 2, S("abcdefghij12lmnopqrst"));
5004     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 0, 4, S("abcdefghij1234lmnopqrst"));
5005     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 0, 5, S("abcdefghij12345lmnopqrst"));
5006     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 0, 6, S("abcdefghij12345lmnopqrst"));
5007     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 1, 0, S("abcdefghijlmnopqrst"));
5008     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 1, 1, S("abcdefghij2lmnopqrst"));
5009     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 1, 2, S("abcdefghij23lmnopqrst"));
5010     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 1, 3, S("abcdefghij234lmnopqrst"));
5011     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 1, 4, S("abcdefghij2345lmnopqrst"));
5012     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 1, 5, S("abcdefghij2345lmnopqrst"));
5013     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 2, 0, S("abcdefghijlmnopqrst"));
5014     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 2, 1, S("abcdefghij3lmnopqrst"));
5015     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 2, 2, S("abcdefghij34lmnopqrst"));
5016     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 2, 3, S("abcdefghij345lmnopqrst"));
5017     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 2, 4, S("abcdefghij345lmnopqrst"));
5018     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 4, 0, S("abcdefghijlmnopqrst"));
5019     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 4, 1, S("abcdefghij5lmnopqrst"));
5020     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 4, 2, S("abcdefghij5lmnopqrst"));
5021     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 5, 0, S("abcdefghijlmnopqrst"));
5022     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 5, 1, S("abcdefghijlmnopqrst"));
5023     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345"), 6, 0, S("can't happen"));
5024     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 0, 0, S("abcdefghijlmnopqrst"));
5025     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 0, 1, S("abcdefghij1lmnopqrst"));
5026     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 0, 5, S("abcdefghij12345lmnopqrst"));
5027     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 0, 9, S("abcdefghij123456789lmnopqrst"));
5028     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 0, 10, S("abcdefghij1234567890lmnopqrst"));
5029     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 0, 11, S("abcdefghij1234567890lmnopqrst"));
5030     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 1, 0, S("abcdefghijlmnopqrst"));
5031     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 1, 1, S("abcdefghij2lmnopqrst"));
5032     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 1, 4, S("abcdefghij2345lmnopqrst"));
5033     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 1, 8, S("abcdefghij23456789lmnopqrst"));
5034     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 1, 9, S("abcdefghij234567890lmnopqrst"));
5035     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 1, 10, S("abcdefghij234567890lmnopqrst"));
5036 }
5037 
5038 template <class S, class SV>
test47()5039 void test47()
5040 {
5041     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 5, 0, S("abcdefghijlmnopqrst"));
5042     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 5, 1, S("abcdefghij6lmnopqrst"));
5043     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 5, 2, S("abcdefghij67lmnopqrst"));
5044     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 5, 4, S("abcdefghij6789lmnopqrst"));
5045     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 5, 5, S("abcdefghij67890lmnopqrst"));
5046     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 5, 6, S("abcdefghij67890lmnopqrst"));
5047     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 9, 0, S("abcdefghijlmnopqrst"));
5048     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 9, 1, S("abcdefghij0lmnopqrst"));
5049     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 9, 2, S("abcdefghij0lmnopqrst"));
5050     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 10, 0, S("abcdefghijlmnopqrst"));
5051     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 10, 1, S("abcdefghijlmnopqrst"));
5052     test(S("abcdefghijklmnopqrst"), 10, 1, SV("1234567890"), 11, 0, S("can't happen"));
5053     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 0, 0, S("abcdefghijlmnopqrst"));
5054     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 0, 1, S("abcdefghij1lmnopqrst"));
5055     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890lmnopqrst"));
5056     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789lmnopqrst"));
5057     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890lmnopqrst"));
5058     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890lmnopqrst"));
5059     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 1, 0, S("abcdefghijlmnopqrst"));
5060     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 1, 1, S("abcdefghij2lmnopqrst"));
5061     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890lmnopqrst"));
5062     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789lmnopqrst"));
5063     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890lmnopqrst"));
5064     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890lmnopqrst"));
5065     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 10, 0, S("abcdefghijlmnopqrst"));
5066     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 10, 1, S("abcdefghij1lmnopqrst"));
5067     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 10, 5, S("abcdefghij12345lmnopqrst"));
5068     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789lmnopqrst"));
5069     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890lmnopqrst"));
5070     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890lmnopqrst"));
5071     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 19, 0, S("abcdefghijlmnopqrst"));
5072     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 19, 1, S("abcdefghij0lmnopqrst"));
5073     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 19, 2, S("abcdefghij0lmnopqrst"));
5074     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 20, 0, S("abcdefghijlmnopqrst"));
5075     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 20, 1, S("abcdefghijlmnopqrst"));
5076     test(S("abcdefghijklmnopqrst"), 10, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
5077     test(S("abcdefghijklmnopqrst"), 10, 5, SV(""), 0, 0, S("abcdefghijpqrst"));
5078     test(S("abcdefghijklmnopqrst"), 10, 5, SV(""), 0, 1, S("abcdefghijpqrst"));
5079     test(S("abcdefghijklmnopqrst"), 10, 5, SV(""), 1, 0, S("can't happen"));
5080     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 0, 0, S("abcdefghijpqrst"));
5081     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 0, 1, S("abcdefghij1pqrst"));
5082     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 0, 2, S("abcdefghij12pqrst"));
5083     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 0, 4, S("abcdefghij1234pqrst"));
5084     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 0, 5, S("abcdefghij12345pqrst"));
5085     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 0, 6, S("abcdefghij12345pqrst"));
5086     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 1, 0, S("abcdefghijpqrst"));
5087     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 1, 1, S("abcdefghij2pqrst"));
5088     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 1, 2, S("abcdefghij23pqrst"));
5089     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 1, 3, S("abcdefghij234pqrst"));
5090     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 1, 4, S("abcdefghij2345pqrst"));
5091     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 1, 5, S("abcdefghij2345pqrst"));
5092     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 2, 0, S("abcdefghijpqrst"));
5093     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 2, 1, S("abcdefghij3pqrst"));
5094     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 2, 2, S("abcdefghij34pqrst"));
5095     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 2, 3, S("abcdefghij345pqrst"));
5096     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 2, 4, S("abcdefghij345pqrst"));
5097     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 4, 0, S("abcdefghijpqrst"));
5098     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 4, 1, S("abcdefghij5pqrst"));
5099     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 4, 2, S("abcdefghij5pqrst"));
5100     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 5, 0, S("abcdefghijpqrst"));
5101     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 5, 1, S("abcdefghijpqrst"));
5102     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345"), 6, 0, S("can't happen"));
5103     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 0, 0, S("abcdefghijpqrst"));
5104     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 0, 1, S("abcdefghij1pqrst"));
5105     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 0, 5, S("abcdefghij12345pqrst"));
5106     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 0, 9, S("abcdefghij123456789pqrst"));
5107     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 0, 10, S("abcdefghij1234567890pqrst"));
5108     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 0, 11, S("abcdefghij1234567890pqrst"));
5109     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 1, 0, S("abcdefghijpqrst"));
5110     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 1, 1, S("abcdefghij2pqrst"));
5111     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 1, 4, S("abcdefghij2345pqrst"));
5112     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 1, 8, S("abcdefghij23456789pqrst"));
5113     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 1, 9, S("abcdefghij234567890pqrst"));
5114     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 1, 10, S("abcdefghij234567890pqrst"));
5115     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 5, 0, S("abcdefghijpqrst"));
5116     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 5, 1, S("abcdefghij6pqrst"));
5117     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 5, 2, S("abcdefghij67pqrst"));
5118     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 5, 4, S("abcdefghij6789pqrst"));
5119     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 5, 5, S("abcdefghij67890pqrst"));
5120     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 5, 6, S("abcdefghij67890pqrst"));
5121     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 9, 0, S("abcdefghijpqrst"));
5122     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 9, 1, S("abcdefghij0pqrst"));
5123     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 9, 2, S("abcdefghij0pqrst"));
5124     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 10, 0, S("abcdefghijpqrst"));
5125     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 10, 1, S("abcdefghijpqrst"));
5126     test(S("abcdefghijklmnopqrst"), 10, 5, SV("1234567890"), 11, 0, S("can't happen"));
5127     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 0, 0, S("abcdefghijpqrst"));
5128     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 0, 1, S("abcdefghij1pqrst"));
5129     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890pqrst"));
5130     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789pqrst"));
5131     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890pqrst"));
5132     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890pqrst"));
5133     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 1, 0, S("abcdefghijpqrst"));
5134     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 1, 1, S("abcdefghij2pqrst"));
5135     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890pqrst"));
5136     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789pqrst"));
5137     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890pqrst"));
5138     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890pqrst"));
5139     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 10, 0, S("abcdefghijpqrst"));
5140     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 10, 1, S("abcdefghij1pqrst"));
5141 }
5142 
5143 template <class S, class SV>
test48()5144 void test48()
5145 {
5146     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 10, 5, S("abcdefghij12345pqrst"));
5147     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789pqrst"));
5148     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890pqrst"));
5149     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890pqrst"));
5150     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 19, 0, S("abcdefghijpqrst"));
5151     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 19, 1, S("abcdefghij0pqrst"));
5152     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 19, 2, S("abcdefghij0pqrst"));
5153     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 20, 0, S("abcdefghijpqrst"));
5154     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 20, 1, S("abcdefghijpqrst"));
5155     test(S("abcdefghijklmnopqrst"), 10, 5, SV("12345678901234567890"), 21, 0, S("can't happen"));
5156     test(S("abcdefghijklmnopqrst"), 10, 9, SV(""), 0, 0, S("abcdefghijt"));
5157     test(S("abcdefghijklmnopqrst"), 10, 9, SV(""), 0, 1, S("abcdefghijt"));
5158     test(S("abcdefghijklmnopqrst"), 10, 9, SV(""), 1, 0, S("can't happen"));
5159     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 0, 0, S("abcdefghijt"));
5160     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 0, 1, S("abcdefghij1t"));
5161     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 0, 2, S("abcdefghij12t"));
5162     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 0, 4, S("abcdefghij1234t"));
5163     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 0, 5, S("abcdefghij12345t"));
5164     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 0, 6, S("abcdefghij12345t"));
5165     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 1, 0, S("abcdefghijt"));
5166     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 1, 1, S("abcdefghij2t"));
5167     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 1, 2, S("abcdefghij23t"));
5168     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 1, 3, S("abcdefghij234t"));
5169     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 1, 4, S("abcdefghij2345t"));
5170     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 1, 5, S("abcdefghij2345t"));
5171     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 2, 0, S("abcdefghijt"));
5172     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 2, 1, S("abcdefghij3t"));
5173     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 2, 2, S("abcdefghij34t"));
5174     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 2, 3, S("abcdefghij345t"));
5175     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 2, 4, S("abcdefghij345t"));
5176     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 4, 0, S("abcdefghijt"));
5177     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 4, 1, S("abcdefghij5t"));
5178     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 4, 2, S("abcdefghij5t"));
5179     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 5, 0, S("abcdefghijt"));
5180     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 5, 1, S("abcdefghijt"));
5181     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345"), 6, 0, S("can't happen"));
5182     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 0, 0, S("abcdefghijt"));
5183     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 0, 1, S("abcdefghij1t"));
5184     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 0, 5, S("abcdefghij12345t"));
5185     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 0, 9, S("abcdefghij123456789t"));
5186     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 0, 10, S("abcdefghij1234567890t"));
5187     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 0, 11, S("abcdefghij1234567890t"));
5188     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 1, 0, S("abcdefghijt"));
5189     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 1, 1, S("abcdefghij2t"));
5190     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 1, 4, S("abcdefghij2345t"));
5191     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 1, 8, S("abcdefghij23456789t"));
5192     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 1, 9, S("abcdefghij234567890t"));
5193     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 1, 10, S("abcdefghij234567890t"));
5194     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 5, 0, S("abcdefghijt"));
5195     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 5, 1, S("abcdefghij6t"));
5196     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 5, 2, S("abcdefghij67t"));
5197     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 5, 4, S("abcdefghij6789t"));
5198     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 5, 5, S("abcdefghij67890t"));
5199     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 5, 6, S("abcdefghij67890t"));
5200     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 9, 0, S("abcdefghijt"));
5201     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 9, 1, S("abcdefghij0t"));
5202     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 9, 2, S("abcdefghij0t"));
5203     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 10, 0, S("abcdefghijt"));
5204     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 10, 1, S("abcdefghijt"));
5205     test(S("abcdefghijklmnopqrst"), 10, 9, SV("1234567890"), 11, 0, S("can't happen"));
5206     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 0, 0, S("abcdefghijt"));
5207     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 0, 1, S("abcdefghij1t"));
5208     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890t"));
5209     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789t"));
5210     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890t"));
5211     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890t"));
5212     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 1, 0, S("abcdefghijt"));
5213     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 1, 1, S("abcdefghij2t"));
5214     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890t"));
5215     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789t"));
5216     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890t"));
5217     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890t"));
5218     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 10, 0, S("abcdefghijt"));
5219     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 10, 1, S("abcdefghij1t"));
5220     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 10, 5, S("abcdefghij12345t"));
5221     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789t"));
5222     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890t"));
5223     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890t"));
5224     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 19, 0, S("abcdefghijt"));
5225     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 19, 1, S("abcdefghij0t"));
5226     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 19, 2, S("abcdefghij0t"));
5227     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 20, 0, S("abcdefghijt"));
5228     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 20, 1, S("abcdefghijt"));
5229     test(S("abcdefghijklmnopqrst"), 10, 9, SV("12345678901234567890"), 21, 0, S("can't happen"));
5230     test(S("abcdefghijklmnopqrst"), 10, 10, SV(""), 0, 0, S("abcdefghij"));
5231     test(S("abcdefghijklmnopqrst"), 10, 10, SV(""), 0, 1, S("abcdefghij"));
5232     test(S("abcdefghijklmnopqrst"), 10, 10, SV(""), 1, 0, S("can't happen"));
5233     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 0, 0, S("abcdefghij"));
5234     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 0, 1, S("abcdefghij1"));
5235     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 0, 2, S("abcdefghij12"));
5236     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 0, 4, S("abcdefghij1234"));
5237     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 0, 5, S("abcdefghij12345"));
5238     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 0, 6, S("abcdefghij12345"));
5239     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 1, 0, S("abcdefghij"));
5240     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 1, 1, S("abcdefghij2"));
5241     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 1, 2, S("abcdefghij23"));
5242     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 1, 3, S("abcdefghij234"));
5243     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 1, 4, S("abcdefghij2345"));
5244     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 1, 5, S("abcdefghij2345"));
5245     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 2, 0, S("abcdefghij"));
5246 }
5247 
5248 template <class S, class SV>
test49()5249 void test49()
5250 {
5251     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 2, 1, S("abcdefghij3"));
5252     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 2, 2, S("abcdefghij34"));
5253     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 2, 3, S("abcdefghij345"));
5254     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 2, 4, S("abcdefghij345"));
5255     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 4, 0, S("abcdefghij"));
5256     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 4, 1, S("abcdefghij5"));
5257     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 4, 2, S("abcdefghij5"));
5258     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 5, 0, S("abcdefghij"));
5259     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 5, 1, S("abcdefghij"));
5260     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345"), 6, 0, S("can't happen"));
5261     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 0, 0, S("abcdefghij"));
5262     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 0, 1, S("abcdefghij1"));
5263     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 0, 5, S("abcdefghij12345"));
5264     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 0, 9, S("abcdefghij123456789"));
5265     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 0, 10, S("abcdefghij1234567890"));
5266     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 0, 11, S("abcdefghij1234567890"));
5267     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 1, 0, S("abcdefghij"));
5268     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 1, 1, S("abcdefghij2"));
5269     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 1, 4, S("abcdefghij2345"));
5270     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 1, 8, S("abcdefghij23456789"));
5271     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 1, 9, S("abcdefghij234567890"));
5272     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 1, 10, S("abcdefghij234567890"));
5273     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 5, 0, S("abcdefghij"));
5274     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 5, 1, S("abcdefghij6"));
5275     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 5, 2, S("abcdefghij67"));
5276     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 5, 4, S("abcdefghij6789"));
5277     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 5, 5, S("abcdefghij67890"));
5278     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 5, 6, S("abcdefghij67890"));
5279     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 9, 0, S("abcdefghij"));
5280     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 9, 1, S("abcdefghij0"));
5281     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 9, 2, S("abcdefghij0"));
5282     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 10, 0, S("abcdefghij"));
5283     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 10, 1, S("abcdefghij"));
5284     test(S("abcdefghijklmnopqrst"), 10, 10, SV("1234567890"), 11, 0, S("can't happen"));
5285     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
5286     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 0, 1, S("abcdefghij1"));
5287     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
5288     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
5289     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
5290     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
5291     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
5292     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 1, 1, S("abcdefghij2"));
5293     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
5294     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
5295     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
5296     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
5297     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
5298     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 10, 1, S("abcdefghij1"));
5299     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 10, 5, S("abcdefghij12345"));
5300     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
5301     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
5302     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
5303     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
5304     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 19, 1, S("abcdefghij0"));
5305     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 19, 2, S("abcdefghij0"));
5306     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
5307     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
5308     test(S("abcdefghijklmnopqrst"), 10, 10, SV("12345678901234567890"), 21, 0, S("can't happen"));
5309     test(S("abcdefghijklmnopqrst"), 10, 11, SV(""), 0, 0, S("abcdefghij"));
5310     test(S("abcdefghijklmnopqrst"), 10, 11, SV(""), 0, 1, S("abcdefghij"));
5311     test(S("abcdefghijklmnopqrst"), 10, 11, SV(""), 1, 0, S("can't happen"));
5312     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 0, 0, S("abcdefghij"));
5313     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 0, 1, S("abcdefghij1"));
5314     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 0, 2, S("abcdefghij12"));
5315     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 0, 4, S("abcdefghij1234"));
5316     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 0, 5, S("abcdefghij12345"));
5317     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 0, 6, S("abcdefghij12345"));
5318     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 1, 0, S("abcdefghij"));
5319     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 1, 1, S("abcdefghij2"));
5320     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 1, 2, S("abcdefghij23"));
5321     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 1, 3, S("abcdefghij234"));
5322     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 1, 4, S("abcdefghij2345"));
5323     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 1, 5, S("abcdefghij2345"));
5324     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 2, 0, S("abcdefghij"));
5325     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 2, 1, S("abcdefghij3"));
5326     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 2, 2, S("abcdefghij34"));
5327     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 2, 3, S("abcdefghij345"));
5328     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 2, 4, S("abcdefghij345"));
5329     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 4, 0, S("abcdefghij"));
5330     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 4, 1, S("abcdefghij5"));
5331     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 4, 2, S("abcdefghij5"));
5332     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 5, 0, S("abcdefghij"));
5333     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 5, 1, S("abcdefghij"));
5334     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345"), 6, 0, S("can't happen"));
5335     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 0, 0, S("abcdefghij"));
5336     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 0, 1, S("abcdefghij1"));
5337     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 0, 5, S("abcdefghij12345"));
5338     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 0, 9, S("abcdefghij123456789"));
5339     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 0, 10, S("abcdefghij1234567890"));
5340     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 0, 11, S("abcdefghij1234567890"));
5341     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 1, 0, S("abcdefghij"));
5342     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 1, 1, S("abcdefghij2"));
5343     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 1, 4, S("abcdefghij2345"));
5344     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 1, 8, S("abcdefghij23456789"));
5345     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 1, 9, S("abcdefghij234567890"));
5346     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 1, 10, S("abcdefghij234567890"));
5347     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 5, 0, S("abcdefghij"));
5348     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 5, 1, S("abcdefghij6"));
5349     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 5, 2, S("abcdefghij67"));
5350     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 5, 4, S("abcdefghij6789"));
5351 }
5352 
5353 template <class S, class SV>
test50()5354 void test50()
5355 {
5356     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 5, 5, S("abcdefghij67890"));
5357     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 5, 6, S("abcdefghij67890"));
5358     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 9, 0, S("abcdefghij"));
5359     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 9, 1, S("abcdefghij0"));
5360     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 9, 2, S("abcdefghij0"));
5361     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 10, 0, S("abcdefghij"));
5362     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 10, 1, S("abcdefghij"));
5363     test(S("abcdefghijklmnopqrst"), 10, 11, SV("1234567890"), 11, 0, S("can't happen"));
5364     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 0, 0, S("abcdefghij"));
5365     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 0, 1, S("abcdefghij1"));
5366     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
5367     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
5368     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
5369     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
5370     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 1, 0, S("abcdefghij"));
5371     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 1, 1, S("abcdefghij2"));
5372     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
5373     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
5374     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
5375     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
5376     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 10, 0, S("abcdefghij"));
5377     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 10, 1, S("abcdefghij1"));
5378     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 10, 5, S("abcdefghij12345"));
5379     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
5380     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
5381     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
5382     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 19, 0, S("abcdefghij"));
5383     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 19, 1, S("abcdefghij0"));
5384     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 19, 2, S("abcdefghij0"));
5385     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 20, 0, S("abcdefghij"));
5386     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 20, 1, S("abcdefghij"));
5387     test(S("abcdefghijklmnopqrst"), 10, 11, SV("12345678901234567890"), 21, 0, S("can't happen"));
5388     test(S("abcdefghijklmnopqrst"), 19, 0, SV(""), 0, 0, S("abcdefghijklmnopqrst"));
5389     test(S("abcdefghijklmnopqrst"), 19, 0, SV(""), 0, 1, S("abcdefghijklmnopqrst"));
5390     test(S("abcdefghijklmnopqrst"), 19, 0, SV(""), 1, 0, S("can't happen"));
5391     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 0, 0, S("abcdefghijklmnopqrst"));
5392     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 0, 1, S("abcdefghijklmnopqrs1t"));
5393     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 0, 2, S("abcdefghijklmnopqrs12t"));
5394     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 0, 4, S("abcdefghijklmnopqrs1234t"));
5395     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 0, 5, S("abcdefghijklmnopqrs12345t"));
5396     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 0, 6, S("abcdefghijklmnopqrs12345t"));
5397     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 1, 0, S("abcdefghijklmnopqrst"));
5398     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 1, 1, S("abcdefghijklmnopqrs2t"));
5399     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 1, 2, S("abcdefghijklmnopqrs23t"));
5400     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 1, 3, S("abcdefghijklmnopqrs234t"));
5401     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 1, 4, S("abcdefghijklmnopqrs2345t"));
5402     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 1, 5, S("abcdefghijklmnopqrs2345t"));
5403     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
5404     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 2, 1, S("abcdefghijklmnopqrs3t"));
5405     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 2, 2, S("abcdefghijklmnopqrs34t"));
5406     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 2, 3, S("abcdefghijklmnopqrs345t"));
5407     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 2, 4, S("abcdefghijklmnopqrs345t"));
5408     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 4, 0, S("abcdefghijklmnopqrst"));
5409     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 4, 1, S("abcdefghijklmnopqrs5t"));
5410     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 4, 2, S("abcdefghijklmnopqrs5t"));
5411     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 5, 0, S("abcdefghijklmnopqrst"));
5412     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 5, 1, S("abcdefghijklmnopqrst"));
5413     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345"), 6, 0, S("can't happen"));
5414     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5415     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
5416     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345t"));
5417     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789t"));
5418     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
5419     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890t"));
5420     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5421     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
5422     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345t"));
5423     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789t"));
5424     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
5425     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890t"));
5426     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
5427     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 5, 1, S("abcdefghijklmnopqrs6t"));
5428     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 5, 2, S("abcdefghijklmnopqrs67t"));
5429     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789t"));
5430     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890t"));
5431     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890t"));
5432     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
5433     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 9, 1, S("abcdefghijklmnopqrs0t"));
5434     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 9, 2, S("abcdefghijklmnopqrs0t"));
5435     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5436     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
5437     test(S("abcdefghijklmnopqrst"), 19, 0, SV("1234567890"), 11, 0, S("can't happen"));
5438     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5439     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
5440     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
5441     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789t"));
5442     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890t"));
5443     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890t"));
5444     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5445     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
5446     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
5447     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789t"));
5448     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890t"));
5449     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890t"));
5450     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5451     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1t"));
5452     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345t"));
5453     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789t"));
5454     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890t"));
5455     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890t"));
5456 }
5457 
5458 template <class S, class SV>
test51()5459 void test51()
5460 {
5461     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
5462     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0t"));
5463     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0t"));
5464     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
5465     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
5466     test(S("abcdefghijklmnopqrst"), 19, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
5467     test(S("abcdefghijklmnopqrst"), 19, 1, SV(""), 0, 0, S("abcdefghijklmnopqrs"));
5468     test(S("abcdefghijklmnopqrst"), 19, 1, SV(""), 0, 1, S("abcdefghijklmnopqrs"));
5469     test(S("abcdefghijklmnopqrst"), 19, 1, SV(""), 1, 0, S("can't happen"));
5470     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 0, 0, S("abcdefghijklmnopqrs"));
5471     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 0, 1, S("abcdefghijklmnopqrs1"));
5472     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 0, 2, S("abcdefghijklmnopqrs12"));
5473     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 0, 4, S("abcdefghijklmnopqrs1234"));
5474     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 0, 5, S("abcdefghijklmnopqrs12345"));
5475     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 0, 6, S("abcdefghijklmnopqrs12345"));
5476     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 1, 0, S("abcdefghijklmnopqrs"));
5477     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 1, 1, S("abcdefghijklmnopqrs2"));
5478     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 1, 2, S("abcdefghijklmnopqrs23"));
5479     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 1, 3, S("abcdefghijklmnopqrs234"));
5480     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 1, 4, S("abcdefghijklmnopqrs2345"));
5481     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 1, 5, S("abcdefghijklmnopqrs2345"));
5482     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 2, 0, S("abcdefghijklmnopqrs"));
5483     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 2, 1, S("abcdefghijklmnopqrs3"));
5484     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 2, 2, S("abcdefghijklmnopqrs34"));
5485     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 2, 3, S("abcdefghijklmnopqrs345"));
5486     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 2, 4, S("abcdefghijklmnopqrs345"));
5487     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 4, 0, S("abcdefghijklmnopqrs"));
5488     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 4, 1, S("abcdefghijklmnopqrs5"));
5489     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 4, 2, S("abcdefghijklmnopqrs5"));
5490     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 5, 0, S("abcdefghijklmnopqrs"));
5491     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 5, 1, S("abcdefghijklmnopqrs"));
5492     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345"), 6, 0, S("can't happen"));
5493     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5494     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5495     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345"));
5496     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789"));
5497     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5498     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890"));
5499     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5500     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5501     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345"));
5502     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789"));
5503     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5504     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890"));
5505     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrs"));
5506     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 5, 1, S("abcdefghijklmnopqrs6"));
5507     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 5, 2, S("abcdefghijklmnopqrs67"));
5508     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789"));
5509     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890"));
5510     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890"));
5511     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrs"));
5512     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 9, 1, S("abcdefghijklmnopqrs0"));
5513     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 9, 2, S("abcdefghijklmnopqrs0"));
5514     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5515     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrs"));
5516     test(S("abcdefghijklmnopqrst"), 19, 1, SV("1234567890"), 11, 0, S("can't happen"));
5517     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5518     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5519     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5520     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789"));
5521     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890"));
5522     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890"));
5523     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5524     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5525     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5526     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789"));
5527     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890"));
5528     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890"));
5529     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5530     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1"));
5531     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345"));
5532     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789"));
5533     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890"));
5534     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890"));
5535     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrs"));
5536     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0"));
5537     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0"));
5538     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrs"));
5539     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrs"));
5540     test(S("abcdefghijklmnopqrst"), 19, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
5541     test(S("abcdefghijklmnopqrst"), 19, 2, SV(""), 0, 0, S("abcdefghijklmnopqrs"));
5542     test(S("abcdefghijklmnopqrst"), 19, 2, SV(""), 0, 1, S("abcdefghijklmnopqrs"));
5543     test(S("abcdefghijklmnopqrst"), 19, 2, SV(""), 1, 0, S("can't happen"));
5544     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 0, 0, S("abcdefghijklmnopqrs"));
5545     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 0, 1, S("abcdefghijklmnopqrs1"));
5546     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 0, 2, S("abcdefghijklmnopqrs12"));
5547     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 0, 4, S("abcdefghijklmnopqrs1234"));
5548     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 0, 5, S("abcdefghijklmnopqrs12345"));
5549     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 0, 6, S("abcdefghijklmnopqrs12345"));
5550     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 1, 0, S("abcdefghijklmnopqrs"));
5551     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 1, 1, S("abcdefghijklmnopqrs2"));
5552     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 1, 2, S("abcdefghijklmnopqrs23"));
5553     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 1, 3, S("abcdefghijklmnopqrs234"));
5554     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 1, 4, S("abcdefghijklmnopqrs2345"));
5555     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 1, 5, S("abcdefghijklmnopqrs2345"));
5556     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 2, 0, S("abcdefghijklmnopqrs"));
5557     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 2, 1, S("abcdefghijklmnopqrs3"));
5558     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 2, 2, S("abcdefghijklmnopqrs34"));
5559     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 2, 3, S("abcdefghijklmnopqrs345"));
5560     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 2, 4, S("abcdefghijklmnopqrs345"));
5561 }
5562 
5563 template <class S, class SV>
test52()5564 void test52()
5565 {
5566     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 4, 0, S("abcdefghijklmnopqrs"));
5567     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 4, 1, S("abcdefghijklmnopqrs5"));
5568     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 4, 2, S("abcdefghijklmnopqrs5"));
5569     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 5, 0, S("abcdefghijklmnopqrs"));
5570     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 5, 1, S("abcdefghijklmnopqrs"));
5571     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345"), 6, 0, S("can't happen"));
5572     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5573     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5574     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345"));
5575     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789"));
5576     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5577     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890"));
5578     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5579     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5580     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345"));
5581     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789"));
5582     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5583     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890"));
5584     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrs"));
5585     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 5, 1, S("abcdefghijklmnopqrs6"));
5586     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 5, 2, S("abcdefghijklmnopqrs67"));
5587     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789"));
5588     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890"));
5589     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890"));
5590     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrs"));
5591     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 9, 1, S("abcdefghijklmnopqrs0"));
5592     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 9, 2, S("abcdefghijklmnopqrs0"));
5593     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5594     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrs"));
5595     test(S("abcdefghijklmnopqrst"), 19, 2, SV("1234567890"), 11, 0, S("can't happen"));
5596     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5597     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5598     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5599     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789"));
5600     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890"));
5601     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890"));
5602     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5603     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5604     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5605     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789"));
5606     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890"));
5607     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890"));
5608     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5609     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1"));
5610     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345"));
5611     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789"));
5612     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890"));
5613     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890"));
5614     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrs"));
5615     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0"));
5616     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0"));
5617     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrs"));
5618     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrs"));
5619     test(S("abcdefghijklmnopqrst"), 19, 2, SV("12345678901234567890"), 21, 0, S("can't happen"));
5620     test(S("abcdefghijklmnopqrst"), 20, 0, SV(""), 0, 0, S("abcdefghijklmnopqrst"));
5621     test(S("abcdefghijklmnopqrst"), 20, 0, SV(""), 0, 1, S("abcdefghijklmnopqrst"));
5622     test(S("abcdefghijklmnopqrst"), 20, 0, SV(""), 1, 0, S("can't happen"));
5623     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 0, 0, S("abcdefghijklmnopqrst"));
5624     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 0, 1, S("abcdefghijklmnopqrst1"));
5625     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 0, 2, S("abcdefghijklmnopqrst12"));
5626     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 0, 4, S("abcdefghijklmnopqrst1234"));
5627     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 0, 5, S("abcdefghijklmnopqrst12345"));
5628     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 0, 6, S("abcdefghijklmnopqrst12345"));
5629     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 1, 0, S("abcdefghijklmnopqrst"));
5630     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 1, 1, S("abcdefghijklmnopqrst2"));
5631     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 1, 2, S("abcdefghijklmnopqrst23"));
5632     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 1, 3, S("abcdefghijklmnopqrst234"));
5633     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 1, 4, S("abcdefghijklmnopqrst2345"));
5634     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 1, 5, S("abcdefghijklmnopqrst2345"));
5635     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
5636     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
5637     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
5638     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
5639     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
5640     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 4, 0, S("abcdefghijklmnopqrst"));
5641     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 4, 1, S("abcdefghijklmnopqrst5"));
5642     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 4, 2, S("abcdefghijklmnopqrst5"));
5643     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 5, 0, S("abcdefghijklmnopqrst"));
5644     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 5, 1, S("abcdefghijklmnopqrst"));
5645     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345"), 6, 0, S("can't happen"));
5646     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5647     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5648     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 0, 5, S("abcdefghijklmnopqrst12345"));
5649     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 0, 9, S("abcdefghijklmnopqrst123456789"));
5650     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5651     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 0, 11, S("abcdefghijklmnopqrst1234567890"));
5652     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5653     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5654     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 1, 4, S("abcdefghijklmnopqrst2345"));
5655     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 1, 8, S("abcdefghijklmnopqrst23456789"));
5656     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5657     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 1, 10, S("abcdefghijklmnopqrst234567890"));
5658     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
5659     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 5, 1, S("abcdefghijklmnopqrst6"));
5660     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 5, 2, S("abcdefghijklmnopqrst67"));
5661     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 5, 4, S("abcdefghijklmnopqrst6789"));
5662     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 5, 5, S("abcdefghijklmnopqrst67890"));
5663     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 5, 6, S("abcdefghijklmnopqrst67890"));
5664     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
5665     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 9, 1, S("abcdefghijklmnopqrst0"));
5666 }
5667 
5668 template <class S, class SV>
test53()5669 void test53()
5670 {
5671     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 9, 2, S("abcdefghijklmnopqrst0"));
5672     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5673     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
5674     test(S("abcdefghijklmnopqrst"), 20, 0, SV("1234567890"), 11, 0, S("can't happen"));
5675     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5676     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5677     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5678     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrst1234567890123456789"));
5679     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrst12345678901234567890"));
5680     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrst12345678901234567890"));
5681     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5682     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5683     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5684     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrst234567890123456789"));
5685     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrst2345678901234567890"));
5686     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrst2345678901234567890"));
5687     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5688     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrst1"));
5689     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrst12345"));
5690     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
5691     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
5692     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
5693     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
5694     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
5695     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrst0"));
5696     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
5697     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
5698     test(S("abcdefghijklmnopqrst"), 20, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
5699     test(S("abcdefghijklmnopqrst"), 20, 1, SV(""), 0, 0, S("abcdefghijklmnopqrst"));
5700     test(S("abcdefghijklmnopqrst"), 20, 1, SV(""), 0, 1, S("abcdefghijklmnopqrst"));
5701     test(S("abcdefghijklmnopqrst"), 20, 1, SV(""), 1, 0, S("can't happen"));
5702     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 0, 0, S("abcdefghijklmnopqrst"));
5703     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 0, 1, S("abcdefghijklmnopqrst1"));
5704     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 0, 2, S("abcdefghijklmnopqrst12"));
5705     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 0, 4, S("abcdefghijklmnopqrst1234"));
5706     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 0, 5, S("abcdefghijklmnopqrst12345"));
5707     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 0, 6, S("abcdefghijklmnopqrst12345"));
5708     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 1, 0, S("abcdefghijklmnopqrst"));
5709     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 1, 1, S("abcdefghijklmnopqrst2"));
5710     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 1, 2, S("abcdefghijklmnopqrst23"));
5711     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 1, 3, S("abcdefghijklmnopqrst234"));
5712     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 1, 4, S("abcdefghijklmnopqrst2345"));
5713     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 1, 5, S("abcdefghijklmnopqrst2345"));
5714     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 2, 0, S("abcdefghijklmnopqrst"));
5715     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
5716     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
5717     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
5718     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
5719     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 4, 0, S("abcdefghijklmnopqrst"));
5720     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 4, 1, S("abcdefghijklmnopqrst5"));
5721     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 4, 2, S("abcdefghijklmnopqrst5"));
5722     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 5, 0, S("abcdefghijklmnopqrst"));
5723     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 5, 1, S("abcdefghijklmnopqrst"));
5724     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345"), 6, 0, S("can't happen"));
5725     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5726     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5727     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 0, 5, S("abcdefghijklmnopqrst12345"));
5728     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 0, 9, S("abcdefghijklmnopqrst123456789"));
5729     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5730     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 0, 11, S("abcdefghijklmnopqrst1234567890"));
5731     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5732     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5733     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 1, 4, S("abcdefghijklmnopqrst2345"));
5734     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 1, 8, S("abcdefghijklmnopqrst23456789"));
5735     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5736     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 1, 10, S("abcdefghijklmnopqrst234567890"));
5737     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
5738     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 5, 1, S("abcdefghijklmnopqrst6"));
5739     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 5, 2, S("abcdefghijklmnopqrst67"));
5740     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 5, 4, S("abcdefghijklmnopqrst6789"));
5741     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 5, 5, S("abcdefghijklmnopqrst67890"));
5742     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 5, 6, S("abcdefghijklmnopqrst67890"));
5743     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
5744     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 9, 1, S("abcdefghijklmnopqrst0"));
5745     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 9, 2, S("abcdefghijklmnopqrst0"));
5746     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5747     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
5748     test(S("abcdefghijklmnopqrst"), 20, 1, SV("1234567890"), 11, 0, S("can't happen"));
5749     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5750     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5751     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5752     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrst1234567890123456789"));
5753     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrst12345678901234567890"));
5754     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrst12345678901234567890"));
5755     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5756     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5757     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5758     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrst234567890123456789"));
5759     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrst2345678901234567890"));
5760     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrst2345678901234567890"));
5761     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5762     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrst1"));
5763     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrst12345"));
5764     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
5765     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
5766     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
5767     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
5768     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
5769     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrst0"));
5770     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
5771 }
5772 
5773 template <class S, class SV>
test54()5774 void test54()
5775 {
5776     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
5777     test(S("abcdefghijklmnopqrst"), 20, 1, SV("12345678901234567890"), 21, 0, S("can't happen"));
5778     test(S("abcdefghijklmnopqrst"), 21, 0, SV(""), 0, 0, S("can't happen"));
5779     test(S("abcdefghijklmnopqrst"), 21, 0, SV(""), 0, 1, S("can't happen"));
5780     test(S("abcdefghijklmnopqrst"), 21, 0, SV(""), 1, 0, S("can't happen"));
5781     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 0, 0, S("can't happen"));
5782     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 0, 1, S("can't happen"));
5783     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 0, 2, S("can't happen"));
5784     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 0, 4, S("can't happen"));
5785     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 0, 5, S("can't happen"));
5786     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 0, 6, S("can't happen"));
5787     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 1, 0, S("can't happen"));
5788     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 1, 1, S("can't happen"));
5789     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 1, 2, S("can't happen"));
5790     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 1, 3, S("can't happen"));
5791     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 1, 4, S("can't happen"));
5792     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 1, 5, S("can't happen"));
5793     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 2, 0, S("can't happen"));
5794     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 2, 1, S("can't happen"));
5795     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 2, 2, S("can't happen"));
5796     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 2, 3, S("can't happen"));
5797     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 2, 4, S("can't happen"));
5798     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 4, 0, S("can't happen"));
5799     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 4, 1, S("can't happen"));
5800     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 4, 2, S("can't happen"));
5801     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 5, 0, S("can't happen"));
5802     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 5, 1, S("can't happen"));
5803     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345"), 6, 0, S("can't happen"));
5804     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 0, 0, S("can't happen"));
5805     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 0, 1, S("can't happen"));
5806     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 0, 5, S("can't happen"));
5807     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 0, 9, S("can't happen"));
5808     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 0, 10, S("can't happen"));
5809     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 0, 11, S("can't happen"));
5810     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 1, 0, S("can't happen"));
5811     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 1, 1, S("can't happen"));
5812     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 1, 4, S("can't happen"));
5813     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 1, 8, S("can't happen"));
5814     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 1, 9, S("can't happen"));
5815     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 1, 10, S("can't happen"));
5816     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 5, 0, S("can't happen"));
5817     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 5, 1, S("can't happen"));
5818     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 5, 2, S("can't happen"));
5819     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 5, 4, S("can't happen"));
5820     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 5, 5, S("can't happen"));
5821     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 5, 6, S("can't happen"));
5822     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 9, 0, S("can't happen"));
5823     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 9, 1, S("can't happen"));
5824     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 9, 2, S("can't happen"));
5825     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 10, 0, S("can't happen"));
5826     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 10, 1, S("can't happen"));
5827     test(S("abcdefghijklmnopqrst"), 21, 0, SV("1234567890"), 11, 0, S("can't happen"));
5828     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 0, 0, S("can't happen"));
5829     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 0, 1, S("can't happen"));
5830     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 0, 10, S("can't happen"));
5831     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 0, 19, S("can't happen"));
5832     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 0, 20, S("can't happen"));
5833     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 0, 21, S("can't happen"));
5834     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 1, 0, S("can't happen"));
5835     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 1, 1, S("can't happen"));
5836     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 1, 9, S("can't happen"));
5837     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 1, 18, S("can't happen"));
5838     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 1, 19, S("can't happen"));
5839     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 1, 20, S("can't happen"));
5840     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 10, 0, S("can't happen"));
5841     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 10, 1, S("can't happen"));
5842     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 10, 5, S("can't happen"));
5843     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 10, 9, S("can't happen"));
5844     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 10, 10, S("can't happen"));
5845     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 10, 11, S("can't happen"));
5846     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 19, 0, S("can't happen"));
5847     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 19, 1, S("can't happen"));
5848     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 19, 2, S("can't happen"));
5849     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 20, 0, S("can't happen"));
5850     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 20, 1, S("can't happen"));
5851     test(S("abcdefghijklmnopqrst"), 21, 0, SV("12345678901234567890"), 21, 0, S("can't happen"));
5852 }
5853 
5854 template <class S, class SV>
test55()5855 void test55()
5856 {
5857     test_npos(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 10, S("abcdefghi1234567890"));
5858     test_npos(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 19, S("abcdefghi0"));
5859     test_npos(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 20, S("abcdefghi"));
5860     test_npos(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 20, S("abcdefghi"));
5861     test_npos(S("abcdefghij"), 9, 1, SV("12345678901234567890"), 21, S("can't happen"));
5862     test_npos(S("abcdefghij"), 9, 2, SV(""), 0, S("abcdefghi"));
5863     test_npos(S("abcdefghij"), 9, 2, SV(""), 1, S("can't happen"));
5864     test_npos(S("abcdefghij"), 9, 2, SV("12345"), 0, S("abcdefghi12345"));
5865     test_npos(S("abcdefghij"), 9, 2, SV("12345"), 1, S("abcdefghi2345"));
5866     test_npos(S("abcdefghij"), 9, 2, SV("12345"), 2, S("abcdefghi345"));
5867     test_npos(S("abcdefghij"), 9, 2, SV("12345"), 4, S("abcdefghi5"));
5868     test_npos(S("abcdefghij"), 9, 2, SV("12345"), 5, S("abcdefghi"));
5869     test_npos(S("abcdefghij"), 9, 2, SV("12345"), 6, S("can't happen"));
5870 }
5871 
main(int,char **)5872 int main(int, char**)
5873 {
5874     {
5875     typedef std::string S;
5876     typedef std::string_view SV;
5877     test0<S, SV>();
5878     test1<S, SV>();
5879     test2<S, SV>();
5880     test3<S, SV>();
5881     test4<S, SV>();
5882     test5<S, SV>();
5883     test6<S, SV>();
5884     test7<S, SV>();
5885     test8<S, SV>();
5886     test9<S, SV>();
5887     test10<S, SV>();
5888     test11<S, SV>();
5889     test12<S, SV>();
5890     test13<S, SV>();
5891     test14<S, SV>();
5892     test15<S, SV>();
5893     test16<S, SV>();
5894     test17<S, SV>();
5895     test18<S, SV>();
5896     test19<S, SV>();
5897     test20<S, SV>();
5898     test21<S, SV>();
5899     test22<S, SV>();
5900     test23<S, SV>();
5901     test24<S, SV>();
5902     test25<S, SV>();
5903     test26<S, SV>();
5904     test27<S, SV>();
5905     test28<S, SV>();
5906     test29<S, SV>();
5907     test30<S, SV>();
5908     test31<S, SV>();
5909     test32<S, SV>();
5910     test33<S, SV>();
5911     test34<S, SV>();
5912     test35<S, SV>();
5913     test36<S, SV>();
5914     test37<S, SV>();
5915     test38<S, SV>();
5916     test39<S, SV>();
5917     test40<S, SV>();
5918     test41<S, SV>();
5919     test42<S, SV>();
5920     test43<S, SV>();
5921     test44<S, SV>();
5922     test45<S, SV>();
5923     test46<S, SV>();
5924     test47<S, SV>();
5925     test48<S, SV>();
5926     test49<S, SV>();
5927     test50<S, SV>();
5928     test51<S, SV>();
5929     test52<S, SV>();
5930     test53<S, SV>();
5931     test54<S, SV>();
5932     test55<S, SV>();
5933     }
5934 #if TEST_STD_VER >= 11
5935     {
5936     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
5937     typedef std::basic_string_view<char, std::char_traits<char>> SV;
5938     test0<S, SV>();
5939     test1<S, SV>();
5940     test2<S, SV>();
5941     test3<S, SV>();
5942     test4<S, SV>();
5943     test5<S, SV>();
5944     test6<S, SV>();
5945     test7<S, SV>();
5946     test8<S, SV>();
5947     test9<S, SV>();
5948     test10<S, SV>();
5949     test11<S, SV>();
5950     test12<S, SV>();
5951     test13<S, SV>();
5952     test14<S, SV>();
5953     test15<S, SV>();
5954     test16<S, SV>();
5955     test17<S, SV>();
5956     test18<S, SV>();
5957     test19<S, SV>();
5958     test20<S, SV>();
5959     test21<S, SV>();
5960     test22<S, SV>();
5961     test23<S, SV>();
5962     test24<S, SV>();
5963     test25<S, SV>();
5964     test26<S, SV>();
5965     test27<S, SV>();
5966     test28<S, SV>();
5967     test29<S, SV>();
5968     test30<S, SV>();
5969     test31<S, SV>();
5970     test32<S, SV>();
5971     test33<S, SV>();
5972     test34<S, SV>();
5973     test35<S, SV>();
5974     test36<S, SV>();
5975     test37<S, SV>();
5976     test38<S, SV>();
5977     test39<S, SV>();
5978     test40<S, SV>();
5979     test41<S, SV>();
5980     test42<S, SV>();
5981     test43<S, SV>();
5982     test44<S, SV>();
5983     test45<S, SV>();
5984     test46<S, SV>();
5985     test47<S, SV>();
5986     test48<S, SV>();
5987     test49<S, SV>();
5988     test50<S, SV>();
5989     test51<S, SV>();
5990     test52<S, SV>();
5991     test53<S, SV>();
5992     test54<S, SV>();
5993     test55<S, SV>();
5994     }
5995 #endif
5996     {
5997     typedef std::string S;
5998     typedef std::string_view SV;
5999     S s0 = "ABCD";
6000     S s;
6001     SV sv = "EFGH";
6002     char arr[] = "IJKL";
6003 
6004     s = s0;
6005     s.replace(0, 4, "CDEF", 0);    // calls replace(pos1, n1, const char *, len)
6006     assert(s == "");
6007 
6008     s = s0;
6009     s.replace(0, 4, "QRST", 0, std::string::npos); // calls replace(pos1, n1, string("QRST"), pos, npos)
6010     assert(s == "QRST");
6011 
6012     s = s0;
6013     s.replace(0, 4, sv, 0);  // calls replace(pos1, n1, T, pos, npos)
6014     assert(s == sv);
6015 
6016     s = s0;
6017     s.replace(0, 4, sv, 0, std::string::npos);   // calls replace(pos1, n1, T, pos, npos)
6018     assert(s == sv);
6019 
6020     s = s0;
6021     s.replace(0, 4, arr, 0);     // calls replace(pos1, n1, const char *, len)
6022     assert(s == "");
6023 
6024     s = s0;
6025     s.replace(0, 4, arr, 0, std::string::npos);    // calls replace(pos1, n1, string("IJKL"), pos, npos)
6026     assert(s == "IJKL");
6027     }
6028 
6029   return 0;
6030 }
6031