1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// basic_string<charT,traits,Allocator>&
13//   replace(size_type pos1, size_type n1, const basic_string<charT,traits,Allocator>& str,
14//           size_type pos2, size_type n2=npos);
15//  the "=npos" was added in C++14
16
17#include <string>
18#include <stdexcept>
19#include <algorithm>
20#include <cassert>
21
22#include "min_allocator.h"
23
24template <class S>
25void
26test(S s, typename S::size_type pos1, typename S::size_type n1,
27     S str, typename S::size_type pos2, typename S::size_type n2,
28     S expected)
29{
30    typename S::size_type old_size = s.size();
31    S s0 = s;
32    try
33    {
34        s.replace(pos1, n1, str, pos2, n2);
35        assert(s.__invariants());
36        assert(pos1 <= old_size && pos2 <= str.size());
37        assert(s == expected);
38        typename S::size_type xlen = std::min(n1, old_size - pos1);
39        typename S::size_type rlen = std::min(n2, str.size() - pos2);
40        assert(s.size() == old_size - xlen + rlen);
41    }
42    catch (std::out_of_range&)
43    {
44        assert(pos1 > old_size || pos2 > str.size());
45        assert(s == s0);
46    }
47}
48
49template <class S>
50void
51test_npos(S s, typename S::size_type pos1, typename S::size_type n1,
52     S str, typename S::size_type pos2,
53     S expected)
54{
55    typename S::size_type old_size = s.size();
56    S s0 = s;
57    try
58    {
59        s.replace(pos1, n1, str, pos2);
60        assert(s.__invariants());
61        assert(pos1 <= old_size && pos2 <= str.size());
62        assert(s == expected);
63        typename S::size_type xlen = std::min(n1, old_size - pos1);
64        typename S::size_type rlen = std::min(S::npos, str.size() - pos2);
65        assert(s.size() == old_size - xlen + rlen);
66    }
67    catch (std::out_of_range&)
68    {
69        assert(pos1 > old_size || pos2 > str.size());
70        assert(s == s0);
71    }
72}
73
74
75template <class S>
76void test0()
77{
78    test(S(""), 0, 0, S(""), 0, 0, S(""));
79    test(S(""), 0, 0, S(""), 0, 1, S(""));
80    test(S(""), 0, 0, S(""), 1, 0, S("can't happen"));
81    test(S(""), 0, 0, S("12345"), 0, 0, S(""));
82    test(S(""), 0, 0, S("12345"), 0, 1, S("1"));
83    test(S(""), 0, 0, S("12345"), 0, 2, S("12"));
84    test(S(""), 0, 0, S("12345"), 0, 4, S("1234"));
85    test(S(""), 0, 0, S("12345"), 0, 5, S("12345"));
86    test(S(""), 0, 0, S("12345"), 0, 6, S("12345"));
87    test(S(""), 0, 0, S("12345"), 1, 0, S(""));
88    test(S(""), 0, 0, S("12345"), 1, 1, S("2"));
89    test(S(""), 0, 0, S("12345"), 1, 2, S("23"));
90    test(S(""), 0, 0, S("12345"), 1, 3, S("234"));
91    test(S(""), 0, 0, S("12345"), 1, 4, S("2345"));
92    test(S(""), 0, 0, S("12345"), 1, 5, S("2345"));
93    test(S(""), 0, 0, S("12345"), 2, 0, S(""));
94    test(S(""), 0, 0, S("12345"), 2, 1, S("3"));
95    test(S(""), 0, 0, S("12345"), 2, 2, S("34"));
96    test(S(""), 0, 0, S("12345"), 2, 3, S("345"));
97    test(S(""), 0, 0, S("12345"), 2, 4, S("345"));
98    test(S(""), 0, 0, S("12345"), 4, 0, S(""));
99    test(S(""), 0, 0, S("12345"), 4, 1, S("5"));
100    test(S(""), 0, 0, S("12345"), 4, 2, S("5"));
101    test(S(""), 0, 0, S("12345"), 5, 0, S(""));
102    test(S(""), 0, 0, S("12345"), 5, 1, S(""));
103    test(S(""), 0, 0, S("12345"), 6, 0, S("can't happen"));
104    test(S(""), 0, 0, S("1234567890"), 0, 0, S(""));
105    test(S(""), 0, 0, S("1234567890"), 0, 1, S("1"));
106    test(S(""), 0, 0, S("1234567890"), 0, 5, S("12345"));
107    test(S(""), 0, 0, S("1234567890"), 0, 9, S("123456789"));
108    test(S(""), 0, 0, S("1234567890"), 0, 10, S("1234567890"));
109    test(S(""), 0, 0, S("1234567890"), 0, 11, S("1234567890"));
110    test(S(""), 0, 0, S("1234567890"), 1, 0, S(""));
111    test(S(""), 0, 0, S("1234567890"), 1, 1, S("2"));
112    test(S(""), 0, 0, S("1234567890"), 1, 4, S("2345"));
113    test(S(""), 0, 0, S("1234567890"), 1, 8, S("23456789"));
114    test(S(""), 0, 0, S("1234567890"), 1, 9, S("234567890"));
115    test(S(""), 0, 0, S("1234567890"), 1, 10, S("234567890"));
116    test(S(""), 0, 0, S("1234567890"), 5, 0, S(""));
117    test(S(""), 0, 0, S("1234567890"), 5, 1, S("6"));
118    test(S(""), 0, 0, S("1234567890"), 5, 2, S("67"));
119    test(S(""), 0, 0, S("1234567890"), 5, 4, S("6789"));
120    test(S(""), 0, 0, S("1234567890"), 5, 5, S("67890"));
121    test(S(""), 0, 0, S("1234567890"), 5, 6, S("67890"));
122    test(S(""), 0, 0, S("1234567890"), 9, 0, S(""));
123    test(S(""), 0, 0, S("1234567890"), 9, 1, S("0"));
124    test(S(""), 0, 0, S("1234567890"), 9, 2, S("0"));
125    test(S(""), 0, 0, S("1234567890"), 10, 0, S(""));
126    test(S(""), 0, 0, S("1234567890"), 10, 1, S(""));
127    test(S(""), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
128    test(S(""), 0, 0, S("12345678901234567890"), 0, 0, S(""));
129    test(S(""), 0, 0, S("12345678901234567890"), 0, 1, S("1"));
130    test(S(""), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890"));
131    test(S(""), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
132    test(S(""), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
133    test(S(""), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
134    test(S(""), 0, 0, S("12345678901234567890"), 1, 0, S(""));
135    test(S(""), 0, 0, S("12345678901234567890"), 1, 1, S("2"));
136    test(S(""), 0, 0, S("12345678901234567890"), 1, 9, S("234567890"));
137    test(S(""), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789"));
138    test(S(""), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
139    test(S(""), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
140    test(S(""), 0, 0, S("12345678901234567890"), 10, 0, S(""));
141    test(S(""), 0, 0, S("12345678901234567890"), 10, 1, S("1"));
142    test(S(""), 0, 0, S("12345678901234567890"), 10, 5, S("12345"));
143    test(S(""), 0, 0, S("12345678901234567890"), 10, 9, S("123456789"));
144    test(S(""), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890"));
145    test(S(""), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890"));
146    test(S(""), 0, 0, S("12345678901234567890"), 19, 0, S(""));
147    test(S(""), 0, 0, S("12345678901234567890"), 19, 1, S("0"));
148    test(S(""), 0, 0, S("12345678901234567890"), 19, 2, S("0"));
149    test(S(""), 0, 0, S("12345678901234567890"), 20, 0, S(""));
150    test(S(""), 0, 0, S("12345678901234567890"), 20, 1, S(""));
151    test(S(""), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
152    test(S(""), 0, 1, S(""), 0, 0, S(""));
153    test(S(""), 0, 1, S(""), 0, 1, S(""));
154    test(S(""), 0, 1, S(""), 1, 0, S("can't happen"));
155    test(S(""), 0, 1, S("12345"), 0, 0, S(""));
156    test(S(""), 0, 1, S("12345"), 0, 1, S("1"));
157    test(S(""), 0, 1, S("12345"), 0, 2, S("12"));
158    test(S(""), 0, 1, S("12345"), 0, 4, S("1234"));
159    test(S(""), 0, 1, S("12345"), 0, 5, S("12345"));
160    test(S(""), 0, 1, S("12345"), 0, 6, S("12345"));
161    test(S(""), 0, 1, S("12345"), 1, 0, S(""));
162    test(S(""), 0, 1, S("12345"), 1, 1, S("2"));
163    test(S(""), 0, 1, S("12345"), 1, 2, S("23"));
164    test(S(""), 0, 1, S("12345"), 1, 3, S("234"));
165    test(S(""), 0, 1, S("12345"), 1, 4, S("2345"));
166    test(S(""), 0, 1, S("12345"), 1, 5, S("2345"));
167    test(S(""), 0, 1, S("12345"), 2, 0, S(""));
168    test(S(""), 0, 1, S("12345"), 2, 1, S("3"));
169    test(S(""), 0, 1, S("12345"), 2, 2, S("34"));
170    test(S(""), 0, 1, S("12345"), 2, 3, S("345"));
171    test(S(""), 0, 1, S("12345"), 2, 4, S("345"));
172    test(S(""), 0, 1, S("12345"), 4, 0, S(""));
173    test(S(""), 0, 1, S("12345"), 4, 1, S("5"));
174    test(S(""), 0, 1, S("12345"), 4, 2, S("5"));
175    test(S(""), 0, 1, S("12345"), 5, 0, S(""));
176    test(S(""), 0, 1, S("12345"), 5, 1, S(""));
177    test(S(""), 0, 1, S("12345"), 6, 0, S("can't happen"));
178}
179
180template <class S>
181void test1()
182{
183    test(S(""), 0, 1, S("1234567890"), 0, 0, S(""));
184    test(S(""), 0, 1, S("1234567890"), 0, 1, S("1"));
185    test(S(""), 0, 1, S("1234567890"), 0, 5, S("12345"));
186    test(S(""), 0, 1, S("1234567890"), 0, 9, S("123456789"));
187    test(S(""), 0, 1, S("1234567890"), 0, 10, S("1234567890"));
188    test(S(""), 0, 1, S("1234567890"), 0, 11, S("1234567890"));
189    test(S(""), 0, 1, S("1234567890"), 1, 0, S(""));
190    test(S(""), 0, 1, S("1234567890"), 1, 1, S("2"));
191    test(S(""), 0, 1, S("1234567890"), 1, 4, S("2345"));
192    test(S(""), 0, 1, S("1234567890"), 1, 8, S("23456789"));
193    test(S(""), 0, 1, S("1234567890"), 1, 9, S("234567890"));
194    test(S(""), 0, 1, S("1234567890"), 1, 10, S("234567890"));
195    test(S(""), 0, 1, S("1234567890"), 5, 0, S(""));
196    test(S(""), 0, 1, S("1234567890"), 5, 1, S("6"));
197    test(S(""), 0, 1, S("1234567890"), 5, 2, S("67"));
198    test(S(""), 0, 1, S("1234567890"), 5, 4, S("6789"));
199    test(S(""), 0, 1, S("1234567890"), 5, 5, S("67890"));
200    test(S(""), 0, 1, S("1234567890"), 5, 6, S("67890"));
201    test(S(""), 0, 1, S("1234567890"), 9, 0, S(""));
202    test(S(""), 0, 1, S("1234567890"), 9, 1, S("0"));
203    test(S(""), 0, 1, S("1234567890"), 9, 2, S("0"));
204    test(S(""), 0, 1, S("1234567890"), 10, 0, S(""));
205    test(S(""), 0, 1, S("1234567890"), 10, 1, S(""));
206    test(S(""), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
207    test(S(""), 0, 1, S("12345678901234567890"), 0, 0, S(""));
208    test(S(""), 0, 1, S("12345678901234567890"), 0, 1, S("1"));
209    test(S(""), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890"));
210    test(S(""), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
211    test(S(""), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
212    test(S(""), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
213    test(S(""), 0, 1, S("12345678901234567890"), 1, 0, S(""));
214    test(S(""), 0, 1, S("12345678901234567890"), 1, 1, S("2"));
215    test(S(""), 0, 1, S("12345678901234567890"), 1, 9, S("234567890"));
216    test(S(""), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789"));
217    test(S(""), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
218    test(S(""), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
219    test(S(""), 0, 1, S("12345678901234567890"), 10, 0, S(""));
220    test(S(""), 0, 1, S("12345678901234567890"), 10, 1, S("1"));
221    test(S(""), 0, 1, S("12345678901234567890"), 10, 5, S("12345"));
222    test(S(""), 0, 1, S("12345678901234567890"), 10, 9, S("123456789"));
223    test(S(""), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890"));
224    test(S(""), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890"));
225    test(S(""), 0, 1, S("12345678901234567890"), 19, 0, S(""));
226    test(S(""), 0, 1, S("12345678901234567890"), 19, 1, S("0"));
227    test(S(""), 0, 1, S("12345678901234567890"), 19, 2, S("0"));
228    test(S(""), 0, 1, S("12345678901234567890"), 20, 0, S(""));
229    test(S(""), 0, 1, S("12345678901234567890"), 20, 1, S(""));
230    test(S(""), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
231    test(S(""), 1, 0, S(""), 0, 0, S("can't happen"));
232    test(S(""), 1, 0, S(""), 0, 1, S("can't happen"));
233    test(S(""), 1, 0, S(""), 1, 0, S("can't happen"));
234    test(S(""), 1, 0, S("12345"), 0, 0, S("can't happen"));
235    test(S(""), 1, 0, S("12345"), 0, 1, S("can't happen"));
236    test(S(""), 1, 0, S("12345"), 0, 2, S("can't happen"));
237    test(S(""), 1, 0, S("12345"), 0, 4, S("can't happen"));
238    test(S(""), 1, 0, S("12345"), 0, 5, S("can't happen"));
239    test(S(""), 1, 0, S("12345"), 0, 6, S("can't happen"));
240    test(S(""), 1, 0, S("12345"), 1, 0, S("can't happen"));
241    test(S(""), 1, 0, S("12345"), 1, 1, S("can't happen"));
242    test(S(""), 1, 0, S("12345"), 1, 2, S("can't happen"));
243    test(S(""), 1, 0, S("12345"), 1, 3, S("can't happen"));
244    test(S(""), 1, 0, S("12345"), 1, 4, S("can't happen"));
245    test(S(""), 1, 0, S("12345"), 1, 5, S("can't happen"));
246    test(S(""), 1, 0, S("12345"), 2, 0, S("can't happen"));
247    test(S(""), 1, 0, S("12345"), 2, 1, S("can't happen"));
248    test(S(""), 1, 0, S("12345"), 2, 2, S("can't happen"));
249    test(S(""), 1, 0, S("12345"), 2, 3, S("can't happen"));
250    test(S(""), 1, 0, S("12345"), 2, 4, S("can't happen"));
251    test(S(""), 1, 0, S("12345"), 4, 0, S("can't happen"));
252    test(S(""), 1, 0, S("12345"), 4, 1, S("can't happen"));
253    test(S(""), 1, 0, S("12345"), 4, 2, S("can't happen"));
254    test(S(""), 1, 0, S("12345"), 5, 0, S("can't happen"));
255    test(S(""), 1, 0, S("12345"), 5, 1, S("can't happen"));
256    test(S(""), 1, 0, S("12345"), 6, 0, S("can't happen"));
257    test(S(""), 1, 0, S("1234567890"), 0, 0, S("can't happen"));
258    test(S(""), 1, 0, S("1234567890"), 0, 1, S("can't happen"));
259    test(S(""), 1, 0, S("1234567890"), 0, 5, S("can't happen"));
260    test(S(""), 1, 0, S("1234567890"), 0, 9, S("can't happen"));
261    test(S(""), 1, 0, S("1234567890"), 0, 10, S("can't happen"));
262    test(S(""), 1, 0, S("1234567890"), 0, 11, S("can't happen"));
263    test(S(""), 1, 0, S("1234567890"), 1, 0, S("can't happen"));
264    test(S(""), 1, 0, S("1234567890"), 1, 1, S("can't happen"));
265    test(S(""), 1, 0, S("1234567890"), 1, 4, S("can't happen"));
266    test(S(""), 1, 0, S("1234567890"), 1, 8, S("can't happen"));
267    test(S(""), 1, 0, S("1234567890"), 1, 9, S("can't happen"));
268    test(S(""), 1, 0, S("1234567890"), 1, 10, S("can't happen"));
269    test(S(""), 1, 0, S("1234567890"), 5, 0, S("can't happen"));
270    test(S(""), 1, 0, S("1234567890"), 5, 1, S("can't happen"));
271    test(S(""), 1, 0, S("1234567890"), 5, 2, S("can't happen"));
272    test(S(""), 1, 0, S("1234567890"), 5, 4, S("can't happen"));
273    test(S(""), 1, 0, S("1234567890"), 5, 5, S("can't happen"));
274    test(S(""), 1, 0, S("1234567890"), 5, 6, S("can't happen"));
275    test(S(""), 1, 0, S("1234567890"), 9, 0, S("can't happen"));
276    test(S(""), 1, 0, S("1234567890"), 9, 1, S("can't happen"));
277    test(S(""), 1, 0, S("1234567890"), 9, 2, S("can't happen"));
278    test(S(""), 1, 0, S("1234567890"), 10, 0, S("can't happen"));
279    test(S(""), 1, 0, S("1234567890"), 10, 1, S("can't happen"));
280    test(S(""), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
281    test(S(""), 1, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
282    test(S(""), 1, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
283}
284
285template <class S>
286void test2()
287{
288    test(S(""), 1, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
289    test(S(""), 1, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
290    test(S(""), 1, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
291    test(S(""), 1, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
292    test(S(""), 1, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
293    test(S(""), 1, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
294    test(S(""), 1, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
295    test(S(""), 1, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
296    test(S(""), 1, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
297    test(S(""), 1, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
298    test(S(""), 1, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
299    test(S(""), 1, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
300    test(S(""), 1, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
301    test(S(""), 1, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
302    test(S(""), 1, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
303    test(S(""), 1, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
304    test(S(""), 1, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
305    test(S(""), 1, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
306    test(S(""), 1, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
307    test(S(""), 1, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
308    test(S(""), 1, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
309    test(S(""), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
310    test(S("abcde"), 0, 0, S(""), 0, 0, S("abcde"));
311    test(S("abcde"), 0, 0, S(""), 0, 1, S("abcde"));
312    test(S("abcde"), 0, 0, S(""), 1, 0, S("can't happen"));
313    test(S("abcde"), 0, 0, S("12345"), 0, 0, S("abcde"));
314    test(S("abcde"), 0, 0, S("12345"), 0, 1, S("1abcde"));
315    test(S("abcde"), 0, 0, S("12345"), 0, 2, S("12abcde"));
316    test(S("abcde"), 0, 0, S("12345"), 0, 4, S("1234abcde"));
317    test(S("abcde"), 0, 0, S("12345"), 0, 5, S("12345abcde"));
318    test(S("abcde"), 0, 0, S("12345"), 0, 6, S("12345abcde"));
319    test(S("abcde"), 0, 0, S("12345"), 1, 0, S("abcde"));
320    test(S("abcde"), 0, 0, S("12345"), 1, 1, S("2abcde"));
321    test(S("abcde"), 0, 0, S("12345"), 1, 2, S("23abcde"));
322    test(S("abcde"), 0, 0, S("12345"), 1, 3, S("234abcde"));
323    test(S("abcde"), 0, 0, S("12345"), 1, 4, S("2345abcde"));
324    test(S("abcde"), 0, 0, S("12345"), 1, 5, S("2345abcde"));
325    test(S("abcde"), 0, 0, S("12345"), 2, 0, S("abcde"));
326    test(S("abcde"), 0, 0, S("12345"), 2, 1, S("3abcde"));
327    test(S("abcde"), 0, 0, S("12345"), 2, 2, S("34abcde"));
328    test(S("abcde"), 0, 0, S("12345"), 2, 3, S("345abcde"));
329    test(S("abcde"), 0, 0, S("12345"), 2, 4, S("345abcde"));
330    test(S("abcde"), 0, 0, S("12345"), 4, 0, S("abcde"));
331    test(S("abcde"), 0, 0, S("12345"), 4, 1, S("5abcde"));
332    test(S("abcde"), 0, 0, S("12345"), 4, 2, S("5abcde"));
333    test(S("abcde"), 0, 0, S("12345"), 5, 0, S("abcde"));
334    test(S("abcde"), 0, 0, S("12345"), 5, 1, S("abcde"));
335    test(S("abcde"), 0, 0, S("12345"), 6, 0, S("can't happen"));
336    test(S("abcde"), 0, 0, S("1234567890"), 0, 0, S("abcde"));
337    test(S("abcde"), 0, 0, S("1234567890"), 0, 1, S("1abcde"));
338    test(S("abcde"), 0, 0, S("1234567890"), 0, 5, S("12345abcde"));
339    test(S("abcde"), 0, 0, S("1234567890"), 0, 9, S("123456789abcde"));
340    test(S("abcde"), 0, 0, S("1234567890"), 0, 10, S("1234567890abcde"));
341    test(S("abcde"), 0, 0, S("1234567890"), 0, 11, S("1234567890abcde"));
342    test(S("abcde"), 0, 0, S("1234567890"), 1, 0, S("abcde"));
343    test(S("abcde"), 0, 0, S("1234567890"), 1, 1, S("2abcde"));
344    test(S("abcde"), 0, 0, S("1234567890"), 1, 4, S("2345abcde"));
345    test(S("abcde"), 0, 0, S("1234567890"), 1, 8, S("23456789abcde"));
346    test(S("abcde"), 0, 0, S("1234567890"), 1, 9, S("234567890abcde"));
347    test(S("abcde"), 0, 0, S("1234567890"), 1, 10, S("234567890abcde"));
348    test(S("abcde"), 0, 0, S("1234567890"), 5, 0, S("abcde"));
349    test(S("abcde"), 0, 0, S("1234567890"), 5, 1, S("6abcde"));
350    test(S("abcde"), 0, 0, S("1234567890"), 5, 2, S("67abcde"));
351    test(S("abcde"), 0, 0, S("1234567890"), 5, 4, S("6789abcde"));
352    test(S("abcde"), 0, 0, S("1234567890"), 5, 5, S("67890abcde"));
353    test(S("abcde"), 0, 0, S("1234567890"), 5, 6, S("67890abcde"));
354    test(S("abcde"), 0, 0, S("1234567890"), 9, 0, S("abcde"));
355    test(S("abcde"), 0, 0, S("1234567890"), 9, 1, S("0abcde"));
356    test(S("abcde"), 0, 0, S("1234567890"), 9, 2, S("0abcde"));
357    test(S("abcde"), 0, 0, S("1234567890"), 10, 0, S("abcde"));
358    test(S("abcde"), 0, 0, S("1234567890"), 10, 1, S("abcde"));
359    test(S("abcde"), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
360    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 0, S("abcde"));
361    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 1, S("1abcde"));
362    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890abcde"));
363    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcde"));
364    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcde"));
365    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcde"));
366    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 0, S("abcde"));
367    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 1, S("2abcde"));
368    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 9, S("234567890abcde"));
369    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcde"));
370    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcde"));
371    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcde"));
372    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 0, S("abcde"));
373    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 1, S("1abcde"));
374    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 5, S("12345abcde"));
375    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 9, S("123456789abcde"));
376    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890abcde"));
377    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890abcde"));
378    test(S("abcde"), 0, 0, S("12345678901234567890"), 19, 0, S("abcde"));
379    test(S("abcde"), 0, 0, S("12345678901234567890"), 19, 1, S("0abcde"));
380    test(S("abcde"), 0, 0, S("12345678901234567890"), 19, 2, S("0abcde"));
381    test(S("abcde"), 0, 0, S("12345678901234567890"), 20, 0, S("abcde"));
382    test(S("abcde"), 0, 0, S("12345678901234567890"), 20, 1, S("abcde"));
383    test(S("abcde"), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
384    test(S("abcde"), 0, 1, S(""), 0, 0, S("bcde"));
385    test(S("abcde"), 0, 1, S(""), 0, 1, S("bcde"));
386    test(S("abcde"), 0, 1, S(""), 1, 0, S("can't happen"));
387    test(S("abcde"), 0, 1, S("12345"), 0, 0, S("bcde"));
388}
389
390template <class S>
391void test3()
392{
393    test(S("abcde"), 0, 1, S("12345"), 0, 1, S("1bcde"));
394    test(S("abcde"), 0, 1, S("12345"), 0, 2, S("12bcde"));
395    test(S("abcde"), 0, 1, S("12345"), 0, 4, S("1234bcde"));
396    test(S("abcde"), 0, 1, S("12345"), 0, 5, S("12345bcde"));
397    test(S("abcde"), 0, 1, S("12345"), 0, 6, S("12345bcde"));
398    test(S("abcde"), 0, 1, S("12345"), 1, 0, S("bcde"));
399    test(S("abcde"), 0, 1, S("12345"), 1, 1, S("2bcde"));
400    test(S("abcde"), 0, 1, S("12345"), 1, 2, S("23bcde"));
401    test(S("abcde"), 0, 1, S("12345"), 1, 3, S("234bcde"));
402    test(S("abcde"), 0, 1, S("12345"), 1, 4, S("2345bcde"));
403    test(S("abcde"), 0, 1, S("12345"), 1, 5, S("2345bcde"));
404    test(S("abcde"), 0, 1, S("12345"), 2, 0, S("bcde"));
405    test(S("abcde"), 0, 1, S("12345"), 2, 1, S("3bcde"));
406    test(S("abcde"), 0, 1, S("12345"), 2, 2, S("34bcde"));
407    test(S("abcde"), 0, 1, S("12345"), 2, 3, S("345bcde"));
408    test(S("abcde"), 0, 1, S("12345"), 2, 4, S("345bcde"));
409    test(S("abcde"), 0, 1, S("12345"), 4, 0, S("bcde"));
410    test(S("abcde"), 0, 1, S("12345"), 4, 1, S("5bcde"));
411    test(S("abcde"), 0, 1, S("12345"), 4, 2, S("5bcde"));
412    test(S("abcde"), 0, 1, S("12345"), 5, 0, S("bcde"));
413    test(S("abcde"), 0, 1, S("12345"), 5, 1, S("bcde"));
414    test(S("abcde"), 0, 1, S("12345"), 6, 0, S("can't happen"));
415    test(S("abcde"), 0, 1, S("1234567890"), 0, 0, S("bcde"));
416    test(S("abcde"), 0, 1, S("1234567890"), 0, 1, S("1bcde"));
417    test(S("abcde"), 0, 1, S("1234567890"), 0, 5, S("12345bcde"));
418    test(S("abcde"), 0, 1, S("1234567890"), 0, 9, S("123456789bcde"));
419    test(S("abcde"), 0, 1, S("1234567890"), 0, 10, S("1234567890bcde"));
420    test(S("abcde"), 0, 1, S("1234567890"), 0, 11, S("1234567890bcde"));
421    test(S("abcde"), 0, 1, S("1234567890"), 1, 0, S("bcde"));
422    test(S("abcde"), 0, 1, S("1234567890"), 1, 1, S("2bcde"));
423    test(S("abcde"), 0, 1, S("1234567890"), 1, 4, S("2345bcde"));
424    test(S("abcde"), 0, 1, S("1234567890"), 1, 8, S("23456789bcde"));
425    test(S("abcde"), 0, 1, S("1234567890"), 1, 9, S("234567890bcde"));
426    test(S("abcde"), 0, 1, S("1234567890"), 1, 10, S("234567890bcde"));
427    test(S("abcde"), 0, 1, S("1234567890"), 5, 0, S("bcde"));
428    test(S("abcde"), 0, 1, S("1234567890"), 5, 1, S("6bcde"));
429    test(S("abcde"), 0, 1, S("1234567890"), 5, 2, S("67bcde"));
430    test(S("abcde"), 0, 1, S("1234567890"), 5, 4, S("6789bcde"));
431    test(S("abcde"), 0, 1, S("1234567890"), 5, 5, S("67890bcde"));
432    test(S("abcde"), 0, 1, S("1234567890"), 5, 6, S("67890bcde"));
433    test(S("abcde"), 0, 1, S("1234567890"), 9, 0, S("bcde"));
434    test(S("abcde"), 0, 1, S("1234567890"), 9, 1, S("0bcde"));
435    test(S("abcde"), 0, 1, S("1234567890"), 9, 2, S("0bcde"));
436    test(S("abcde"), 0, 1, S("1234567890"), 10, 0, S("bcde"));
437    test(S("abcde"), 0, 1, S("1234567890"), 10, 1, S("bcde"));
438    test(S("abcde"), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
439    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 0, S("bcde"));
440    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 1, S("1bcde"));
441    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890bcde"));
442    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789bcde"));
443    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890bcde"));
444    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890bcde"));
445    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 0, S("bcde"));
446    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 1, S("2bcde"));
447    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 9, S("234567890bcde"));
448    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789bcde"));
449    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890bcde"));
450    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890bcde"));
451    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 0, S("bcde"));
452    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 1, S("1bcde"));
453    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 5, S("12345bcde"));
454    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 9, S("123456789bcde"));
455    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890bcde"));
456    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890bcde"));
457    test(S("abcde"), 0, 1, S("12345678901234567890"), 19, 0, S("bcde"));
458    test(S("abcde"), 0, 1, S("12345678901234567890"), 19, 1, S("0bcde"));
459    test(S("abcde"), 0, 1, S("12345678901234567890"), 19, 2, S("0bcde"));
460    test(S("abcde"), 0, 1, S("12345678901234567890"), 20, 0, S("bcde"));
461    test(S("abcde"), 0, 1, S("12345678901234567890"), 20, 1, S("bcde"));
462    test(S("abcde"), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
463    test(S("abcde"), 0, 2, S(""), 0, 0, S("cde"));
464    test(S("abcde"), 0, 2, S(""), 0, 1, S("cde"));
465    test(S("abcde"), 0, 2, S(""), 1, 0, S("can't happen"));
466    test(S("abcde"), 0, 2, S("12345"), 0, 0, S("cde"));
467    test(S("abcde"), 0, 2, S("12345"), 0, 1, S("1cde"));
468    test(S("abcde"), 0, 2, S("12345"), 0, 2, S("12cde"));
469    test(S("abcde"), 0, 2, S("12345"), 0, 4, S("1234cde"));
470    test(S("abcde"), 0, 2, S("12345"), 0, 5, S("12345cde"));
471    test(S("abcde"), 0, 2, S("12345"), 0, 6, S("12345cde"));
472    test(S("abcde"), 0, 2, S("12345"), 1, 0, S("cde"));
473    test(S("abcde"), 0, 2, S("12345"), 1, 1, S("2cde"));
474    test(S("abcde"), 0, 2, S("12345"), 1, 2, S("23cde"));
475    test(S("abcde"), 0, 2, S("12345"), 1, 3, S("234cde"));
476    test(S("abcde"), 0, 2, S("12345"), 1, 4, S("2345cde"));
477    test(S("abcde"), 0, 2, S("12345"), 1, 5, S("2345cde"));
478    test(S("abcde"), 0, 2, S("12345"), 2, 0, S("cde"));
479    test(S("abcde"), 0, 2, S("12345"), 2, 1, S("3cde"));
480    test(S("abcde"), 0, 2, S("12345"), 2, 2, S("34cde"));
481    test(S("abcde"), 0, 2, S("12345"), 2, 3, S("345cde"));
482    test(S("abcde"), 0, 2, S("12345"), 2, 4, S("345cde"));
483    test(S("abcde"), 0, 2, S("12345"), 4, 0, S("cde"));
484    test(S("abcde"), 0, 2, S("12345"), 4, 1, S("5cde"));
485    test(S("abcde"), 0, 2, S("12345"), 4, 2, S("5cde"));
486    test(S("abcde"), 0, 2, S("12345"), 5, 0, S("cde"));
487    test(S("abcde"), 0, 2, S("12345"), 5, 1, S("cde"));
488    test(S("abcde"), 0, 2, S("12345"), 6, 0, S("can't happen"));
489    test(S("abcde"), 0, 2, S("1234567890"), 0, 0, S("cde"));
490    test(S("abcde"), 0, 2, S("1234567890"), 0, 1, S("1cde"));
491    test(S("abcde"), 0, 2, S("1234567890"), 0, 5, S("12345cde"));
492    test(S("abcde"), 0, 2, S("1234567890"), 0, 9, S("123456789cde"));
493}
494
495template <class S>
496void test4()
497{
498    test(S("abcde"), 0, 2, S("1234567890"), 0, 10, S("1234567890cde"));
499    test(S("abcde"), 0, 2, S("1234567890"), 0, 11, S("1234567890cde"));
500    test(S("abcde"), 0, 2, S("1234567890"), 1, 0, S("cde"));
501    test(S("abcde"), 0, 2, S("1234567890"), 1, 1, S("2cde"));
502    test(S("abcde"), 0, 2, S("1234567890"), 1, 4, S("2345cde"));
503    test(S("abcde"), 0, 2, S("1234567890"), 1, 8, S("23456789cde"));
504    test(S("abcde"), 0, 2, S("1234567890"), 1, 9, S("234567890cde"));
505    test(S("abcde"), 0, 2, S("1234567890"), 1, 10, S("234567890cde"));
506    test(S("abcde"), 0, 2, S("1234567890"), 5, 0, S("cde"));
507    test(S("abcde"), 0, 2, S("1234567890"), 5, 1, S("6cde"));
508    test(S("abcde"), 0, 2, S("1234567890"), 5, 2, S("67cde"));
509    test(S("abcde"), 0, 2, S("1234567890"), 5, 4, S("6789cde"));
510    test(S("abcde"), 0, 2, S("1234567890"), 5, 5, S("67890cde"));
511    test(S("abcde"), 0, 2, S("1234567890"), 5, 6, S("67890cde"));
512    test(S("abcde"), 0, 2, S("1234567890"), 9, 0, S("cde"));
513    test(S("abcde"), 0, 2, S("1234567890"), 9, 1, S("0cde"));
514    test(S("abcde"), 0, 2, S("1234567890"), 9, 2, S("0cde"));
515    test(S("abcde"), 0, 2, S("1234567890"), 10, 0, S("cde"));
516    test(S("abcde"), 0, 2, S("1234567890"), 10, 1, S("cde"));
517    test(S("abcde"), 0, 2, S("1234567890"), 11, 0, S("can't happen"));
518    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 0, S("cde"));
519    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 1, S("1cde"));
520    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 10, S("1234567890cde"));
521    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 19, S("1234567890123456789cde"));
522    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 20, S("12345678901234567890cde"));
523    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 21, S("12345678901234567890cde"));
524    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 0, S("cde"));
525    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 1, S("2cde"));
526    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 9, S("234567890cde"));
527    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 18, S("234567890123456789cde"));
528    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 19, S("2345678901234567890cde"));
529    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 20, S("2345678901234567890cde"));
530    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 0, S("cde"));
531    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 1, S("1cde"));
532    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 5, S("12345cde"));
533    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 9, S("123456789cde"));
534    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 10, S("1234567890cde"));
535    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 11, S("1234567890cde"));
536    test(S("abcde"), 0, 2, S("12345678901234567890"), 19, 0, S("cde"));
537    test(S("abcde"), 0, 2, S("12345678901234567890"), 19, 1, S("0cde"));
538    test(S("abcde"), 0, 2, S("12345678901234567890"), 19, 2, S("0cde"));
539    test(S("abcde"), 0, 2, S("12345678901234567890"), 20, 0, S("cde"));
540    test(S("abcde"), 0, 2, S("12345678901234567890"), 20, 1, S("cde"));
541    test(S("abcde"), 0, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
542    test(S("abcde"), 0, 4, S(""), 0, 0, S("e"));
543    test(S("abcde"), 0, 4, S(""), 0, 1, S("e"));
544    test(S("abcde"), 0, 4, S(""), 1, 0, S("can't happen"));
545    test(S("abcde"), 0, 4, S("12345"), 0, 0, S("e"));
546    test(S("abcde"), 0, 4, S("12345"), 0, 1, S("1e"));
547    test(S("abcde"), 0, 4, S("12345"), 0, 2, S("12e"));
548    test(S("abcde"), 0, 4, S("12345"), 0, 4, S("1234e"));
549    test(S("abcde"), 0, 4, S("12345"), 0, 5, S("12345e"));
550    test(S("abcde"), 0, 4, S("12345"), 0, 6, S("12345e"));
551    test(S("abcde"), 0, 4, S("12345"), 1, 0, S("e"));
552    test(S("abcde"), 0, 4, S("12345"), 1, 1, S("2e"));
553    test(S("abcde"), 0, 4, S("12345"), 1, 2, S("23e"));
554    test(S("abcde"), 0, 4, S("12345"), 1, 3, S("234e"));
555    test(S("abcde"), 0, 4, S("12345"), 1, 4, S("2345e"));
556    test(S("abcde"), 0, 4, S("12345"), 1, 5, S("2345e"));
557    test(S("abcde"), 0, 4, S("12345"), 2, 0, S("e"));
558    test(S("abcde"), 0, 4, S("12345"), 2, 1, S("3e"));
559    test(S("abcde"), 0, 4, S("12345"), 2, 2, S("34e"));
560    test(S("abcde"), 0, 4, S("12345"), 2, 3, S("345e"));
561    test(S("abcde"), 0, 4, S("12345"), 2, 4, S("345e"));
562    test(S("abcde"), 0, 4, S("12345"), 4, 0, S("e"));
563    test(S("abcde"), 0, 4, S("12345"), 4, 1, S("5e"));
564    test(S("abcde"), 0, 4, S("12345"), 4, 2, S("5e"));
565    test(S("abcde"), 0, 4, S("12345"), 5, 0, S("e"));
566    test(S("abcde"), 0, 4, S("12345"), 5, 1, S("e"));
567    test(S("abcde"), 0, 4, S("12345"), 6, 0, S("can't happen"));
568    test(S("abcde"), 0, 4, S("1234567890"), 0, 0, S("e"));
569    test(S("abcde"), 0, 4, S("1234567890"), 0, 1, S("1e"));
570    test(S("abcde"), 0, 4, S("1234567890"), 0, 5, S("12345e"));
571    test(S("abcde"), 0, 4, S("1234567890"), 0, 9, S("123456789e"));
572    test(S("abcde"), 0, 4, S("1234567890"), 0, 10, S("1234567890e"));
573    test(S("abcde"), 0, 4, S("1234567890"), 0, 11, S("1234567890e"));
574    test(S("abcde"), 0, 4, S("1234567890"), 1, 0, S("e"));
575    test(S("abcde"), 0, 4, S("1234567890"), 1, 1, S("2e"));
576    test(S("abcde"), 0, 4, S("1234567890"), 1, 4, S("2345e"));
577    test(S("abcde"), 0, 4, S("1234567890"), 1, 8, S("23456789e"));
578    test(S("abcde"), 0, 4, S("1234567890"), 1, 9, S("234567890e"));
579    test(S("abcde"), 0, 4, S("1234567890"), 1, 10, S("234567890e"));
580    test(S("abcde"), 0, 4, S("1234567890"), 5, 0, S("e"));
581    test(S("abcde"), 0, 4, S("1234567890"), 5, 1, S("6e"));
582    test(S("abcde"), 0, 4, S("1234567890"), 5, 2, S("67e"));
583    test(S("abcde"), 0, 4, S("1234567890"), 5, 4, S("6789e"));
584    test(S("abcde"), 0, 4, S("1234567890"), 5, 5, S("67890e"));
585    test(S("abcde"), 0, 4, S("1234567890"), 5, 6, S("67890e"));
586    test(S("abcde"), 0, 4, S("1234567890"), 9, 0, S("e"));
587    test(S("abcde"), 0, 4, S("1234567890"), 9, 1, S("0e"));
588    test(S("abcde"), 0, 4, S("1234567890"), 9, 2, S("0e"));
589    test(S("abcde"), 0, 4, S("1234567890"), 10, 0, S("e"));
590    test(S("abcde"), 0, 4, S("1234567890"), 10, 1, S("e"));
591    test(S("abcde"), 0, 4, S("1234567890"), 11, 0, S("can't happen"));
592    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 0, S("e"));
593    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 1, S("1e"));
594    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 10, S("1234567890e"));
595    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 19, S("1234567890123456789e"));
596    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 20, S("12345678901234567890e"));
597    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 21, S("12345678901234567890e"));
598}
599
600template <class S>
601void test5()
602{
603    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 0, S("e"));
604    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 1, S("2e"));
605    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 9, S("234567890e"));
606    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 18, S("234567890123456789e"));
607    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 19, S("2345678901234567890e"));
608    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 20, S("2345678901234567890e"));
609    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 0, S("e"));
610    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 1, S("1e"));
611    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 5, S("12345e"));
612    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 9, S("123456789e"));
613    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 10, S("1234567890e"));
614    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 11, S("1234567890e"));
615    test(S("abcde"), 0, 4, S("12345678901234567890"), 19, 0, S("e"));
616    test(S("abcde"), 0, 4, S("12345678901234567890"), 19, 1, S("0e"));
617    test(S("abcde"), 0, 4, S("12345678901234567890"), 19, 2, S("0e"));
618    test(S("abcde"), 0, 4, S("12345678901234567890"), 20, 0, S("e"));
619    test(S("abcde"), 0, 4, S("12345678901234567890"), 20, 1, S("e"));
620    test(S("abcde"), 0, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
621    test(S("abcde"), 0, 5, S(""), 0, 0, S(""));
622    test(S("abcde"), 0, 5, S(""), 0, 1, S(""));
623    test(S("abcde"), 0, 5, S(""), 1, 0, S("can't happen"));
624    test(S("abcde"), 0, 5, S("12345"), 0, 0, S(""));
625    test(S("abcde"), 0, 5, S("12345"), 0, 1, S("1"));
626    test(S("abcde"), 0, 5, S("12345"), 0, 2, S("12"));
627    test(S("abcde"), 0, 5, S("12345"), 0, 4, S("1234"));
628    test(S("abcde"), 0, 5, S("12345"), 0, 5, S("12345"));
629    test(S("abcde"), 0, 5, S("12345"), 0, 6, S("12345"));
630    test(S("abcde"), 0, 5, S("12345"), 1, 0, S(""));
631    test(S("abcde"), 0, 5, S("12345"), 1, 1, S("2"));
632    test(S("abcde"), 0, 5, S("12345"), 1, 2, S("23"));
633    test(S("abcde"), 0, 5, S("12345"), 1, 3, S("234"));
634    test(S("abcde"), 0, 5, S("12345"), 1, 4, S("2345"));
635    test(S("abcde"), 0, 5, S("12345"), 1, 5, S("2345"));
636    test(S("abcde"), 0, 5, S("12345"), 2, 0, S(""));
637    test(S("abcde"), 0, 5, S("12345"), 2, 1, S("3"));
638    test(S("abcde"), 0, 5, S("12345"), 2, 2, S("34"));
639    test(S("abcde"), 0, 5, S("12345"), 2, 3, S("345"));
640    test(S("abcde"), 0, 5, S("12345"), 2, 4, S("345"));
641    test(S("abcde"), 0, 5, S("12345"), 4, 0, S(""));
642    test(S("abcde"), 0, 5, S("12345"), 4, 1, S("5"));
643    test(S("abcde"), 0, 5, S("12345"), 4, 2, S("5"));
644    test(S("abcde"), 0, 5, S("12345"), 5, 0, S(""));
645    test(S("abcde"), 0, 5, S("12345"), 5, 1, S(""));
646    test(S("abcde"), 0, 5, S("12345"), 6, 0, S("can't happen"));
647    test(S("abcde"), 0, 5, S("1234567890"), 0, 0, S(""));
648    test(S("abcde"), 0, 5, S("1234567890"), 0, 1, S("1"));
649    test(S("abcde"), 0, 5, S("1234567890"), 0, 5, S("12345"));
650    test(S("abcde"), 0, 5, S("1234567890"), 0, 9, S("123456789"));
651    test(S("abcde"), 0, 5, S("1234567890"), 0, 10, S("1234567890"));
652    test(S("abcde"), 0, 5, S("1234567890"), 0, 11, S("1234567890"));
653    test(S("abcde"), 0, 5, S("1234567890"), 1, 0, S(""));
654    test(S("abcde"), 0, 5, S("1234567890"), 1, 1, S("2"));
655    test(S("abcde"), 0, 5, S("1234567890"), 1, 4, S("2345"));
656    test(S("abcde"), 0, 5, S("1234567890"), 1, 8, S("23456789"));
657    test(S("abcde"), 0, 5, S("1234567890"), 1, 9, S("234567890"));
658    test(S("abcde"), 0, 5, S("1234567890"), 1, 10, S("234567890"));
659    test(S("abcde"), 0, 5, S("1234567890"), 5, 0, S(""));
660    test(S("abcde"), 0, 5, S("1234567890"), 5, 1, S("6"));
661    test(S("abcde"), 0, 5, S("1234567890"), 5, 2, S("67"));
662    test(S("abcde"), 0, 5, S("1234567890"), 5, 4, S("6789"));
663    test(S("abcde"), 0, 5, S("1234567890"), 5, 5, S("67890"));
664    test(S("abcde"), 0, 5, S("1234567890"), 5, 6, S("67890"));
665    test(S("abcde"), 0, 5, S("1234567890"), 9, 0, S(""));
666    test(S("abcde"), 0, 5, S("1234567890"), 9, 1, S("0"));
667    test(S("abcde"), 0, 5, S("1234567890"), 9, 2, S("0"));
668    test(S("abcde"), 0, 5, S("1234567890"), 10, 0, S(""));
669    test(S("abcde"), 0, 5, S("1234567890"), 10, 1, S(""));
670    test(S("abcde"), 0, 5, S("1234567890"), 11, 0, S("can't happen"));
671    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 0, S(""));
672    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 1, S("1"));
673    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 10, S("1234567890"));
674    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
675    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
676    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
677    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 0, S(""));
678    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 1, S("2"));
679    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 9, S("234567890"));
680    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 18, S("234567890123456789"));
681    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
682    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
683    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 0, S(""));
684    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 1, S("1"));
685    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 5, S("12345"));
686    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 9, S("123456789"));
687    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 10, S("1234567890"));
688    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 11, S("1234567890"));
689    test(S("abcde"), 0, 5, S("12345678901234567890"), 19, 0, S(""));
690    test(S("abcde"), 0, 5, S("12345678901234567890"), 19, 1, S("0"));
691    test(S("abcde"), 0, 5, S("12345678901234567890"), 19, 2, S("0"));
692    test(S("abcde"), 0, 5, S("12345678901234567890"), 20, 0, S(""));
693    test(S("abcde"), 0, 5, S("12345678901234567890"), 20, 1, S(""));
694    test(S("abcde"), 0, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
695    test(S("abcde"), 0, 6, S(""), 0, 0, S(""));
696    test(S("abcde"), 0, 6, S(""), 0, 1, S(""));
697    test(S("abcde"), 0, 6, S(""), 1, 0, S("can't happen"));
698    test(S("abcde"), 0, 6, S("12345"), 0, 0, S(""));
699    test(S("abcde"), 0, 6, S("12345"), 0, 1, S("1"));
700    test(S("abcde"), 0, 6, S("12345"), 0, 2, S("12"));
701    test(S("abcde"), 0, 6, S("12345"), 0, 4, S("1234"));
702    test(S("abcde"), 0, 6, S("12345"), 0, 5, S("12345"));
703}
704
705template <class S>
706void test6()
707{
708    test(S("abcde"), 0, 6, S("12345"), 0, 6, S("12345"));
709    test(S("abcde"), 0, 6, S("12345"), 1, 0, S(""));
710    test(S("abcde"), 0, 6, S("12345"), 1, 1, S("2"));
711    test(S("abcde"), 0, 6, S("12345"), 1, 2, S("23"));
712    test(S("abcde"), 0, 6, S("12345"), 1, 3, S("234"));
713    test(S("abcde"), 0, 6, S("12345"), 1, 4, S("2345"));
714    test(S("abcde"), 0, 6, S("12345"), 1, 5, S("2345"));
715    test(S("abcde"), 0, 6, S("12345"), 2, 0, S(""));
716    test(S("abcde"), 0, 6, S("12345"), 2, 1, S("3"));
717    test(S("abcde"), 0, 6, S("12345"), 2, 2, S("34"));
718    test(S("abcde"), 0, 6, S("12345"), 2, 3, S("345"));
719    test(S("abcde"), 0, 6, S("12345"), 2, 4, S("345"));
720    test(S("abcde"), 0, 6, S("12345"), 4, 0, S(""));
721    test(S("abcde"), 0, 6, S("12345"), 4, 1, S("5"));
722    test(S("abcde"), 0, 6, S("12345"), 4, 2, S("5"));
723    test(S("abcde"), 0, 6, S("12345"), 5, 0, S(""));
724    test(S("abcde"), 0, 6, S("12345"), 5, 1, S(""));
725    test(S("abcde"), 0, 6, S("12345"), 6, 0, S("can't happen"));
726    test(S("abcde"), 0, 6, S("1234567890"), 0, 0, S(""));
727    test(S("abcde"), 0, 6, S("1234567890"), 0, 1, S("1"));
728    test(S("abcde"), 0, 6, S("1234567890"), 0, 5, S("12345"));
729    test(S("abcde"), 0, 6, S("1234567890"), 0, 9, S("123456789"));
730    test(S("abcde"), 0, 6, S("1234567890"), 0, 10, S("1234567890"));
731    test(S("abcde"), 0, 6, S("1234567890"), 0, 11, S("1234567890"));
732    test(S("abcde"), 0, 6, S("1234567890"), 1, 0, S(""));
733    test(S("abcde"), 0, 6, S("1234567890"), 1, 1, S("2"));
734    test(S("abcde"), 0, 6, S("1234567890"), 1, 4, S("2345"));
735    test(S("abcde"), 0, 6, S("1234567890"), 1, 8, S("23456789"));
736    test(S("abcde"), 0, 6, S("1234567890"), 1, 9, S("234567890"));
737    test(S("abcde"), 0, 6, S("1234567890"), 1, 10, S("234567890"));
738    test(S("abcde"), 0, 6, S("1234567890"), 5, 0, S(""));
739    test(S("abcde"), 0, 6, S("1234567890"), 5, 1, S("6"));
740    test(S("abcde"), 0, 6, S("1234567890"), 5, 2, S("67"));
741    test(S("abcde"), 0, 6, S("1234567890"), 5, 4, S("6789"));
742    test(S("abcde"), 0, 6, S("1234567890"), 5, 5, S("67890"));
743    test(S("abcde"), 0, 6, S("1234567890"), 5, 6, S("67890"));
744    test(S("abcde"), 0, 6, S("1234567890"), 9, 0, S(""));
745    test(S("abcde"), 0, 6, S("1234567890"), 9, 1, S("0"));
746    test(S("abcde"), 0, 6, S("1234567890"), 9, 2, S("0"));
747    test(S("abcde"), 0, 6, S("1234567890"), 10, 0, S(""));
748    test(S("abcde"), 0, 6, S("1234567890"), 10, 1, S(""));
749    test(S("abcde"), 0, 6, S("1234567890"), 11, 0, S("can't happen"));
750    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 0, S(""));
751    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 1, S("1"));
752    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 10, S("1234567890"));
753    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
754    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
755    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
756    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 0, S(""));
757    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 1, S("2"));
758    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 9, S("234567890"));
759    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 18, S("234567890123456789"));
760    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
761    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
762    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 0, S(""));
763    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 1, S("1"));
764    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 5, S("12345"));
765    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 9, S("123456789"));
766    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 10, S("1234567890"));
767    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 11, S("1234567890"));
768    test(S("abcde"), 0, 6, S("12345678901234567890"), 19, 0, S(""));
769    test(S("abcde"), 0, 6, S("12345678901234567890"), 19, 1, S("0"));
770    test(S("abcde"), 0, 6, S("12345678901234567890"), 19, 2, S("0"));
771    test(S("abcde"), 0, 6, S("12345678901234567890"), 20, 0, S(""));
772    test(S("abcde"), 0, 6, S("12345678901234567890"), 20, 1, S(""));
773    test(S("abcde"), 0, 6, S("12345678901234567890"), 21, 0, S("can't happen"));
774    test(S("abcde"), 1, 0, S(""), 0, 0, S("abcde"));
775    test(S("abcde"), 1, 0, S(""), 0, 1, S("abcde"));
776    test(S("abcde"), 1, 0, S(""), 1, 0, S("can't happen"));
777    test(S("abcde"), 1, 0, S("12345"), 0, 0, S("abcde"));
778    test(S("abcde"), 1, 0, S("12345"), 0, 1, S("a1bcde"));
779    test(S("abcde"), 1, 0, S("12345"), 0, 2, S("a12bcde"));
780    test(S("abcde"), 1, 0, S("12345"), 0, 4, S("a1234bcde"));
781    test(S("abcde"), 1, 0, S("12345"), 0, 5, S("a12345bcde"));
782    test(S("abcde"), 1, 0, S("12345"), 0, 6, S("a12345bcde"));
783    test(S("abcde"), 1, 0, S("12345"), 1, 0, S("abcde"));
784    test(S("abcde"), 1, 0, S("12345"), 1, 1, S("a2bcde"));
785    test(S("abcde"), 1, 0, S("12345"), 1, 2, S("a23bcde"));
786    test(S("abcde"), 1, 0, S("12345"), 1, 3, S("a234bcde"));
787    test(S("abcde"), 1, 0, S("12345"), 1, 4, S("a2345bcde"));
788    test(S("abcde"), 1, 0, S("12345"), 1, 5, S("a2345bcde"));
789    test(S("abcde"), 1, 0, S("12345"), 2, 0, S("abcde"));
790    test(S("abcde"), 1, 0, S("12345"), 2, 1, S("a3bcde"));
791    test(S("abcde"), 1, 0, S("12345"), 2, 2, S("a34bcde"));
792    test(S("abcde"), 1, 0, S("12345"), 2, 3, S("a345bcde"));
793    test(S("abcde"), 1, 0, S("12345"), 2, 4, S("a345bcde"));
794    test(S("abcde"), 1, 0, S("12345"), 4, 0, S("abcde"));
795    test(S("abcde"), 1, 0, S("12345"), 4, 1, S("a5bcde"));
796    test(S("abcde"), 1, 0, S("12345"), 4, 2, S("a5bcde"));
797    test(S("abcde"), 1, 0, S("12345"), 5, 0, S("abcde"));
798    test(S("abcde"), 1, 0, S("12345"), 5, 1, S("abcde"));
799    test(S("abcde"), 1, 0, S("12345"), 6, 0, S("can't happen"));
800    test(S("abcde"), 1, 0, S("1234567890"), 0, 0, S("abcde"));
801    test(S("abcde"), 1, 0, S("1234567890"), 0, 1, S("a1bcde"));
802    test(S("abcde"), 1, 0, S("1234567890"), 0, 5, S("a12345bcde"));
803    test(S("abcde"), 1, 0, S("1234567890"), 0, 9, S("a123456789bcde"));
804    test(S("abcde"), 1, 0, S("1234567890"), 0, 10, S("a1234567890bcde"));
805    test(S("abcde"), 1, 0, S("1234567890"), 0, 11, S("a1234567890bcde"));
806    test(S("abcde"), 1, 0, S("1234567890"), 1, 0, S("abcde"));
807    test(S("abcde"), 1, 0, S("1234567890"), 1, 1, S("a2bcde"));
808}
809
810template <class S>
811void test7()
812{
813    test(S("abcde"), 1, 0, S("1234567890"), 1, 4, S("a2345bcde"));
814    test(S("abcde"), 1, 0, S("1234567890"), 1, 8, S("a23456789bcde"));
815    test(S("abcde"), 1, 0, S("1234567890"), 1, 9, S("a234567890bcde"));
816    test(S("abcde"), 1, 0, S("1234567890"), 1, 10, S("a234567890bcde"));
817    test(S("abcde"), 1, 0, S("1234567890"), 5, 0, S("abcde"));
818    test(S("abcde"), 1, 0, S("1234567890"), 5, 1, S("a6bcde"));
819    test(S("abcde"), 1, 0, S("1234567890"), 5, 2, S("a67bcde"));
820    test(S("abcde"), 1, 0, S("1234567890"), 5, 4, S("a6789bcde"));
821    test(S("abcde"), 1, 0, S("1234567890"), 5, 5, S("a67890bcde"));
822    test(S("abcde"), 1, 0, S("1234567890"), 5, 6, S("a67890bcde"));
823    test(S("abcde"), 1, 0, S("1234567890"), 9, 0, S("abcde"));
824    test(S("abcde"), 1, 0, S("1234567890"), 9, 1, S("a0bcde"));
825    test(S("abcde"), 1, 0, S("1234567890"), 9, 2, S("a0bcde"));
826    test(S("abcde"), 1, 0, S("1234567890"), 10, 0, S("abcde"));
827    test(S("abcde"), 1, 0, S("1234567890"), 10, 1, S("abcde"));
828    test(S("abcde"), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
829    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 0, S("abcde"));
830    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 1, S("a1bcde"));
831    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 10, S("a1234567890bcde"));
832    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcde"));
833    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcde"));
834    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcde"));
835    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 0, S("abcde"));
836    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 1, S("a2bcde"));
837    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 9, S("a234567890bcde"));
838    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 18, S("a234567890123456789bcde"));
839    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcde"));
840    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcde"));
841    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 0, S("abcde"));
842    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 1, S("a1bcde"));
843    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 5, S("a12345bcde"));
844    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 9, S("a123456789bcde"));
845    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 10, S("a1234567890bcde"));
846    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 11, S("a1234567890bcde"));
847    test(S("abcde"), 1, 0, S("12345678901234567890"), 19, 0, S("abcde"));
848    test(S("abcde"), 1, 0, S("12345678901234567890"), 19, 1, S("a0bcde"));
849    test(S("abcde"), 1, 0, S("12345678901234567890"), 19, 2, S("a0bcde"));
850    test(S("abcde"), 1, 0, S("12345678901234567890"), 20, 0, S("abcde"));
851    test(S("abcde"), 1, 0, S("12345678901234567890"), 20, 1, S("abcde"));
852    test(S("abcde"), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
853    test(S("abcde"), 1, 1, S(""), 0, 0, S("acde"));
854    test(S("abcde"), 1, 1, S(""), 0, 1, S("acde"));
855    test(S("abcde"), 1, 1, S(""), 1, 0, S("can't happen"));
856    test(S("abcde"), 1, 1, S("12345"), 0, 0, S("acde"));
857    test(S("abcde"), 1, 1, S("12345"), 0, 1, S("a1cde"));
858    test(S("abcde"), 1, 1, S("12345"), 0, 2, S("a12cde"));
859    test(S("abcde"), 1, 1, S("12345"), 0, 4, S("a1234cde"));
860    test(S("abcde"), 1, 1, S("12345"), 0, 5, S("a12345cde"));
861    test(S("abcde"), 1, 1, S("12345"), 0, 6, S("a12345cde"));
862    test(S("abcde"), 1, 1, S("12345"), 1, 0, S("acde"));
863    test(S("abcde"), 1, 1, S("12345"), 1, 1, S("a2cde"));
864    test(S("abcde"), 1, 1, S("12345"), 1, 2, S("a23cde"));
865    test(S("abcde"), 1, 1, S("12345"), 1, 3, S("a234cde"));
866    test(S("abcde"), 1, 1, S("12345"), 1, 4, S("a2345cde"));
867    test(S("abcde"), 1, 1, S("12345"), 1, 5, S("a2345cde"));
868    test(S("abcde"), 1, 1, S("12345"), 2, 0, S("acde"));
869    test(S("abcde"), 1, 1, S("12345"), 2, 1, S("a3cde"));
870    test(S("abcde"), 1, 1, S("12345"), 2, 2, S("a34cde"));
871    test(S("abcde"), 1, 1, S("12345"), 2, 3, S("a345cde"));
872    test(S("abcde"), 1, 1, S("12345"), 2, 4, S("a345cde"));
873    test(S("abcde"), 1, 1, S("12345"), 4, 0, S("acde"));
874    test(S("abcde"), 1, 1, S("12345"), 4, 1, S("a5cde"));
875    test(S("abcde"), 1, 1, S("12345"), 4, 2, S("a5cde"));
876    test(S("abcde"), 1, 1, S("12345"), 5, 0, S("acde"));
877    test(S("abcde"), 1, 1, S("12345"), 5, 1, S("acde"));
878    test(S("abcde"), 1, 1, S("12345"), 6, 0, S("can't happen"));
879    test(S("abcde"), 1, 1, S("1234567890"), 0, 0, S("acde"));
880    test(S("abcde"), 1, 1, S("1234567890"), 0, 1, S("a1cde"));
881    test(S("abcde"), 1, 1, S("1234567890"), 0, 5, S("a12345cde"));
882    test(S("abcde"), 1, 1, S("1234567890"), 0, 9, S("a123456789cde"));
883    test(S("abcde"), 1, 1, S("1234567890"), 0, 10, S("a1234567890cde"));
884    test(S("abcde"), 1, 1, S("1234567890"), 0, 11, S("a1234567890cde"));
885    test(S("abcde"), 1, 1, S("1234567890"), 1, 0, S("acde"));
886    test(S("abcde"), 1, 1, S("1234567890"), 1, 1, S("a2cde"));
887    test(S("abcde"), 1, 1, S("1234567890"), 1, 4, S("a2345cde"));
888    test(S("abcde"), 1, 1, S("1234567890"), 1, 8, S("a23456789cde"));
889    test(S("abcde"), 1, 1, S("1234567890"), 1, 9, S("a234567890cde"));
890    test(S("abcde"), 1, 1, S("1234567890"), 1, 10, S("a234567890cde"));
891    test(S("abcde"), 1, 1, S("1234567890"), 5, 0, S("acde"));
892    test(S("abcde"), 1, 1, S("1234567890"), 5, 1, S("a6cde"));
893    test(S("abcde"), 1, 1, S("1234567890"), 5, 2, S("a67cde"));
894    test(S("abcde"), 1, 1, S("1234567890"), 5, 4, S("a6789cde"));
895    test(S("abcde"), 1, 1, S("1234567890"), 5, 5, S("a67890cde"));
896    test(S("abcde"), 1, 1, S("1234567890"), 5, 6, S("a67890cde"));
897    test(S("abcde"), 1, 1, S("1234567890"), 9, 0, S("acde"));
898    test(S("abcde"), 1, 1, S("1234567890"), 9, 1, S("a0cde"));
899    test(S("abcde"), 1, 1, S("1234567890"), 9, 2, S("a0cde"));
900    test(S("abcde"), 1, 1, S("1234567890"), 10, 0, S("acde"));
901    test(S("abcde"), 1, 1, S("1234567890"), 10, 1, S("acde"));
902    test(S("abcde"), 1, 1, S("1234567890"), 11, 0, S("can't happen"));
903    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 0, S("acde"));
904    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 1, S("a1cde"));
905    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 10, S("a1234567890cde"));
906    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789cde"));
907    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890cde"));
908    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890cde"));
909    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 0, S("acde"));
910    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 1, S("a2cde"));
911    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 9, S("a234567890cde"));
912    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 18, S("a234567890123456789cde"));
913}
914
915template <class S>
916void test8()
917{
918    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890cde"));
919    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890cde"));
920    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 0, S("acde"));
921    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 1, S("a1cde"));
922    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 5, S("a12345cde"));
923    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 9, S("a123456789cde"));
924    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 10, S("a1234567890cde"));
925    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 11, S("a1234567890cde"));
926    test(S("abcde"), 1, 1, S("12345678901234567890"), 19, 0, S("acde"));
927    test(S("abcde"), 1, 1, S("12345678901234567890"), 19, 1, S("a0cde"));
928    test(S("abcde"), 1, 1, S("12345678901234567890"), 19, 2, S("a0cde"));
929    test(S("abcde"), 1, 1, S("12345678901234567890"), 20, 0, S("acde"));
930    test(S("abcde"), 1, 1, S("12345678901234567890"), 20, 1, S("acde"));
931    test(S("abcde"), 1, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
932    test(S("abcde"), 1, 2, S(""), 0, 0, S("ade"));
933    test(S("abcde"), 1, 2, S(""), 0, 1, S("ade"));
934    test(S("abcde"), 1, 2, S(""), 1, 0, S("can't happen"));
935    test(S("abcde"), 1, 2, S("12345"), 0, 0, S("ade"));
936    test(S("abcde"), 1, 2, S("12345"), 0, 1, S("a1de"));
937    test(S("abcde"), 1, 2, S("12345"), 0, 2, S("a12de"));
938    test(S("abcde"), 1, 2, S("12345"), 0, 4, S("a1234de"));
939    test(S("abcde"), 1, 2, S("12345"), 0, 5, S("a12345de"));
940    test(S("abcde"), 1, 2, S("12345"), 0, 6, S("a12345de"));
941    test(S("abcde"), 1, 2, S("12345"), 1, 0, S("ade"));
942    test(S("abcde"), 1, 2, S("12345"), 1, 1, S("a2de"));
943    test(S("abcde"), 1, 2, S("12345"), 1, 2, S("a23de"));
944    test(S("abcde"), 1, 2, S("12345"), 1, 3, S("a234de"));
945    test(S("abcde"), 1, 2, S("12345"), 1, 4, S("a2345de"));
946    test(S("abcde"), 1, 2, S("12345"), 1, 5, S("a2345de"));
947    test(S("abcde"), 1, 2, S("12345"), 2, 0, S("ade"));
948    test(S("abcde"), 1, 2, S("12345"), 2, 1, S("a3de"));
949    test(S("abcde"), 1, 2, S("12345"), 2, 2, S("a34de"));
950    test(S("abcde"), 1, 2, S("12345"), 2, 3, S("a345de"));
951    test(S("abcde"), 1, 2, S("12345"), 2, 4, S("a345de"));
952    test(S("abcde"), 1, 2, S("12345"), 4, 0, S("ade"));
953    test(S("abcde"), 1, 2, S("12345"), 4, 1, S("a5de"));
954    test(S("abcde"), 1, 2, S("12345"), 4, 2, S("a5de"));
955    test(S("abcde"), 1, 2, S("12345"), 5, 0, S("ade"));
956    test(S("abcde"), 1, 2, S("12345"), 5, 1, S("ade"));
957    test(S("abcde"), 1, 2, S("12345"), 6, 0, S("can't happen"));
958    test(S("abcde"), 1, 2, S("1234567890"), 0, 0, S("ade"));
959    test(S("abcde"), 1, 2, S("1234567890"), 0, 1, S("a1de"));
960    test(S("abcde"), 1, 2, S("1234567890"), 0, 5, S("a12345de"));
961    test(S("abcde"), 1, 2, S("1234567890"), 0, 9, S("a123456789de"));
962    test(S("abcde"), 1, 2, S("1234567890"), 0, 10, S("a1234567890de"));
963    test(S("abcde"), 1, 2, S("1234567890"), 0, 11, S("a1234567890de"));
964    test(S("abcde"), 1, 2, S("1234567890"), 1, 0, S("ade"));
965    test(S("abcde"), 1, 2, S("1234567890"), 1, 1, S("a2de"));
966    test(S("abcde"), 1, 2, S("1234567890"), 1, 4, S("a2345de"));
967    test(S("abcde"), 1, 2, S("1234567890"), 1, 8, S("a23456789de"));
968    test(S("abcde"), 1, 2, S("1234567890"), 1, 9, S("a234567890de"));
969    test(S("abcde"), 1, 2, S("1234567890"), 1, 10, S("a234567890de"));
970    test(S("abcde"), 1, 2, S("1234567890"), 5, 0, S("ade"));
971    test(S("abcde"), 1, 2, S("1234567890"), 5, 1, S("a6de"));
972    test(S("abcde"), 1, 2, S("1234567890"), 5, 2, S("a67de"));
973    test(S("abcde"), 1, 2, S("1234567890"), 5, 4, S("a6789de"));
974    test(S("abcde"), 1, 2, S("1234567890"), 5, 5, S("a67890de"));
975    test(S("abcde"), 1, 2, S("1234567890"), 5, 6, S("a67890de"));
976    test(S("abcde"), 1, 2, S("1234567890"), 9, 0, S("ade"));
977    test(S("abcde"), 1, 2, S("1234567890"), 9, 1, S("a0de"));
978    test(S("abcde"), 1, 2, S("1234567890"), 9, 2, S("a0de"));
979    test(S("abcde"), 1, 2, S("1234567890"), 10, 0, S("ade"));
980    test(S("abcde"), 1, 2, S("1234567890"), 10, 1, S("ade"));
981    test(S("abcde"), 1, 2, S("1234567890"), 11, 0, S("can't happen"));
982    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 0, S("ade"));
983    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 1, S("a1de"));
984    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 10, S("a1234567890de"));
985    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 19, S("a1234567890123456789de"));
986    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 20, S("a12345678901234567890de"));
987    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 21, S("a12345678901234567890de"));
988    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 0, S("ade"));
989    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 1, S("a2de"));
990    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 9, S("a234567890de"));
991    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 18, S("a234567890123456789de"));
992    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 19, S("a2345678901234567890de"));
993    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 20, S("a2345678901234567890de"));
994    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 0, S("ade"));
995    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 1, S("a1de"));
996    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 5, S("a12345de"));
997    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 9, S("a123456789de"));
998    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 10, S("a1234567890de"));
999    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 11, S("a1234567890de"));
1000    test(S("abcde"), 1, 2, S("12345678901234567890"), 19, 0, S("ade"));
1001    test(S("abcde"), 1, 2, S("12345678901234567890"), 19, 1, S("a0de"));
1002    test(S("abcde"), 1, 2, S("12345678901234567890"), 19, 2, S("a0de"));
1003    test(S("abcde"), 1, 2, S("12345678901234567890"), 20, 0, S("ade"));
1004    test(S("abcde"), 1, 2, S("12345678901234567890"), 20, 1, S("ade"));
1005    test(S("abcde"), 1, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
1006    test(S("abcde"), 1, 3, S(""), 0, 0, S("ae"));
1007    test(S("abcde"), 1, 3, S(""), 0, 1, S("ae"));
1008    test(S("abcde"), 1, 3, S(""), 1, 0, S("can't happen"));
1009    test(S("abcde"), 1, 3, S("12345"), 0, 0, S("ae"));
1010    test(S("abcde"), 1, 3, S("12345"), 0, 1, S("a1e"));
1011    test(S("abcde"), 1, 3, S("12345"), 0, 2, S("a12e"));
1012    test(S("abcde"), 1, 3, S("12345"), 0, 4, S("a1234e"));
1013    test(S("abcde"), 1, 3, S("12345"), 0, 5, S("a12345e"));
1014    test(S("abcde"), 1, 3, S("12345"), 0, 6, S("a12345e"));
1015    test(S("abcde"), 1, 3, S("12345"), 1, 0, S("ae"));
1016    test(S("abcde"), 1, 3, S("12345"), 1, 1, S("a2e"));
1017    test(S("abcde"), 1, 3, S("12345"), 1, 2, S("a23e"));
1018}
1019
1020template <class S>
1021void test9()
1022{
1023    test(S("abcde"), 1, 3, S("12345"), 1, 3, S("a234e"));
1024    test(S("abcde"), 1, 3, S("12345"), 1, 4, S("a2345e"));
1025    test(S("abcde"), 1, 3, S("12345"), 1, 5, S("a2345e"));
1026    test(S("abcde"), 1, 3, S("12345"), 2, 0, S("ae"));
1027    test(S("abcde"), 1, 3, S("12345"), 2, 1, S("a3e"));
1028    test(S("abcde"), 1, 3, S("12345"), 2, 2, S("a34e"));
1029    test(S("abcde"), 1, 3, S("12345"), 2, 3, S("a345e"));
1030    test(S("abcde"), 1, 3, S("12345"), 2, 4, S("a345e"));
1031    test(S("abcde"), 1, 3, S("12345"), 4, 0, S("ae"));
1032    test(S("abcde"), 1, 3, S("12345"), 4, 1, S("a5e"));
1033    test(S("abcde"), 1, 3, S("12345"), 4, 2, S("a5e"));
1034    test(S("abcde"), 1, 3, S("12345"), 5, 0, S("ae"));
1035    test(S("abcde"), 1, 3, S("12345"), 5, 1, S("ae"));
1036    test(S("abcde"), 1, 3, S("12345"), 6, 0, S("can't happen"));
1037    test(S("abcde"), 1, 3, S("1234567890"), 0, 0, S("ae"));
1038    test(S("abcde"), 1, 3, S("1234567890"), 0, 1, S("a1e"));
1039    test(S("abcde"), 1, 3, S("1234567890"), 0, 5, S("a12345e"));
1040    test(S("abcde"), 1, 3, S("1234567890"), 0, 9, S("a123456789e"));
1041    test(S("abcde"), 1, 3, S("1234567890"), 0, 10, S("a1234567890e"));
1042    test(S("abcde"), 1, 3, S("1234567890"), 0, 11, S("a1234567890e"));
1043    test(S("abcde"), 1, 3, S("1234567890"), 1, 0, S("ae"));
1044    test(S("abcde"), 1, 3, S("1234567890"), 1, 1, S("a2e"));
1045    test(S("abcde"), 1, 3, S("1234567890"), 1, 4, S("a2345e"));
1046    test(S("abcde"), 1, 3, S("1234567890"), 1, 8, S("a23456789e"));
1047    test(S("abcde"), 1, 3, S("1234567890"), 1, 9, S("a234567890e"));
1048    test(S("abcde"), 1, 3, S("1234567890"), 1, 10, S("a234567890e"));
1049    test(S("abcde"), 1, 3, S("1234567890"), 5, 0, S("ae"));
1050    test(S("abcde"), 1, 3, S("1234567890"), 5, 1, S("a6e"));
1051    test(S("abcde"), 1, 3, S("1234567890"), 5, 2, S("a67e"));
1052    test(S("abcde"), 1, 3, S("1234567890"), 5, 4, S("a6789e"));
1053    test(S("abcde"), 1, 3, S("1234567890"), 5, 5, S("a67890e"));
1054    test(S("abcde"), 1, 3, S("1234567890"), 5, 6, S("a67890e"));
1055    test(S("abcde"), 1, 3, S("1234567890"), 9, 0, S("ae"));
1056    test(S("abcde"), 1, 3, S("1234567890"), 9, 1, S("a0e"));
1057    test(S("abcde"), 1, 3, S("1234567890"), 9, 2, S("a0e"));
1058    test(S("abcde"), 1, 3, S("1234567890"), 10, 0, S("ae"));
1059    test(S("abcde"), 1, 3, S("1234567890"), 10, 1, S("ae"));
1060    test(S("abcde"), 1, 3, S("1234567890"), 11, 0, S("can't happen"));
1061    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 0, S("ae"));
1062    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 1, S("a1e"));
1063    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 10, S("a1234567890e"));
1064    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 19, S("a1234567890123456789e"));
1065    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 20, S("a12345678901234567890e"));
1066    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 21, S("a12345678901234567890e"));
1067    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 0, S("ae"));
1068    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 1, S("a2e"));
1069    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 9, S("a234567890e"));
1070    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 18, S("a234567890123456789e"));
1071    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 19, S("a2345678901234567890e"));
1072    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 20, S("a2345678901234567890e"));
1073    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 0, S("ae"));
1074    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 1, S("a1e"));
1075    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 5, S("a12345e"));
1076    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 9, S("a123456789e"));
1077    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 10, S("a1234567890e"));
1078    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 11, S("a1234567890e"));
1079    test(S("abcde"), 1, 3, S("12345678901234567890"), 19, 0, S("ae"));
1080    test(S("abcde"), 1, 3, S("12345678901234567890"), 19, 1, S("a0e"));
1081    test(S("abcde"), 1, 3, S("12345678901234567890"), 19, 2, S("a0e"));
1082    test(S("abcde"), 1, 3, S("12345678901234567890"), 20, 0, S("ae"));
1083    test(S("abcde"), 1, 3, S("12345678901234567890"), 20, 1, S("ae"));
1084    test(S("abcde"), 1, 3, S("12345678901234567890"), 21, 0, S("can't happen"));
1085    test(S("abcde"), 1, 4, S(""), 0, 0, S("a"));
1086    test(S("abcde"), 1, 4, S(""), 0, 1, S("a"));
1087    test(S("abcde"), 1, 4, S(""), 1, 0, S("can't happen"));
1088    test(S("abcde"), 1, 4, S("12345"), 0, 0, S("a"));
1089    test(S("abcde"), 1, 4, S("12345"), 0, 1, S("a1"));
1090    test(S("abcde"), 1, 4, S("12345"), 0, 2, S("a12"));
1091    test(S("abcde"), 1, 4, S("12345"), 0, 4, S("a1234"));
1092    test(S("abcde"), 1, 4, S("12345"), 0, 5, S("a12345"));
1093    test(S("abcde"), 1, 4, S("12345"), 0, 6, S("a12345"));
1094    test(S("abcde"), 1, 4, S("12345"), 1, 0, S("a"));
1095    test(S("abcde"), 1, 4, S("12345"), 1, 1, S("a2"));
1096    test(S("abcde"), 1, 4, S("12345"), 1, 2, S("a23"));
1097    test(S("abcde"), 1, 4, S("12345"), 1, 3, S("a234"));
1098    test(S("abcde"), 1, 4, S("12345"), 1, 4, S("a2345"));
1099    test(S("abcde"), 1, 4, S("12345"), 1, 5, S("a2345"));
1100    test(S("abcde"), 1, 4, S("12345"), 2, 0, S("a"));
1101    test(S("abcde"), 1, 4, S("12345"), 2, 1, S("a3"));
1102    test(S("abcde"), 1, 4, S("12345"), 2, 2, S("a34"));
1103    test(S("abcde"), 1, 4, S("12345"), 2, 3, S("a345"));
1104    test(S("abcde"), 1, 4, S("12345"), 2, 4, S("a345"));
1105    test(S("abcde"), 1, 4, S("12345"), 4, 0, S("a"));
1106    test(S("abcde"), 1, 4, S("12345"), 4, 1, S("a5"));
1107    test(S("abcde"), 1, 4, S("12345"), 4, 2, S("a5"));
1108    test(S("abcde"), 1, 4, S("12345"), 5, 0, S("a"));
1109    test(S("abcde"), 1, 4, S("12345"), 5, 1, S("a"));
1110    test(S("abcde"), 1, 4, S("12345"), 6, 0, S("can't happen"));
1111    test(S("abcde"), 1, 4, S("1234567890"), 0, 0, S("a"));
1112    test(S("abcde"), 1, 4, S("1234567890"), 0, 1, S("a1"));
1113    test(S("abcde"), 1, 4, S("1234567890"), 0, 5, S("a12345"));
1114    test(S("abcde"), 1, 4, S("1234567890"), 0, 9, S("a123456789"));
1115    test(S("abcde"), 1, 4, S("1234567890"), 0, 10, S("a1234567890"));
1116    test(S("abcde"), 1, 4, S("1234567890"), 0, 11, S("a1234567890"));
1117    test(S("abcde"), 1, 4, S("1234567890"), 1, 0, S("a"));
1118    test(S("abcde"), 1, 4, S("1234567890"), 1, 1, S("a2"));
1119    test(S("abcde"), 1, 4, S("1234567890"), 1, 4, S("a2345"));
1120    test(S("abcde"), 1, 4, S("1234567890"), 1, 8, S("a23456789"));
1121    test(S("abcde"), 1, 4, S("1234567890"), 1, 9, S("a234567890"));
1122    test(S("abcde"), 1, 4, S("1234567890"), 1, 10, S("a234567890"));
1123}
1124
1125template <class S>
1126void test10()
1127{
1128    test(S("abcde"), 1, 4, S("1234567890"), 5, 0, S("a"));
1129    test(S("abcde"), 1, 4, S("1234567890"), 5, 1, S("a6"));
1130    test(S("abcde"), 1, 4, S("1234567890"), 5, 2, S("a67"));
1131    test(S("abcde"), 1, 4, S("1234567890"), 5, 4, S("a6789"));
1132    test(S("abcde"), 1, 4, S("1234567890"), 5, 5, S("a67890"));
1133    test(S("abcde"), 1, 4, S("1234567890"), 5, 6, S("a67890"));
1134    test(S("abcde"), 1, 4, S("1234567890"), 9, 0, S("a"));
1135    test(S("abcde"), 1, 4, S("1234567890"), 9, 1, S("a0"));
1136    test(S("abcde"), 1, 4, S("1234567890"), 9, 2, S("a0"));
1137    test(S("abcde"), 1, 4, S("1234567890"), 10, 0, S("a"));
1138    test(S("abcde"), 1, 4, S("1234567890"), 10, 1, S("a"));
1139    test(S("abcde"), 1, 4, S("1234567890"), 11, 0, S("can't happen"));
1140    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 0, S("a"));
1141    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 1, S("a1"));
1142    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 10, S("a1234567890"));
1143    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
1144    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
1145    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
1146    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 0, S("a"));
1147    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 1, S("a2"));
1148    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 9, S("a234567890"));
1149    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
1150    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
1151    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
1152    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 0, S("a"));
1153    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 1, S("a1"));
1154    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 5, S("a12345"));
1155    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 9, S("a123456789"));
1156    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 10, S("a1234567890"));
1157    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 11, S("a1234567890"));
1158    test(S("abcde"), 1, 4, S("12345678901234567890"), 19, 0, S("a"));
1159    test(S("abcde"), 1, 4, S("12345678901234567890"), 19, 1, S("a0"));
1160    test(S("abcde"), 1, 4, S("12345678901234567890"), 19, 2, S("a0"));
1161    test(S("abcde"), 1, 4, S("12345678901234567890"), 20, 0, S("a"));
1162    test(S("abcde"), 1, 4, S("12345678901234567890"), 20, 1, S("a"));
1163    test(S("abcde"), 1, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
1164    test(S("abcde"), 1, 5, S(""), 0, 0, S("a"));
1165    test(S("abcde"), 1, 5, S(""), 0, 1, S("a"));
1166    test(S("abcde"), 1, 5, S(""), 1, 0, S("can't happen"));
1167    test(S("abcde"), 1, 5, S("12345"), 0, 0, S("a"));
1168    test(S("abcde"), 1, 5, S("12345"), 0, 1, S("a1"));
1169    test(S("abcde"), 1, 5, S("12345"), 0, 2, S("a12"));
1170    test(S("abcde"), 1, 5, S("12345"), 0, 4, S("a1234"));
1171    test(S("abcde"), 1, 5, S("12345"), 0, 5, S("a12345"));
1172    test(S("abcde"), 1, 5, S("12345"), 0, 6, S("a12345"));
1173    test(S("abcde"), 1, 5, S("12345"), 1, 0, S("a"));
1174    test(S("abcde"), 1, 5, S("12345"), 1, 1, S("a2"));
1175    test(S("abcde"), 1, 5, S("12345"), 1, 2, S("a23"));
1176    test(S("abcde"), 1, 5, S("12345"), 1, 3, S("a234"));
1177    test(S("abcde"), 1, 5, S("12345"), 1, 4, S("a2345"));
1178    test(S("abcde"), 1, 5, S("12345"), 1, 5, S("a2345"));
1179    test(S("abcde"), 1, 5, S("12345"), 2, 0, S("a"));
1180    test(S("abcde"), 1, 5, S("12345"), 2, 1, S("a3"));
1181    test(S("abcde"), 1, 5, S("12345"), 2, 2, S("a34"));
1182    test(S("abcde"), 1, 5, S("12345"), 2, 3, S("a345"));
1183    test(S("abcde"), 1, 5, S("12345"), 2, 4, S("a345"));
1184    test(S("abcde"), 1, 5, S("12345"), 4, 0, S("a"));
1185    test(S("abcde"), 1, 5, S("12345"), 4, 1, S("a5"));
1186    test(S("abcde"), 1, 5, S("12345"), 4, 2, S("a5"));
1187    test(S("abcde"), 1, 5, S("12345"), 5, 0, S("a"));
1188    test(S("abcde"), 1, 5, S("12345"), 5, 1, S("a"));
1189    test(S("abcde"), 1, 5, S("12345"), 6, 0, S("can't happen"));
1190    test(S("abcde"), 1, 5, S("1234567890"), 0, 0, S("a"));
1191    test(S("abcde"), 1, 5, S("1234567890"), 0, 1, S("a1"));
1192    test(S("abcde"), 1, 5, S("1234567890"), 0, 5, S("a12345"));
1193    test(S("abcde"), 1, 5, S("1234567890"), 0, 9, S("a123456789"));
1194    test(S("abcde"), 1, 5, S("1234567890"), 0, 10, S("a1234567890"));
1195    test(S("abcde"), 1, 5, S("1234567890"), 0, 11, S("a1234567890"));
1196    test(S("abcde"), 1, 5, S("1234567890"), 1, 0, S("a"));
1197    test(S("abcde"), 1, 5, S("1234567890"), 1, 1, S("a2"));
1198    test(S("abcde"), 1, 5, S("1234567890"), 1, 4, S("a2345"));
1199    test(S("abcde"), 1, 5, S("1234567890"), 1, 8, S("a23456789"));
1200    test(S("abcde"), 1, 5, S("1234567890"), 1, 9, S("a234567890"));
1201    test(S("abcde"), 1, 5, S("1234567890"), 1, 10, S("a234567890"));
1202    test(S("abcde"), 1, 5, S("1234567890"), 5, 0, S("a"));
1203    test(S("abcde"), 1, 5, S("1234567890"), 5, 1, S("a6"));
1204    test(S("abcde"), 1, 5, S("1234567890"), 5, 2, S("a67"));
1205    test(S("abcde"), 1, 5, S("1234567890"), 5, 4, S("a6789"));
1206    test(S("abcde"), 1, 5, S("1234567890"), 5, 5, S("a67890"));
1207    test(S("abcde"), 1, 5, S("1234567890"), 5, 6, S("a67890"));
1208    test(S("abcde"), 1, 5, S("1234567890"), 9, 0, S("a"));
1209    test(S("abcde"), 1, 5, S("1234567890"), 9, 1, S("a0"));
1210    test(S("abcde"), 1, 5, S("1234567890"), 9, 2, S("a0"));
1211    test(S("abcde"), 1, 5, S("1234567890"), 10, 0, S("a"));
1212    test(S("abcde"), 1, 5, S("1234567890"), 10, 1, S("a"));
1213    test(S("abcde"), 1, 5, S("1234567890"), 11, 0, S("can't happen"));
1214    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 0, S("a"));
1215    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 1, S("a1"));
1216    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 10, S("a1234567890"));
1217    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
1218    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
1219    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
1220    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 0, S("a"));
1221    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 1, S("a2"));
1222    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 9, S("a234567890"));
1223    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
1224    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
1225    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
1226    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 0, S("a"));
1227    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 1, S("a1"));
1228}
1229
1230template <class S>
1231void test11()
1232{
1233    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 5, S("a12345"));
1234    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 9, S("a123456789"));
1235    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 10, S("a1234567890"));
1236    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 11, S("a1234567890"));
1237    test(S("abcde"), 1, 5, S("12345678901234567890"), 19, 0, S("a"));
1238    test(S("abcde"), 1, 5, S("12345678901234567890"), 19, 1, S("a0"));
1239    test(S("abcde"), 1, 5, S("12345678901234567890"), 19, 2, S("a0"));
1240    test(S("abcde"), 1, 5, S("12345678901234567890"), 20, 0, S("a"));
1241    test(S("abcde"), 1, 5, S("12345678901234567890"), 20, 1, S("a"));
1242    test(S("abcde"), 1, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
1243    test(S("abcde"), 2, 0, S(""), 0, 0, S("abcde"));
1244    test(S("abcde"), 2, 0, S(""), 0, 1, S("abcde"));
1245    test(S("abcde"), 2, 0, S(""), 1, 0, S("can't happen"));
1246    test(S("abcde"), 2, 0, S("12345"), 0, 0, S("abcde"));
1247    test(S("abcde"), 2, 0, S("12345"), 0, 1, S("ab1cde"));
1248    test(S("abcde"), 2, 0, S("12345"), 0, 2, S("ab12cde"));
1249    test(S("abcde"), 2, 0, S("12345"), 0, 4, S("ab1234cde"));
1250    test(S("abcde"), 2, 0, S("12345"), 0, 5, S("ab12345cde"));
1251    test(S("abcde"), 2, 0, S("12345"), 0, 6, S("ab12345cde"));
1252    test(S("abcde"), 2, 0, S("12345"), 1, 0, S("abcde"));
1253    test(S("abcde"), 2, 0, S("12345"), 1, 1, S("ab2cde"));
1254    test(S("abcde"), 2, 0, S("12345"), 1, 2, S("ab23cde"));
1255    test(S("abcde"), 2, 0, S("12345"), 1, 3, S("ab234cde"));
1256    test(S("abcde"), 2, 0, S("12345"), 1, 4, S("ab2345cde"));
1257    test(S("abcde"), 2, 0, S("12345"), 1, 5, S("ab2345cde"));
1258    test(S("abcde"), 2, 0, S("12345"), 2, 0, S("abcde"));
1259    test(S("abcde"), 2, 0, S("12345"), 2, 1, S("ab3cde"));
1260    test(S("abcde"), 2, 0, S("12345"), 2, 2, S("ab34cde"));
1261    test(S("abcde"), 2, 0, S("12345"), 2, 3, S("ab345cde"));
1262    test(S("abcde"), 2, 0, S("12345"), 2, 4, S("ab345cde"));
1263    test(S("abcde"), 2, 0, S("12345"), 4, 0, S("abcde"));
1264    test(S("abcde"), 2, 0, S("12345"), 4, 1, S("ab5cde"));
1265    test(S("abcde"), 2, 0, S("12345"), 4, 2, S("ab5cde"));
1266    test(S("abcde"), 2, 0, S("12345"), 5, 0, S("abcde"));
1267    test(S("abcde"), 2, 0, S("12345"), 5, 1, S("abcde"));
1268    test(S("abcde"), 2, 0, S("12345"), 6, 0, S("can't happen"));
1269    test(S("abcde"), 2, 0, S("1234567890"), 0, 0, S("abcde"));
1270    test(S("abcde"), 2, 0, S("1234567890"), 0, 1, S("ab1cde"));
1271    test(S("abcde"), 2, 0, S("1234567890"), 0, 5, S("ab12345cde"));
1272    test(S("abcde"), 2, 0, S("1234567890"), 0, 9, S("ab123456789cde"));
1273    test(S("abcde"), 2, 0, S("1234567890"), 0, 10, S("ab1234567890cde"));
1274    test(S("abcde"), 2, 0, S("1234567890"), 0, 11, S("ab1234567890cde"));
1275    test(S("abcde"), 2, 0, S("1234567890"), 1, 0, S("abcde"));
1276    test(S("abcde"), 2, 0, S("1234567890"), 1, 1, S("ab2cde"));
1277    test(S("abcde"), 2, 0, S("1234567890"), 1, 4, S("ab2345cde"));
1278    test(S("abcde"), 2, 0, S("1234567890"), 1, 8, S("ab23456789cde"));
1279    test(S("abcde"), 2, 0, S("1234567890"), 1, 9, S("ab234567890cde"));
1280    test(S("abcde"), 2, 0, S("1234567890"), 1, 10, S("ab234567890cde"));
1281    test(S("abcde"), 2, 0, S("1234567890"), 5, 0, S("abcde"));
1282    test(S("abcde"), 2, 0, S("1234567890"), 5, 1, S("ab6cde"));
1283    test(S("abcde"), 2, 0, S("1234567890"), 5, 2, S("ab67cde"));
1284    test(S("abcde"), 2, 0, S("1234567890"), 5, 4, S("ab6789cde"));
1285    test(S("abcde"), 2, 0, S("1234567890"), 5, 5, S("ab67890cde"));
1286    test(S("abcde"), 2, 0, S("1234567890"), 5, 6, S("ab67890cde"));
1287    test(S("abcde"), 2, 0, S("1234567890"), 9, 0, S("abcde"));
1288    test(S("abcde"), 2, 0, S("1234567890"), 9, 1, S("ab0cde"));
1289    test(S("abcde"), 2, 0, S("1234567890"), 9, 2, S("ab0cde"));
1290    test(S("abcde"), 2, 0, S("1234567890"), 10, 0, S("abcde"));
1291    test(S("abcde"), 2, 0, S("1234567890"), 10, 1, S("abcde"));
1292    test(S("abcde"), 2, 0, S("1234567890"), 11, 0, S("can't happen"));
1293    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 0, S("abcde"));
1294    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 1, S("ab1cde"));
1295    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 10, S("ab1234567890cde"));
1296    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 19, S("ab1234567890123456789cde"));
1297    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 20, S("ab12345678901234567890cde"));
1298    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 21, S("ab12345678901234567890cde"));
1299    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 0, S("abcde"));
1300    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 1, S("ab2cde"));
1301    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 9, S("ab234567890cde"));
1302    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 18, S("ab234567890123456789cde"));
1303    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 19, S("ab2345678901234567890cde"));
1304    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 20, S("ab2345678901234567890cde"));
1305    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 0, S("abcde"));
1306    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 1, S("ab1cde"));
1307    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 5, S("ab12345cde"));
1308    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 9, S("ab123456789cde"));
1309    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 10, S("ab1234567890cde"));
1310    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 11, S("ab1234567890cde"));
1311    test(S("abcde"), 2, 0, S("12345678901234567890"), 19, 0, S("abcde"));
1312    test(S("abcde"), 2, 0, S("12345678901234567890"), 19, 1, S("ab0cde"));
1313    test(S("abcde"), 2, 0, S("12345678901234567890"), 19, 2, S("ab0cde"));
1314    test(S("abcde"), 2, 0, S("12345678901234567890"), 20, 0, S("abcde"));
1315    test(S("abcde"), 2, 0, S("12345678901234567890"), 20, 1, S("abcde"));
1316    test(S("abcde"), 2, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
1317    test(S("abcde"), 2, 1, S(""), 0, 0, S("abde"));
1318    test(S("abcde"), 2, 1, S(""), 0, 1, S("abde"));
1319    test(S("abcde"), 2, 1, S(""), 1, 0, S("can't happen"));
1320    test(S("abcde"), 2, 1, S("12345"), 0, 0, S("abde"));
1321    test(S("abcde"), 2, 1, S("12345"), 0, 1, S("ab1de"));
1322    test(S("abcde"), 2, 1, S("12345"), 0, 2, S("ab12de"));
1323    test(S("abcde"), 2, 1, S("12345"), 0, 4, S("ab1234de"));
1324    test(S("abcde"), 2, 1, S("12345"), 0, 5, S("ab12345de"));
1325    test(S("abcde"), 2, 1, S("12345"), 0, 6, S("ab12345de"));
1326    test(S("abcde"), 2, 1, S("12345"), 1, 0, S("abde"));
1327    test(S("abcde"), 2, 1, S("12345"), 1, 1, S("ab2de"));
1328    test(S("abcde"), 2, 1, S("12345"), 1, 2, S("ab23de"));
1329    test(S("abcde"), 2, 1, S("12345"), 1, 3, S("ab234de"));
1330    test(S("abcde"), 2, 1, S("12345"), 1, 4, S("ab2345de"));
1331    test(S("abcde"), 2, 1, S("12345"), 1, 5, S("ab2345de"));
1332    test(S("abcde"), 2, 1, S("12345"), 2, 0, S("abde"));
1333}
1334
1335template <class S>
1336void test12()
1337{
1338    test(S("abcde"), 2, 1, S("12345"), 2, 1, S("ab3de"));
1339    test(S("abcde"), 2, 1, S("12345"), 2, 2, S("ab34de"));
1340    test(S("abcde"), 2, 1, S("12345"), 2, 3, S("ab345de"));
1341    test(S("abcde"), 2, 1, S("12345"), 2, 4, S("ab345de"));
1342    test(S("abcde"), 2, 1, S("12345"), 4, 0, S("abde"));
1343    test(S("abcde"), 2, 1, S("12345"), 4, 1, S("ab5de"));
1344    test(S("abcde"), 2, 1, S("12345"), 4, 2, S("ab5de"));
1345    test(S("abcde"), 2, 1, S("12345"), 5, 0, S("abde"));
1346    test(S("abcde"), 2, 1, S("12345"), 5, 1, S("abde"));
1347    test(S("abcde"), 2, 1, S("12345"), 6, 0, S("can't happen"));
1348    test(S("abcde"), 2, 1, S("1234567890"), 0, 0, S("abde"));
1349    test(S("abcde"), 2, 1, S("1234567890"), 0, 1, S("ab1de"));
1350    test(S("abcde"), 2, 1, S("1234567890"), 0, 5, S("ab12345de"));
1351    test(S("abcde"), 2, 1, S("1234567890"), 0, 9, S("ab123456789de"));
1352    test(S("abcde"), 2, 1, S("1234567890"), 0, 10, S("ab1234567890de"));
1353    test(S("abcde"), 2, 1, S("1234567890"), 0, 11, S("ab1234567890de"));
1354    test(S("abcde"), 2, 1, S("1234567890"), 1, 0, S("abde"));
1355    test(S("abcde"), 2, 1, S("1234567890"), 1, 1, S("ab2de"));
1356    test(S("abcde"), 2, 1, S("1234567890"), 1, 4, S("ab2345de"));
1357    test(S("abcde"), 2, 1, S("1234567890"), 1, 8, S("ab23456789de"));
1358    test(S("abcde"), 2, 1, S("1234567890"), 1, 9, S("ab234567890de"));
1359    test(S("abcde"), 2, 1, S("1234567890"), 1, 10, S("ab234567890de"));
1360    test(S("abcde"), 2, 1, S("1234567890"), 5, 0, S("abde"));
1361    test(S("abcde"), 2, 1, S("1234567890"), 5, 1, S("ab6de"));
1362    test(S("abcde"), 2, 1, S("1234567890"), 5, 2, S("ab67de"));
1363    test(S("abcde"), 2, 1, S("1234567890"), 5, 4, S("ab6789de"));
1364    test(S("abcde"), 2, 1, S("1234567890"), 5, 5, S("ab67890de"));
1365    test(S("abcde"), 2, 1, S("1234567890"), 5, 6, S("ab67890de"));
1366    test(S("abcde"), 2, 1, S("1234567890"), 9, 0, S("abde"));
1367    test(S("abcde"), 2, 1, S("1234567890"), 9, 1, S("ab0de"));
1368    test(S("abcde"), 2, 1, S("1234567890"), 9, 2, S("ab0de"));
1369    test(S("abcde"), 2, 1, S("1234567890"), 10, 0, S("abde"));
1370    test(S("abcde"), 2, 1, S("1234567890"), 10, 1, S("abde"));
1371    test(S("abcde"), 2, 1, S("1234567890"), 11, 0, S("can't happen"));
1372    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 0, S("abde"));
1373    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 1, S("ab1de"));
1374    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 10, S("ab1234567890de"));
1375    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 19, S("ab1234567890123456789de"));
1376    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 20, S("ab12345678901234567890de"));
1377    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 21, S("ab12345678901234567890de"));
1378    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 0, S("abde"));
1379    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 1, S("ab2de"));
1380    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 9, S("ab234567890de"));
1381    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 18, S("ab234567890123456789de"));
1382    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 19, S("ab2345678901234567890de"));
1383    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 20, S("ab2345678901234567890de"));
1384    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 0, S("abde"));
1385    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 1, S("ab1de"));
1386    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 5, S("ab12345de"));
1387    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 9, S("ab123456789de"));
1388    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 10, S("ab1234567890de"));
1389    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 11, S("ab1234567890de"));
1390    test(S("abcde"), 2, 1, S("12345678901234567890"), 19, 0, S("abde"));
1391    test(S("abcde"), 2, 1, S("12345678901234567890"), 19, 1, S("ab0de"));
1392    test(S("abcde"), 2, 1, S("12345678901234567890"), 19, 2, S("ab0de"));
1393    test(S("abcde"), 2, 1, S("12345678901234567890"), 20, 0, S("abde"));
1394    test(S("abcde"), 2, 1, S("12345678901234567890"), 20, 1, S("abde"));
1395    test(S("abcde"), 2, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
1396    test(S("abcde"), 2, 2, S(""), 0, 0, S("abe"));
1397    test(S("abcde"), 2, 2, S(""), 0, 1, S("abe"));
1398    test(S("abcde"), 2, 2, S(""), 1, 0, S("can't happen"));
1399    test(S("abcde"), 2, 2, S("12345"), 0, 0, S("abe"));
1400    test(S("abcde"), 2, 2, S("12345"), 0, 1, S("ab1e"));
1401    test(S("abcde"), 2, 2, S("12345"), 0, 2, S("ab12e"));
1402    test(S("abcde"), 2, 2, S("12345"), 0, 4, S("ab1234e"));
1403    test(S("abcde"), 2, 2, S("12345"), 0, 5, S("ab12345e"));
1404    test(S("abcde"), 2, 2, S("12345"), 0, 6, S("ab12345e"));
1405    test(S("abcde"), 2, 2, S("12345"), 1, 0, S("abe"));
1406    test(S("abcde"), 2, 2, S("12345"), 1, 1, S("ab2e"));
1407    test(S("abcde"), 2, 2, S("12345"), 1, 2, S("ab23e"));
1408    test(S("abcde"), 2, 2, S("12345"), 1, 3, S("ab234e"));
1409    test(S("abcde"), 2, 2, S("12345"), 1, 4, S("ab2345e"));
1410    test(S("abcde"), 2, 2, S("12345"), 1, 5, S("ab2345e"));
1411    test(S("abcde"), 2, 2, S("12345"), 2, 0, S("abe"));
1412    test(S("abcde"), 2, 2, S("12345"), 2, 1, S("ab3e"));
1413    test(S("abcde"), 2, 2, S("12345"), 2, 2, S("ab34e"));
1414    test(S("abcde"), 2, 2, S("12345"), 2, 3, S("ab345e"));
1415    test(S("abcde"), 2, 2, S("12345"), 2, 4, S("ab345e"));
1416    test(S("abcde"), 2, 2, S("12345"), 4, 0, S("abe"));
1417    test(S("abcde"), 2, 2, S("12345"), 4, 1, S("ab5e"));
1418    test(S("abcde"), 2, 2, S("12345"), 4, 2, S("ab5e"));
1419    test(S("abcde"), 2, 2, S("12345"), 5, 0, S("abe"));
1420    test(S("abcde"), 2, 2, S("12345"), 5, 1, S("abe"));
1421    test(S("abcde"), 2, 2, S("12345"), 6, 0, S("can't happen"));
1422    test(S("abcde"), 2, 2, S("1234567890"), 0, 0, S("abe"));
1423    test(S("abcde"), 2, 2, S("1234567890"), 0, 1, S("ab1e"));
1424    test(S("abcde"), 2, 2, S("1234567890"), 0, 5, S("ab12345e"));
1425    test(S("abcde"), 2, 2, S("1234567890"), 0, 9, S("ab123456789e"));
1426    test(S("abcde"), 2, 2, S("1234567890"), 0, 10, S("ab1234567890e"));
1427    test(S("abcde"), 2, 2, S("1234567890"), 0, 11, S("ab1234567890e"));
1428    test(S("abcde"), 2, 2, S("1234567890"), 1, 0, S("abe"));
1429    test(S("abcde"), 2, 2, S("1234567890"), 1, 1, S("ab2e"));
1430    test(S("abcde"), 2, 2, S("1234567890"), 1, 4, S("ab2345e"));
1431    test(S("abcde"), 2, 2, S("1234567890"), 1, 8, S("ab23456789e"));
1432    test(S("abcde"), 2, 2, S("1234567890"), 1, 9, S("ab234567890e"));
1433    test(S("abcde"), 2, 2, S("1234567890"), 1, 10, S("ab234567890e"));
1434    test(S("abcde"), 2, 2, S("1234567890"), 5, 0, S("abe"));
1435    test(S("abcde"), 2, 2, S("1234567890"), 5, 1, S("ab6e"));
1436    test(S("abcde"), 2, 2, S("1234567890"), 5, 2, S("ab67e"));
1437    test(S("abcde"), 2, 2, S("1234567890"), 5, 4, S("ab6789e"));
1438}
1439
1440template <class S>
1441void test13()
1442{
1443    test(S("abcde"), 2, 2, S("1234567890"), 5, 5, S("ab67890e"));
1444    test(S("abcde"), 2, 2, S("1234567890"), 5, 6, S("ab67890e"));
1445    test(S("abcde"), 2, 2, S("1234567890"), 9, 0, S("abe"));
1446    test(S("abcde"), 2, 2, S("1234567890"), 9, 1, S("ab0e"));
1447    test(S("abcde"), 2, 2, S("1234567890"), 9, 2, S("ab0e"));
1448    test(S("abcde"), 2, 2, S("1234567890"), 10, 0, S("abe"));
1449    test(S("abcde"), 2, 2, S("1234567890"), 10, 1, S("abe"));
1450    test(S("abcde"), 2, 2, S("1234567890"), 11, 0, S("can't happen"));
1451    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 0, S("abe"));
1452    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 1, S("ab1e"));
1453    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 10, S("ab1234567890e"));
1454    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 19, S("ab1234567890123456789e"));
1455    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 20, S("ab12345678901234567890e"));
1456    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 21, S("ab12345678901234567890e"));
1457    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 0, S("abe"));
1458    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 1, S("ab2e"));
1459    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 9, S("ab234567890e"));
1460    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 18, S("ab234567890123456789e"));
1461    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 19, S("ab2345678901234567890e"));
1462    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 20, S("ab2345678901234567890e"));
1463    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 0, S("abe"));
1464    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 1, S("ab1e"));
1465    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 5, S("ab12345e"));
1466    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 9, S("ab123456789e"));
1467    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 10, S("ab1234567890e"));
1468    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 11, S("ab1234567890e"));
1469    test(S("abcde"), 2, 2, S("12345678901234567890"), 19, 0, S("abe"));
1470    test(S("abcde"), 2, 2, S("12345678901234567890"), 19, 1, S("ab0e"));
1471    test(S("abcde"), 2, 2, S("12345678901234567890"), 19, 2, S("ab0e"));
1472    test(S("abcde"), 2, 2, S("12345678901234567890"), 20, 0, S("abe"));
1473    test(S("abcde"), 2, 2, S("12345678901234567890"), 20, 1, S("abe"));
1474    test(S("abcde"), 2, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
1475    test(S("abcde"), 2, 3, S(""), 0, 0, S("ab"));
1476    test(S("abcde"), 2, 3, S(""), 0, 1, S("ab"));
1477    test(S("abcde"), 2, 3, S(""), 1, 0, S("can't happen"));
1478    test(S("abcde"), 2, 3, S("12345"), 0, 0, S("ab"));
1479    test(S("abcde"), 2, 3, S("12345"), 0, 1, S("ab1"));
1480    test(S("abcde"), 2, 3, S("12345"), 0, 2, S("ab12"));
1481    test(S("abcde"), 2, 3, S("12345"), 0, 4, S("ab1234"));
1482    test(S("abcde"), 2, 3, S("12345"), 0, 5, S("ab12345"));
1483    test(S("abcde"), 2, 3, S("12345"), 0, 6, S("ab12345"));
1484    test(S("abcde"), 2, 3, S("12345"), 1, 0, S("ab"));
1485    test(S("abcde"), 2, 3, S("12345"), 1, 1, S("ab2"));
1486    test(S("abcde"), 2, 3, S("12345"), 1, 2, S("ab23"));
1487    test(S("abcde"), 2, 3, S("12345"), 1, 3, S("ab234"));
1488    test(S("abcde"), 2, 3, S("12345"), 1, 4, S("ab2345"));
1489    test(S("abcde"), 2, 3, S("12345"), 1, 5, S("ab2345"));
1490    test(S("abcde"), 2, 3, S("12345"), 2, 0, S("ab"));
1491    test(S("abcde"), 2, 3, S("12345"), 2, 1, S("ab3"));
1492    test(S("abcde"), 2, 3, S("12345"), 2, 2, S("ab34"));
1493    test(S("abcde"), 2, 3, S("12345"), 2, 3, S("ab345"));
1494    test(S("abcde"), 2, 3, S("12345"), 2, 4, S("ab345"));
1495    test(S("abcde"), 2, 3, S("12345"), 4, 0, S("ab"));
1496    test(S("abcde"), 2, 3, S("12345"), 4, 1, S("ab5"));
1497    test(S("abcde"), 2, 3, S("12345"), 4, 2, S("ab5"));
1498    test(S("abcde"), 2, 3, S("12345"), 5, 0, S("ab"));
1499    test(S("abcde"), 2, 3, S("12345"), 5, 1, S("ab"));
1500    test(S("abcde"), 2, 3, S("12345"), 6, 0, S("can't happen"));
1501    test(S("abcde"), 2, 3, S("1234567890"), 0, 0, S("ab"));
1502    test(S("abcde"), 2, 3, S("1234567890"), 0, 1, S("ab1"));
1503    test(S("abcde"), 2, 3, S("1234567890"), 0, 5, S("ab12345"));
1504    test(S("abcde"), 2, 3, S("1234567890"), 0, 9, S("ab123456789"));
1505    test(S("abcde"), 2, 3, S("1234567890"), 0, 10, S("ab1234567890"));
1506    test(S("abcde"), 2, 3, S("1234567890"), 0, 11, S("ab1234567890"));
1507    test(S("abcde"), 2, 3, S("1234567890"), 1, 0, S("ab"));
1508    test(S("abcde"), 2, 3, S("1234567890"), 1, 1, S("ab2"));
1509    test(S("abcde"), 2, 3, S("1234567890"), 1, 4, S("ab2345"));
1510    test(S("abcde"), 2, 3, S("1234567890"), 1, 8, S("ab23456789"));
1511    test(S("abcde"), 2, 3, S("1234567890"), 1, 9, S("ab234567890"));
1512    test(S("abcde"), 2, 3, S("1234567890"), 1, 10, S("ab234567890"));
1513    test(S("abcde"), 2, 3, S("1234567890"), 5, 0, S("ab"));
1514    test(S("abcde"), 2, 3, S("1234567890"), 5, 1, S("ab6"));
1515    test(S("abcde"), 2, 3, S("1234567890"), 5, 2, S("ab67"));
1516    test(S("abcde"), 2, 3, S("1234567890"), 5, 4, S("ab6789"));
1517    test(S("abcde"), 2, 3, S("1234567890"), 5, 5, S("ab67890"));
1518    test(S("abcde"), 2, 3, S("1234567890"), 5, 6, S("ab67890"));
1519    test(S("abcde"), 2, 3, S("1234567890"), 9, 0, S("ab"));
1520    test(S("abcde"), 2, 3, S("1234567890"), 9, 1, S("ab0"));
1521    test(S("abcde"), 2, 3, S("1234567890"), 9, 2, S("ab0"));
1522    test(S("abcde"), 2, 3, S("1234567890"), 10, 0, S("ab"));
1523    test(S("abcde"), 2, 3, S("1234567890"), 10, 1, S("ab"));
1524    test(S("abcde"), 2, 3, S("1234567890"), 11, 0, S("can't happen"));
1525    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 0, S("ab"));
1526    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 1, S("ab1"));
1527    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 10, S("ab1234567890"));
1528    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 19, S("ab1234567890123456789"));
1529    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 20, S("ab12345678901234567890"));
1530    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 21, S("ab12345678901234567890"));
1531    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 0, S("ab"));
1532    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 1, S("ab2"));
1533    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 9, S("ab234567890"));
1534    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 18, S("ab234567890123456789"));
1535    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 19, S("ab2345678901234567890"));
1536    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 20, S("ab2345678901234567890"));
1537    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 0, S("ab"));
1538    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 1, S("ab1"));
1539    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 5, S("ab12345"));
1540    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 9, S("ab123456789"));
1541    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 10, S("ab1234567890"));
1542    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 11, S("ab1234567890"));
1543}
1544
1545template <class S>
1546void test14()
1547{
1548    test(S("abcde"), 2, 3, S("12345678901234567890"), 19, 0, S("ab"));
1549    test(S("abcde"), 2, 3, S("12345678901234567890"), 19, 1, S("ab0"));
1550    test(S("abcde"), 2, 3, S("12345678901234567890"), 19, 2, S("ab0"));
1551    test(S("abcde"), 2, 3, S("12345678901234567890"), 20, 0, S("ab"));
1552    test(S("abcde"), 2, 3, S("12345678901234567890"), 20, 1, S("ab"));
1553    test(S("abcde"), 2, 3, S("12345678901234567890"), 21, 0, S("can't happen"));
1554    test(S("abcde"), 2, 4, S(""), 0, 0, S("ab"));
1555    test(S("abcde"), 2, 4, S(""), 0, 1, S("ab"));
1556    test(S("abcde"), 2, 4, S(""), 1, 0, S("can't happen"));
1557    test(S("abcde"), 2, 4, S("12345"), 0, 0, S("ab"));
1558    test(S("abcde"), 2, 4, S("12345"), 0, 1, S("ab1"));
1559    test(S("abcde"), 2, 4, S("12345"), 0, 2, S("ab12"));
1560    test(S("abcde"), 2, 4, S("12345"), 0, 4, S("ab1234"));
1561    test(S("abcde"), 2, 4, S("12345"), 0, 5, S("ab12345"));
1562    test(S("abcde"), 2, 4, S("12345"), 0, 6, S("ab12345"));
1563    test(S("abcde"), 2, 4, S("12345"), 1, 0, S("ab"));
1564    test(S("abcde"), 2, 4, S("12345"), 1, 1, S("ab2"));
1565    test(S("abcde"), 2, 4, S("12345"), 1, 2, S("ab23"));
1566    test(S("abcde"), 2, 4, S("12345"), 1, 3, S("ab234"));
1567    test(S("abcde"), 2, 4, S("12345"), 1, 4, S("ab2345"));
1568    test(S("abcde"), 2, 4, S("12345"), 1, 5, S("ab2345"));
1569    test(S("abcde"), 2, 4, S("12345"), 2, 0, S("ab"));
1570    test(S("abcde"), 2, 4, S("12345"), 2, 1, S("ab3"));
1571    test(S("abcde"), 2, 4, S("12345"), 2, 2, S("ab34"));
1572    test(S("abcde"), 2, 4, S("12345"), 2, 3, S("ab345"));
1573    test(S("abcde"), 2, 4, S("12345"), 2, 4, S("ab345"));
1574    test(S("abcde"), 2, 4, S("12345"), 4, 0, S("ab"));
1575    test(S("abcde"), 2, 4, S("12345"), 4, 1, S("ab5"));
1576    test(S("abcde"), 2, 4, S("12345"), 4, 2, S("ab5"));
1577    test(S("abcde"), 2, 4, S("12345"), 5, 0, S("ab"));
1578    test(S("abcde"), 2, 4, S("12345"), 5, 1, S("ab"));
1579    test(S("abcde"), 2, 4, S("12345"), 6, 0, S("can't happen"));
1580    test(S("abcde"), 2, 4, S("1234567890"), 0, 0, S("ab"));
1581    test(S("abcde"), 2, 4, S("1234567890"), 0, 1, S("ab1"));
1582    test(S("abcde"), 2, 4, S("1234567890"), 0, 5, S("ab12345"));
1583    test(S("abcde"), 2, 4, S("1234567890"), 0, 9, S("ab123456789"));
1584    test(S("abcde"), 2, 4, S("1234567890"), 0, 10, S("ab1234567890"));
1585    test(S("abcde"), 2, 4, S("1234567890"), 0, 11, S("ab1234567890"));
1586    test(S("abcde"), 2, 4, S("1234567890"), 1, 0, S("ab"));
1587    test(S("abcde"), 2, 4, S("1234567890"), 1, 1, S("ab2"));
1588    test(S("abcde"), 2, 4, S("1234567890"), 1, 4, S("ab2345"));
1589    test(S("abcde"), 2, 4, S("1234567890"), 1, 8, S("ab23456789"));
1590    test(S("abcde"), 2, 4, S("1234567890"), 1, 9, S("ab234567890"));
1591    test(S("abcde"), 2, 4, S("1234567890"), 1, 10, S("ab234567890"));
1592    test(S("abcde"), 2, 4, S("1234567890"), 5, 0, S("ab"));
1593    test(S("abcde"), 2, 4, S("1234567890"), 5, 1, S("ab6"));
1594    test(S("abcde"), 2, 4, S("1234567890"), 5, 2, S("ab67"));
1595    test(S("abcde"), 2, 4, S("1234567890"), 5, 4, S("ab6789"));
1596    test(S("abcde"), 2, 4, S("1234567890"), 5, 5, S("ab67890"));
1597    test(S("abcde"), 2, 4, S("1234567890"), 5, 6, S("ab67890"));
1598    test(S("abcde"), 2, 4, S("1234567890"), 9, 0, S("ab"));
1599    test(S("abcde"), 2, 4, S("1234567890"), 9, 1, S("ab0"));
1600    test(S("abcde"), 2, 4, S("1234567890"), 9, 2, S("ab0"));
1601    test(S("abcde"), 2, 4, S("1234567890"), 10, 0, S("ab"));
1602    test(S("abcde"), 2, 4, S("1234567890"), 10, 1, S("ab"));
1603    test(S("abcde"), 2, 4, S("1234567890"), 11, 0, S("can't happen"));
1604    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 0, S("ab"));
1605    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 1, S("ab1"));
1606    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 10, S("ab1234567890"));
1607    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 19, S("ab1234567890123456789"));
1608    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 20, S("ab12345678901234567890"));
1609    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 21, S("ab12345678901234567890"));
1610    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 0, S("ab"));
1611    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 1, S("ab2"));
1612    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 9, S("ab234567890"));
1613    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 18, S("ab234567890123456789"));
1614    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 19, S("ab2345678901234567890"));
1615    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 20, S("ab2345678901234567890"));
1616    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 0, S("ab"));
1617    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 1, S("ab1"));
1618    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 5, S("ab12345"));
1619    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 9, S("ab123456789"));
1620    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 10, S("ab1234567890"));
1621    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 11, S("ab1234567890"));
1622    test(S("abcde"), 2, 4, S("12345678901234567890"), 19, 0, S("ab"));
1623    test(S("abcde"), 2, 4, S("12345678901234567890"), 19, 1, S("ab0"));
1624    test(S("abcde"), 2, 4, S("12345678901234567890"), 19, 2, S("ab0"));
1625    test(S("abcde"), 2, 4, S("12345678901234567890"), 20, 0, S("ab"));
1626    test(S("abcde"), 2, 4, S("12345678901234567890"), 20, 1, S("ab"));
1627    test(S("abcde"), 2, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
1628    test(S("abcde"), 4, 0, S(""), 0, 0, S("abcde"));
1629    test(S("abcde"), 4, 0, S(""), 0, 1, S("abcde"));
1630    test(S("abcde"), 4, 0, S(""), 1, 0, S("can't happen"));
1631    test(S("abcde"), 4, 0, S("12345"), 0, 0, S("abcde"));
1632    test(S("abcde"), 4, 0, S("12345"), 0, 1, S("abcd1e"));
1633    test(S("abcde"), 4, 0, S("12345"), 0, 2, S("abcd12e"));
1634    test(S("abcde"), 4, 0, S("12345"), 0, 4, S("abcd1234e"));
1635    test(S("abcde"), 4, 0, S("12345"), 0, 5, S("abcd12345e"));
1636    test(S("abcde"), 4, 0, S("12345"), 0, 6, S("abcd12345e"));
1637    test(S("abcde"), 4, 0, S("12345"), 1, 0, S("abcde"));
1638    test(S("abcde"), 4, 0, S("12345"), 1, 1, S("abcd2e"));
1639    test(S("abcde"), 4, 0, S("12345"), 1, 2, S("abcd23e"));
1640    test(S("abcde"), 4, 0, S("12345"), 1, 3, S("abcd234e"));
1641    test(S("abcde"), 4, 0, S("12345"), 1, 4, S("abcd2345e"));
1642    test(S("abcde"), 4, 0, S("12345"), 1, 5, S("abcd2345e"));
1643    test(S("abcde"), 4, 0, S("12345"), 2, 0, S("abcde"));
1644    test(S("abcde"), 4, 0, S("12345"), 2, 1, S("abcd3e"));
1645    test(S("abcde"), 4, 0, S("12345"), 2, 2, S("abcd34e"));
1646    test(S("abcde"), 4, 0, S("12345"), 2, 3, S("abcd345e"));
1647    test(S("abcde"), 4, 0, S("12345"), 2, 4, S("abcd345e"));
1648}
1649
1650template <class S>
1651void test15()
1652{
1653    test(S("abcde"), 4, 0, S("12345"), 4, 0, S("abcde"));
1654    test(S("abcde"), 4, 0, S("12345"), 4, 1, S("abcd5e"));
1655    test(S("abcde"), 4, 0, S("12345"), 4, 2, S("abcd5e"));
1656    test(S("abcde"), 4, 0, S("12345"), 5, 0, S("abcde"));
1657    test(S("abcde"), 4, 0, S("12345"), 5, 1, S("abcde"));
1658    test(S("abcde"), 4, 0, S("12345"), 6, 0, S("can't happen"));
1659    test(S("abcde"), 4, 0, S("1234567890"), 0, 0, S("abcde"));
1660    test(S("abcde"), 4, 0, S("1234567890"), 0, 1, S("abcd1e"));
1661    test(S("abcde"), 4, 0, S("1234567890"), 0, 5, S("abcd12345e"));
1662    test(S("abcde"), 4, 0, S("1234567890"), 0, 9, S("abcd123456789e"));
1663    test(S("abcde"), 4, 0, S("1234567890"), 0, 10, S("abcd1234567890e"));
1664    test(S("abcde"), 4, 0, S("1234567890"), 0, 11, S("abcd1234567890e"));
1665    test(S("abcde"), 4, 0, S("1234567890"), 1, 0, S("abcde"));
1666    test(S("abcde"), 4, 0, S("1234567890"), 1, 1, S("abcd2e"));
1667    test(S("abcde"), 4, 0, S("1234567890"), 1, 4, S("abcd2345e"));
1668    test(S("abcde"), 4, 0, S("1234567890"), 1, 8, S("abcd23456789e"));
1669    test(S("abcde"), 4, 0, S("1234567890"), 1, 9, S("abcd234567890e"));
1670    test(S("abcde"), 4, 0, S("1234567890"), 1, 10, S("abcd234567890e"));
1671    test(S("abcde"), 4, 0, S("1234567890"), 5, 0, S("abcde"));
1672    test(S("abcde"), 4, 0, S("1234567890"), 5, 1, S("abcd6e"));
1673    test(S("abcde"), 4, 0, S("1234567890"), 5, 2, S("abcd67e"));
1674    test(S("abcde"), 4, 0, S("1234567890"), 5, 4, S("abcd6789e"));
1675    test(S("abcde"), 4, 0, S("1234567890"), 5, 5, S("abcd67890e"));
1676    test(S("abcde"), 4, 0, S("1234567890"), 5, 6, S("abcd67890e"));
1677    test(S("abcde"), 4, 0, S("1234567890"), 9, 0, S("abcde"));
1678    test(S("abcde"), 4, 0, S("1234567890"), 9, 1, S("abcd0e"));
1679    test(S("abcde"), 4, 0, S("1234567890"), 9, 2, S("abcd0e"));
1680    test(S("abcde"), 4, 0, S("1234567890"), 10, 0, S("abcde"));
1681    test(S("abcde"), 4, 0, S("1234567890"), 10, 1, S("abcde"));
1682    test(S("abcde"), 4, 0, S("1234567890"), 11, 0, S("can't happen"));
1683    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 0, S("abcde"));
1684    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 1, S("abcd1e"));
1685    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 10, S("abcd1234567890e"));
1686    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 19, S("abcd1234567890123456789e"));
1687    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 20, S("abcd12345678901234567890e"));
1688    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 21, S("abcd12345678901234567890e"));
1689    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 0, S("abcde"));
1690    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 1, S("abcd2e"));
1691    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 9, S("abcd234567890e"));
1692    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 18, S("abcd234567890123456789e"));
1693    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 19, S("abcd2345678901234567890e"));
1694    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 20, S("abcd2345678901234567890e"));
1695    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 0, S("abcde"));
1696    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 1, S("abcd1e"));
1697    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 5, S("abcd12345e"));
1698    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 9, S("abcd123456789e"));
1699    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 10, S("abcd1234567890e"));
1700    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 11, S("abcd1234567890e"));
1701    test(S("abcde"), 4, 0, S("12345678901234567890"), 19, 0, S("abcde"));
1702    test(S("abcde"), 4, 0, S("12345678901234567890"), 19, 1, S("abcd0e"));
1703    test(S("abcde"), 4, 0, S("12345678901234567890"), 19, 2, S("abcd0e"));
1704    test(S("abcde"), 4, 0, S("12345678901234567890"), 20, 0, S("abcde"));
1705    test(S("abcde"), 4, 0, S("12345678901234567890"), 20, 1, S("abcde"));
1706    test(S("abcde"), 4, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
1707    test(S("abcde"), 4, 1, S(""), 0, 0, S("abcd"));
1708    test(S("abcde"), 4, 1, S(""), 0, 1, S("abcd"));
1709    test(S("abcde"), 4, 1, S(""), 1, 0, S("can't happen"));
1710    test(S("abcde"), 4, 1, S("12345"), 0, 0, S("abcd"));
1711    test(S("abcde"), 4, 1, S("12345"), 0, 1, S("abcd1"));
1712    test(S("abcde"), 4, 1, S("12345"), 0, 2, S("abcd12"));
1713    test(S("abcde"), 4, 1, S("12345"), 0, 4, S("abcd1234"));
1714    test(S("abcde"), 4, 1, S("12345"), 0, 5, S("abcd12345"));
1715    test(S("abcde"), 4, 1, S("12345"), 0, 6, S("abcd12345"));
1716    test(S("abcde"), 4, 1, S("12345"), 1, 0, S("abcd"));
1717    test(S("abcde"), 4, 1, S("12345"), 1, 1, S("abcd2"));
1718    test(S("abcde"), 4, 1, S("12345"), 1, 2, S("abcd23"));
1719    test(S("abcde"), 4, 1, S("12345"), 1, 3, S("abcd234"));
1720    test(S("abcde"), 4, 1, S("12345"), 1, 4, S("abcd2345"));
1721    test(S("abcde"), 4, 1, S("12345"), 1, 5, S("abcd2345"));
1722    test(S("abcde"), 4, 1, S("12345"), 2, 0, S("abcd"));
1723    test(S("abcde"), 4, 1, S("12345"), 2, 1, S("abcd3"));
1724    test(S("abcde"), 4, 1, S("12345"), 2, 2, S("abcd34"));
1725    test(S("abcde"), 4, 1, S("12345"), 2, 3, S("abcd345"));
1726    test(S("abcde"), 4, 1, S("12345"), 2, 4, S("abcd345"));
1727    test(S("abcde"), 4, 1, S("12345"), 4, 0, S("abcd"));
1728    test(S("abcde"), 4, 1, S("12345"), 4, 1, S("abcd5"));
1729    test(S("abcde"), 4, 1, S("12345"), 4, 2, S("abcd5"));
1730    test(S("abcde"), 4, 1, S("12345"), 5, 0, S("abcd"));
1731    test(S("abcde"), 4, 1, S("12345"), 5, 1, S("abcd"));
1732    test(S("abcde"), 4, 1, S("12345"), 6, 0, S("can't happen"));
1733    test(S("abcde"), 4, 1, S("1234567890"), 0, 0, S("abcd"));
1734    test(S("abcde"), 4, 1, S("1234567890"), 0, 1, S("abcd1"));
1735    test(S("abcde"), 4, 1, S("1234567890"), 0, 5, S("abcd12345"));
1736    test(S("abcde"), 4, 1, S("1234567890"), 0, 9, S("abcd123456789"));
1737    test(S("abcde"), 4, 1, S("1234567890"), 0, 10, S("abcd1234567890"));
1738    test(S("abcde"), 4, 1, S("1234567890"), 0, 11, S("abcd1234567890"));
1739    test(S("abcde"), 4, 1, S("1234567890"), 1, 0, S("abcd"));
1740    test(S("abcde"), 4, 1, S("1234567890"), 1, 1, S("abcd2"));
1741    test(S("abcde"), 4, 1, S("1234567890"), 1, 4, S("abcd2345"));
1742    test(S("abcde"), 4, 1, S("1234567890"), 1, 8, S("abcd23456789"));
1743    test(S("abcde"), 4, 1, S("1234567890"), 1, 9, S("abcd234567890"));
1744    test(S("abcde"), 4, 1, S("1234567890"), 1, 10, S("abcd234567890"));
1745    test(S("abcde"), 4, 1, S("1234567890"), 5, 0, S("abcd"));
1746    test(S("abcde"), 4, 1, S("1234567890"), 5, 1, S("abcd6"));
1747    test(S("abcde"), 4, 1, S("1234567890"), 5, 2, S("abcd67"));
1748    test(S("abcde"), 4, 1, S("1234567890"), 5, 4, S("abcd6789"));
1749    test(S("abcde"), 4, 1, S("1234567890"), 5, 5, S("abcd67890"));
1750    test(S("abcde"), 4, 1, S("1234567890"), 5, 6, S("abcd67890"));
1751    test(S("abcde"), 4, 1, S("1234567890"), 9, 0, S("abcd"));
1752    test(S("abcde"), 4, 1, S("1234567890"), 9, 1, S("abcd0"));
1753}
1754
1755template <class S>
1756void test16()
1757{
1758    test(S("abcde"), 4, 1, S("1234567890"), 9, 2, S("abcd0"));
1759    test(S("abcde"), 4, 1, S("1234567890"), 10, 0, S("abcd"));
1760    test(S("abcde"), 4, 1, S("1234567890"), 10, 1, S("abcd"));
1761    test(S("abcde"), 4, 1, S("1234567890"), 11, 0, S("can't happen"));
1762    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 0, S("abcd"));
1763    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 1, S("abcd1"));
1764    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 10, S("abcd1234567890"));
1765    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 19, S("abcd1234567890123456789"));
1766    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 20, S("abcd12345678901234567890"));
1767    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 21, S("abcd12345678901234567890"));
1768    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 0, S("abcd"));
1769    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 1, S("abcd2"));
1770    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 9, S("abcd234567890"));
1771    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 18, S("abcd234567890123456789"));
1772    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 19, S("abcd2345678901234567890"));
1773    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 20, S("abcd2345678901234567890"));
1774    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 0, S("abcd"));
1775    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 1, S("abcd1"));
1776    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 5, S("abcd12345"));
1777    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 9, S("abcd123456789"));
1778    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 10, S("abcd1234567890"));
1779    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 11, S("abcd1234567890"));
1780    test(S("abcde"), 4, 1, S("12345678901234567890"), 19, 0, S("abcd"));
1781    test(S("abcde"), 4, 1, S("12345678901234567890"), 19, 1, S("abcd0"));
1782    test(S("abcde"), 4, 1, S("12345678901234567890"), 19, 2, S("abcd0"));
1783    test(S("abcde"), 4, 1, S("12345678901234567890"), 20, 0, S("abcd"));
1784    test(S("abcde"), 4, 1, S("12345678901234567890"), 20, 1, S("abcd"));
1785    test(S("abcde"), 4, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
1786    test(S("abcde"), 4, 2, S(""), 0, 0, S("abcd"));
1787    test(S("abcde"), 4, 2, S(""), 0, 1, S("abcd"));
1788    test(S("abcde"), 4, 2, S(""), 1, 0, S("can't happen"));
1789    test(S("abcde"), 4, 2, S("12345"), 0, 0, S("abcd"));
1790    test(S("abcde"), 4, 2, S("12345"), 0, 1, S("abcd1"));
1791    test(S("abcde"), 4, 2, S("12345"), 0, 2, S("abcd12"));
1792    test(S("abcde"), 4, 2, S("12345"), 0, 4, S("abcd1234"));
1793    test(S("abcde"), 4, 2, S("12345"), 0, 5, S("abcd12345"));
1794    test(S("abcde"), 4, 2, S("12345"), 0, 6, S("abcd12345"));
1795    test(S("abcde"), 4, 2, S("12345"), 1, 0, S("abcd"));
1796    test(S("abcde"), 4, 2, S("12345"), 1, 1, S("abcd2"));
1797    test(S("abcde"), 4, 2, S("12345"), 1, 2, S("abcd23"));
1798    test(S("abcde"), 4, 2, S("12345"), 1, 3, S("abcd234"));
1799    test(S("abcde"), 4, 2, S("12345"), 1, 4, S("abcd2345"));
1800    test(S("abcde"), 4, 2, S("12345"), 1, 5, S("abcd2345"));
1801    test(S("abcde"), 4, 2, S("12345"), 2, 0, S("abcd"));
1802    test(S("abcde"), 4, 2, S("12345"), 2, 1, S("abcd3"));
1803    test(S("abcde"), 4, 2, S("12345"), 2, 2, S("abcd34"));
1804    test(S("abcde"), 4, 2, S("12345"), 2, 3, S("abcd345"));
1805    test(S("abcde"), 4, 2, S("12345"), 2, 4, S("abcd345"));
1806    test(S("abcde"), 4, 2, S("12345"), 4, 0, S("abcd"));
1807    test(S("abcde"), 4, 2, S("12345"), 4, 1, S("abcd5"));
1808    test(S("abcde"), 4, 2, S("12345"), 4, 2, S("abcd5"));
1809    test(S("abcde"), 4, 2, S("12345"), 5, 0, S("abcd"));
1810    test(S("abcde"), 4, 2, S("12345"), 5, 1, S("abcd"));
1811    test(S("abcde"), 4, 2, S("12345"), 6, 0, S("can't happen"));
1812    test(S("abcde"), 4, 2, S("1234567890"), 0, 0, S("abcd"));
1813    test(S("abcde"), 4, 2, S("1234567890"), 0, 1, S("abcd1"));
1814    test(S("abcde"), 4, 2, S("1234567890"), 0, 5, S("abcd12345"));
1815    test(S("abcde"), 4, 2, S("1234567890"), 0, 9, S("abcd123456789"));
1816    test(S("abcde"), 4, 2, S("1234567890"), 0, 10, S("abcd1234567890"));
1817    test(S("abcde"), 4, 2, S("1234567890"), 0, 11, S("abcd1234567890"));
1818    test(S("abcde"), 4, 2, S("1234567890"), 1, 0, S("abcd"));
1819    test(S("abcde"), 4, 2, S("1234567890"), 1, 1, S("abcd2"));
1820    test(S("abcde"), 4, 2, S("1234567890"), 1, 4, S("abcd2345"));
1821    test(S("abcde"), 4, 2, S("1234567890"), 1, 8, S("abcd23456789"));
1822    test(S("abcde"), 4, 2, S("1234567890"), 1, 9, S("abcd234567890"));
1823    test(S("abcde"), 4, 2, S("1234567890"), 1, 10, S("abcd234567890"));
1824    test(S("abcde"), 4, 2, S("1234567890"), 5, 0, S("abcd"));
1825    test(S("abcde"), 4, 2, S("1234567890"), 5, 1, S("abcd6"));
1826    test(S("abcde"), 4, 2, S("1234567890"), 5, 2, S("abcd67"));
1827    test(S("abcde"), 4, 2, S("1234567890"), 5, 4, S("abcd6789"));
1828    test(S("abcde"), 4, 2, S("1234567890"), 5, 5, S("abcd67890"));
1829    test(S("abcde"), 4, 2, S("1234567890"), 5, 6, S("abcd67890"));
1830    test(S("abcde"), 4, 2, S("1234567890"), 9, 0, S("abcd"));
1831    test(S("abcde"), 4, 2, S("1234567890"), 9, 1, S("abcd0"));
1832    test(S("abcde"), 4, 2, S("1234567890"), 9, 2, S("abcd0"));
1833    test(S("abcde"), 4, 2, S("1234567890"), 10, 0, S("abcd"));
1834    test(S("abcde"), 4, 2, S("1234567890"), 10, 1, S("abcd"));
1835    test(S("abcde"), 4, 2, S("1234567890"), 11, 0, S("can't happen"));
1836    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 0, S("abcd"));
1837    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 1, S("abcd1"));
1838    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 10, S("abcd1234567890"));
1839    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 19, S("abcd1234567890123456789"));
1840    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 20, S("abcd12345678901234567890"));
1841    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 21, S("abcd12345678901234567890"));
1842    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 0, S("abcd"));
1843    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 1, S("abcd2"));
1844    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 9, S("abcd234567890"));
1845    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 18, S("abcd234567890123456789"));
1846    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 19, S("abcd2345678901234567890"));
1847    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 20, S("abcd2345678901234567890"));
1848    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 0, S("abcd"));
1849    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 1, S("abcd1"));
1850    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 5, S("abcd12345"));
1851    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 9, S("abcd123456789"));
1852    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 10, S("abcd1234567890"));
1853    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 11, S("abcd1234567890"));
1854    test(S("abcde"), 4, 2, S("12345678901234567890"), 19, 0, S("abcd"));
1855    test(S("abcde"), 4, 2, S("12345678901234567890"), 19, 1, S("abcd0"));
1856    test(S("abcde"), 4, 2, S("12345678901234567890"), 19, 2, S("abcd0"));
1857    test(S("abcde"), 4, 2, S("12345678901234567890"), 20, 0, S("abcd"));
1858}
1859
1860template <class S>
1861void test17()
1862{
1863    test(S("abcde"), 4, 2, S("12345678901234567890"), 20, 1, S("abcd"));
1864    test(S("abcde"), 4, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
1865    test(S("abcde"), 5, 0, S(""), 0, 0, S("abcde"));
1866    test(S("abcde"), 5, 0, S(""), 0, 1, S("abcde"));
1867    test(S("abcde"), 5, 0, S(""), 1, 0, S("can't happen"));
1868    test(S("abcde"), 5, 0, S("12345"), 0, 0, S("abcde"));
1869    test(S("abcde"), 5, 0, S("12345"), 0, 1, S("abcde1"));
1870    test(S("abcde"), 5, 0, S("12345"), 0, 2, S("abcde12"));
1871    test(S("abcde"), 5, 0, S("12345"), 0, 4, S("abcde1234"));
1872    test(S("abcde"), 5, 0, S("12345"), 0, 5, S("abcde12345"));
1873    test(S("abcde"), 5, 0, S("12345"), 0, 6, S("abcde12345"));
1874    test(S("abcde"), 5, 0, S("12345"), 1, 0, S("abcde"));
1875    test(S("abcde"), 5, 0, S("12345"), 1, 1, S("abcde2"));
1876    test(S("abcde"), 5, 0, S("12345"), 1, 2, S("abcde23"));
1877    test(S("abcde"), 5, 0, S("12345"), 1, 3, S("abcde234"));
1878    test(S("abcde"), 5, 0, S("12345"), 1, 4, S("abcde2345"));
1879    test(S("abcde"), 5, 0, S("12345"), 1, 5, S("abcde2345"));
1880    test(S("abcde"), 5, 0, S("12345"), 2, 0, S("abcde"));
1881    test(S("abcde"), 5, 0, S("12345"), 2, 1, S("abcde3"));
1882    test(S("abcde"), 5, 0, S("12345"), 2, 2, S("abcde34"));
1883    test(S("abcde"), 5, 0, S("12345"), 2, 3, S("abcde345"));
1884    test(S("abcde"), 5, 0, S("12345"), 2, 4, S("abcde345"));
1885    test(S("abcde"), 5, 0, S("12345"), 4, 0, S("abcde"));
1886    test(S("abcde"), 5, 0, S("12345"), 4, 1, S("abcde5"));
1887    test(S("abcde"), 5, 0, S("12345"), 4, 2, S("abcde5"));
1888    test(S("abcde"), 5, 0, S("12345"), 5, 0, S("abcde"));
1889    test(S("abcde"), 5, 0, S("12345"), 5, 1, S("abcde"));
1890    test(S("abcde"), 5, 0, S("12345"), 6, 0, S("can't happen"));
1891    test(S("abcde"), 5, 0, S("1234567890"), 0, 0, S("abcde"));
1892    test(S("abcde"), 5, 0, S("1234567890"), 0, 1, S("abcde1"));
1893    test(S("abcde"), 5, 0, S("1234567890"), 0, 5, S("abcde12345"));
1894    test(S("abcde"), 5, 0, S("1234567890"), 0, 9, S("abcde123456789"));
1895    test(S("abcde"), 5, 0, S("1234567890"), 0, 10, S("abcde1234567890"));
1896    test(S("abcde"), 5, 0, S("1234567890"), 0, 11, S("abcde1234567890"));
1897    test(S("abcde"), 5, 0, S("1234567890"), 1, 0, S("abcde"));
1898    test(S("abcde"), 5, 0, S("1234567890"), 1, 1, S("abcde2"));
1899    test(S("abcde"), 5, 0, S("1234567890"), 1, 4, S("abcde2345"));
1900    test(S("abcde"), 5, 0, S("1234567890"), 1, 8, S("abcde23456789"));
1901    test(S("abcde"), 5, 0, S("1234567890"), 1, 9, S("abcde234567890"));
1902    test(S("abcde"), 5, 0, S("1234567890"), 1, 10, S("abcde234567890"));
1903    test(S("abcde"), 5, 0, S("1234567890"), 5, 0, S("abcde"));
1904    test(S("abcde"), 5, 0, S("1234567890"), 5, 1, S("abcde6"));
1905    test(S("abcde"), 5, 0, S("1234567890"), 5, 2, S("abcde67"));
1906    test(S("abcde"), 5, 0, S("1234567890"), 5, 4, S("abcde6789"));
1907    test(S("abcde"), 5, 0, S("1234567890"), 5, 5, S("abcde67890"));
1908    test(S("abcde"), 5, 0, S("1234567890"), 5, 6, S("abcde67890"));
1909    test(S("abcde"), 5, 0, S("1234567890"), 9, 0, S("abcde"));
1910    test(S("abcde"), 5, 0, S("1234567890"), 9, 1, S("abcde0"));
1911    test(S("abcde"), 5, 0, S("1234567890"), 9, 2, S("abcde0"));
1912    test(S("abcde"), 5, 0, S("1234567890"), 10, 0, S("abcde"));
1913    test(S("abcde"), 5, 0, S("1234567890"), 10, 1, S("abcde"));
1914    test(S("abcde"), 5, 0, S("1234567890"), 11, 0, S("can't happen"));
1915    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 0, S("abcde"));
1916    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 1, S("abcde1"));
1917    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
1918    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
1919    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
1920    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
1921    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 0, S("abcde"));
1922    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 1, S("abcde2"));
1923    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 9, S("abcde234567890"));
1924    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
1925    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
1926    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
1927    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 0, S("abcde"));
1928    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 1, S("abcde1"));
1929    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 5, S("abcde12345"));
1930    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 9, S("abcde123456789"));
1931    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
1932    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
1933    test(S("abcde"), 5, 0, S("12345678901234567890"), 19, 0, S("abcde"));
1934    test(S("abcde"), 5, 0, S("12345678901234567890"), 19, 1, S("abcde0"));
1935    test(S("abcde"), 5, 0, S("12345678901234567890"), 19, 2, S("abcde0"));
1936    test(S("abcde"), 5, 0, S("12345678901234567890"), 20, 0, S("abcde"));
1937    test(S("abcde"), 5, 0, S("12345678901234567890"), 20, 1, S("abcde"));
1938    test(S("abcde"), 5, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
1939    test(S("abcde"), 5, 1, S(""), 0, 0, S("abcde"));
1940    test(S("abcde"), 5, 1, S(""), 0, 1, S("abcde"));
1941    test(S("abcde"), 5, 1, S(""), 1, 0, S("can't happen"));
1942    test(S("abcde"), 5, 1, S("12345"), 0, 0, S("abcde"));
1943    test(S("abcde"), 5, 1, S("12345"), 0, 1, S("abcde1"));
1944    test(S("abcde"), 5, 1, S("12345"), 0, 2, S("abcde12"));
1945    test(S("abcde"), 5, 1, S("12345"), 0, 4, S("abcde1234"));
1946    test(S("abcde"), 5, 1, S("12345"), 0, 5, S("abcde12345"));
1947    test(S("abcde"), 5, 1, S("12345"), 0, 6, S("abcde12345"));
1948    test(S("abcde"), 5, 1, S("12345"), 1, 0, S("abcde"));
1949    test(S("abcde"), 5, 1, S("12345"), 1, 1, S("abcde2"));
1950    test(S("abcde"), 5, 1, S("12345"), 1, 2, S("abcde23"));
1951    test(S("abcde"), 5, 1, S("12345"), 1, 3, S("abcde234"));
1952    test(S("abcde"), 5, 1, S("12345"), 1, 4, S("abcde2345"));
1953    test(S("abcde"), 5, 1, S("12345"), 1, 5, S("abcde2345"));
1954    test(S("abcde"), 5, 1, S("12345"), 2, 0, S("abcde"));
1955    test(S("abcde"), 5, 1, S("12345"), 2, 1, S("abcde3"));
1956    test(S("abcde"), 5, 1, S("12345"), 2, 2, S("abcde34"));
1957    test(S("abcde"), 5, 1, S("12345"), 2, 3, S("abcde345"));
1958    test(S("abcde"), 5, 1, S("12345"), 2, 4, S("abcde345"));
1959    test(S("abcde"), 5, 1, S("12345"), 4, 0, S("abcde"));
1960    test(S("abcde"), 5, 1, S("12345"), 4, 1, S("abcde5"));
1961    test(S("abcde"), 5, 1, S("12345"), 4, 2, S("abcde5"));
1962    test(S("abcde"), 5, 1, S("12345"), 5, 0, S("abcde"));
1963}
1964
1965template <class S>
1966void test18()
1967{
1968    test(S("abcde"), 5, 1, S("12345"), 5, 1, S("abcde"));
1969    test(S("abcde"), 5, 1, S("12345"), 6, 0, S("can't happen"));
1970    test(S("abcde"), 5, 1, S("1234567890"), 0, 0, S("abcde"));
1971    test(S("abcde"), 5, 1, S("1234567890"), 0, 1, S("abcde1"));
1972    test(S("abcde"), 5, 1, S("1234567890"), 0, 5, S("abcde12345"));
1973    test(S("abcde"), 5, 1, S("1234567890"), 0, 9, S("abcde123456789"));
1974    test(S("abcde"), 5, 1, S("1234567890"), 0, 10, S("abcde1234567890"));
1975    test(S("abcde"), 5, 1, S("1234567890"), 0, 11, S("abcde1234567890"));
1976    test(S("abcde"), 5, 1, S("1234567890"), 1, 0, S("abcde"));
1977    test(S("abcde"), 5, 1, S("1234567890"), 1, 1, S("abcde2"));
1978    test(S("abcde"), 5, 1, S("1234567890"), 1, 4, S("abcde2345"));
1979    test(S("abcde"), 5, 1, S("1234567890"), 1, 8, S("abcde23456789"));
1980    test(S("abcde"), 5, 1, S("1234567890"), 1, 9, S("abcde234567890"));
1981    test(S("abcde"), 5, 1, S("1234567890"), 1, 10, S("abcde234567890"));
1982    test(S("abcde"), 5, 1, S("1234567890"), 5, 0, S("abcde"));
1983    test(S("abcde"), 5, 1, S("1234567890"), 5, 1, S("abcde6"));
1984    test(S("abcde"), 5, 1, S("1234567890"), 5, 2, S("abcde67"));
1985    test(S("abcde"), 5, 1, S("1234567890"), 5, 4, S("abcde6789"));
1986    test(S("abcde"), 5, 1, S("1234567890"), 5, 5, S("abcde67890"));
1987    test(S("abcde"), 5, 1, S("1234567890"), 5, 6, S("abcde67890"));
1988    test(S("abcde"), 5, 1, S("1234567890"), 9, 0, S("abcde"));
1989    test(S("abcde"), 5, 1, S("1234567890"), 9, 1, S("abcde0"));
1990    test(S("abcde"), 5, 1, S("1234567890"), 9, 2, S("abcde0"));
1991    test(S("abcde"), 5, 1, S("1234567890"), 10, 0, S("abcde"));
1992    test(S("abcde"), 5, 1, S("1234567890"), 10, 1, S("abcde"));
1993    test(S("abcde"), 5, 1, S("1234567890"), 11, 0, S("can't happen"));
1994    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 0, S("abcde"));
1995    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 1, S("abcde1"));
1996    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
1997    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
1998    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
1999    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
2000    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 0, S("abcde"));
2001    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 1, S("abcde2"));
2002    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 9, S("abcde234567890"));
2003    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
2004    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
2005    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
2006    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 0, S("abcde"));
2007    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 1, S("abcde1"));
2008    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 5, S("abcde12345"));
2009    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 9, S("abcde123456789"));
2010    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
2011    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
2012    test(S("abcde"), 5, 1, S("12345678901234567890"), 19, 0, S("abcde"));
2013    test(S("abcde"), 5, 1, S("12345678901234567890"), 19, 1, S("abcde0"));
2014    test(S("abcde"), 5, 1, S("12345678901234567890"), 19, 2, S("abcde0"));
2015    test(S("abcde"), 5, 1, S("12345678901234567890"), 20, 0, S("abcde"));
2016    test(S("abcde"), 5, 1, S("12345678901234567890"), 20, 1, S("abcde"));
2017    test(S("abcde"), 5, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
2018    test(S("abcde"), 6, 0, S(""), 0, 0, S("can't happen"));
2019    test(S("abcde"), 6, 0, S(""), 0, 1, S("can't happen"));
2020    test(S("abcde"), 6, 0, S(""), 1, 0, S("can't happen"));
2021    test(S("abcde"), 6, 0, S("12345"), 0, 0, S("can't happen"));
2022    test(S("abcde"), 6, 0, S("12345"), 0, 1, S("can't happen"));
2023    test(S("abcde"), 6, 0, S("12345"), 0, 2, S("can't happen"));
2024    test(S("abcde"), 6, 0, S("12345"), 0, 4, S("can't happen"));
2025    test(S("abcde"), 6, 0, S("12345"), 0, 5, S("can't happen"));
2026    test(S("abcde"), 6, 0, S("12345"), 0, 6, S("can't happen"));
2027    test(S("abcde"), 6, 0, S("12345"), 1, 0, S("can't happen"));
2028    test(S("abcde"), 6, 0, S("12345"), 1, 1, S("can't happen"));
2029    test(S("abcde"), 6, 0, S("12345"), 1, 2, S("can't happen"));
2030    test(S("abcde"), 6, 0, S("12345"), 1, 3, S("can't happen"));
2031    test(S("abcde"), 6, 0, S("12345"), 1, 4, S("can't happen"));
2032    test(S("abcde"), 6, 0, S("12345"), 1, 5, S("can't happen"));
2033    test(S("abcde"), 6, 0, S("12345"), 2, 0, S("can't happen"));
2034    test(S("abcde"), 6, 0, S("12345"), 2, 1, S("can't happen"));
2035    test(S("abcde"), 6, 0, S("12345"), 2, 2, S("can't happen"));
2036    test(S("abcde"), 6, 0, S("12345"), 2, 3, S("can't happen"));
2037    test(S("abcde"), 6, 0, S("12345"), 2, 4, S("can't happen"));
2038    test(S("abcde"), 6, 0, S("12345"), 4, 0, S("can't happen"));
2039    test(S("abcde"), 6, 0, S("12345"), 4, 1, S("can't happen"));
2040    test(S("abcde"), 6, 0, S("12345"), 4, 2, S("can't happen"));
2041    test(S("abcde"), 6, 0, S("12345"), 5, 0, S("can't happen"));
2042    test(S("abcde"), 6, 0, S("12345"), 5, 1, S("can't happen"));
2043    test(S("abcde"), 6, 0, S("12345"), 6, 0, S("can't happen"));
2044    test(S("abcde"), 6, 0, S("1234567890"), 0, 0, S("can't happen"));
2045    test(S("abcde"), 6, 0, S("1234567890"), 0, 1, S("can't happen"));
2046    test(S("abcde"), 6, 0, S("1234567890"), 0, 5, S("can't happen"));
2047    test(S("abcde"), 6, 0, S("1234567890"), 0, 9, S("can't happen"));
2048    test(S("abcde"), 6, 0, S("1234567890"), 0, 10, S("can't happen"));
2049    test(S("abcde"), 6, 0, S("1234567890"), 0, 11, S("can't happen"));
2050    test(S("abcde"), 6, 0, S("1234567890"), 1, 0, S("can't happen"));
2051    test(S("abcde"), 6, 0, S("1234567890"), 1, 1, S("can't happen"));
2052    test(S("abcde"), 6, 0, S("1234567890"), 1, 4, S("can't happen"));
2053    test(S("abcde"), 6, 0, S("1234567890"), 1, 8, S("can't happen"));
2054    test(S("abcde"), 6, 0, S("1234567890"), 1, 9, S("can't happen"));
2055    test(S("abcde"), 6, 0, S("1234567890"), 1, 10, S("can't happen"));
2056    test(S("abcde"), 6, 0, S("1234567890"), 5, 0, S("can't happen"));
2057    test(S("abcde"), 6, 0, S("1234567890"), 5, 1, S("can't happen"));
2058    test(S("abcde"), 6, 0, S("1234567890"), 5, 2, S("can't happen"));
2059    test(S("abcde"), 6, 0, S("1234567890"), 5, 4, S("can't happen"));
2060    test(S("abcde"), 6, 0, S("1234567890"), 5, 5, S("can't happen"));
2061    test(S("abcde"), 6, 0, S("1234567890"), 5, 6, S("can't happen"));
2062    test(S("abcde"), 6, 0, S("1234567890"), 9, 0, S("can't happen"));
2063    test(S("abcde"), 6, 0, S("1234567890"), 9, 1, S("can't happen"));
2064    test(S("abcde"), 6, 0, S("1234567890"), 9, 2, S("can't happen"));
2065    test(S("abcde"), 6, 0, S("1234567890"), 10, 0, S("can't happen"));
2066    test(S("abcde"), 6, 0, S("1234567890"), 10, 1, S("can't happen"));
2067    test(S("abcde"), 6, 0, S("1234567890"), 11, 0, S("can't happen"));
2068}
2069
2070template <class S>
2071void test19()
2072{
2073    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
2074    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
2075    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
2076    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
2077    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
2078    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
2079    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
2080    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
2081    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
2082    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
2083    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
2084    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
2085    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
2086    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
2087    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
2088    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
2089    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
2090    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
2091    test(S("abcde"), 6, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
2092    test(S("abcde"), 6, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
2093    test(S("abcde"), 6, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
2094    test(S("abcde"), 6, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
2095    test(S("abcde"), 6, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
2096    test(S("abcde"), 6, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
2097    test(S("abcdefghij"), 0, 0, S(""), 0, 0, S("abcdefghij"));
2098    test(S("abcdefghij"), 0, 0, S(""), 0, 1, S("abcdefghij"));
2099    test(S("abcdefghij"), 0, 0, S(""), 1, 0, S("can't happen"));
2100    test(S("abcdefghij"), 0, 0, S("12345"), 0, 0, S("abcdefghij"));
2101    test(S("abcdefghij"), 0, 0, S("12345"), 0, 1, S("1abcdefghij"));
2102    test(S("abcdefghij"), 0, 0, S("12345"), 0, 2, S("12abcdefghij"));
2103    test(S("abcdefghij"), 0, 0, S("12345"), 0, 4, S("1234abcdefghij"));
2104    test(S("abcdefghij"), 0, 0, S("12345"), 0, 5, S("12345abcdefghij"));
2105    test(S("abcdefghij"), 0, 0, S("12345"), 0, 6, S("12345abcdefghij"));
2106    test(S("abcdefghij"), 0, 0, S("12345"), 1, 0, S("abcdefghij"));
2107    test(S("abcdefghij"), 0, 0, S("12345"), 1, 1, S("2abcdefghij"));
2108    test(S("abcdefghij"), 0, 0, S("12345"), 1, 2, S("23abcdefghij"));
2109    test(S("abcdefghij"), 0, 0, S("12345"), 1, 3, S("234abcdefghij"));
2110    test(S("abcdefghij"), 0, 0, S("12345"), 1, 4, S("2345abcdefghij"));
2111    test(S("abcdefghij"), 0, 0, S("12345"), 1, 5, S("2345abcdefghij"));
2112    test(S("abcdefghij"), 0, 0, S("12345"), 2, 0, S("abcdefghij"));
2113    test(S("abcdefghij"), 0, 0, S("12345"), 2, 1, S("3abcdefghij"));
2114    test(S("abcdefghij"), 0, 0, S("12345"), 2, 2, S("34abcdefghij"));
2115    test(S("abcdefghij"), 0, 0, S("12345"), 2, 3, S("345abcdefghij"));
2116    test(S("abcdefghij"), 0, 0, S("12345"), 2, 4, S("345abcdefghij"));
2117    test(S("abcdefghij"), 0, 0, S("12345"), 4, 0, S("abcdefghij"));
2118    test(S("abcdefghij"), 0, 0, S("12345"), 4, 1, S("5abcdefghij"));
2119    test(S("abcdefghij"), 0, 0, S("12345"), 4, 2, S("5abcdefghij"));
2120    test(S("abcdefghij"), 0, 0, S("12345"), 5, 0, S("abcdefghij"));
2121    test(S("abcdefghij"), 0, 0, S("12345"), 5, 1, S("abcdefghij"));
2122    test(S("abcdefghij"), 0, 0, S("12345"), 6, 0, S("can't happen"));
2123    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 0, S("abcdefghij"));
2124    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 1, S("1abcdefghij"));
2125    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 5, S("12345abcdefghij"));
2126    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 9, S("123456789abcdefghij"));
2127    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 10, S("1234567890abcdefghij"));
2128    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 11, S("1234567890abcdefghij"));
2129    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 0, S("abcdefghij"));
2130    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 1, S("2abcdefghij"));
2131    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 4, S("2345abcdefghij"));
2132    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 8, S("23456789abcdefghij"));
2133    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 9, S("234567890abcdefghij"));
2134    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 10, S("234567890abcdefghij"));
2135    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 0, S("abcdefghij"));
2136    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 1, S("6abcdefghij"));
2137    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 2, S("67abcdefghij"));
2138    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 4, S("6789abcdefghij"));
2139    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 5, S("67890abcdefghij"));
2140    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 6, S("67890abcdefghij"));
2141    test(S("abcdefghij"), 0, 0, S("1234567890"), 9, 0, S("abcdefghij"));
2142    test(S("abcdefghij"), 0, 0, S("1234567890"), 9, 1, S("0abcdefghij"));
2143    test(S("abcdefghij"), 0, 0, S("1234567890"), 9, 2, S("0abcdefghij"));
2144    test(S("abcdefghij"), 0, 0, S("1234567890"), 10, 0, S("abcdefghij"));
2145    test(S("abcdefghij"), 0, 0, S("1234567890"), 10, 1, S("abcdefghij"));
2146    test(S("abcdefghij"), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
2147    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
2148    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 1, S("1abcdefghij"));
2149    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890abcdefghij"));
2150    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghij"));
2151    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghij"));
2152    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghij"));
2153    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
2154    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 1, S("2abcdefghij"));
2155    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 9, S("234567890abcdefghij"));
2156    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcdefghij"));
2157    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghij"));
2158    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghij"));
2159    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
2160    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 1, S("1abcdefghij"));
2161    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 5, S("12345abcdefghij"));
2162    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 9, S("123456789abcdefghij"));
2163    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890abcdefghij"));
2164    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890abcdefghij"));
2165    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
2166    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 19, 1, S("0abcdefghij"));
2167    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 19, 2, S("0abcdefghij"));
2168    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
2169    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
2170    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
2171    test(S("abcdefghij"), 0, 1, S(""), 0, 0, S("bcdefghij"));
2172    test(S("abcdefghij"), 0, 1, S(""), 0, 1, S("bcdefghij"));
2173}
2174
2175template <class S>
2176void test20()
2177{
2178    test(S("abcdefghij"), 0, 1, S(""), 1, 0, S("can't happen"));
2179    test(S("abcdefghij"), 0, 1, S("12345"), 0, 0, S("bcdefghij"));
2180    test(S("abcdefghij"), 0, 1, S("12345"), 0, 1, S("1bcdefghij"));
2181    test(S("abcdefghij"), 0, 1, S("12345"), 0, 2, S("12bcdefghij"));
2182    test(S("abcdefghij"), 0, 1, S("12345"), 0, 4, S("1234bcdefghij"));
2183    test(S("abcdefghij"), 0, 1, S("12345"), 0, 5, S("12345bcdefghij"));
2184    test(S("abcdefghij"), 0, 1, S("12345"), 0, 6, S("12345bcdefghij"));
2185    test(S("abcdefghij"), 0, 1, S("12345"), 1, 0, S("bcdefghij"));
2186    test(S("abcdefghij"), 0, 1, S("12345"), 1, 1, S("2bcdefghij"));
2187    test(S("abcdefghij"), 0, 1, S("12345"), 1, 2, S("23bcdefghij"));
2188    test(S("abcdefghij"), 0, 1, S("12345"), 1, 3, S("234bcdefghij"));
2189    test(S("abcdefghij"), 0, 1, S("12345"), 1, 4, S("2345bcdefghij"));
2190    test(S("abcdefghij"), 0, 1, S("12345"), 1, 5, S("2345bcdefghij"));
2191    test(S("abcdefghij"), 0, 1, S("12345"), 2, 0, S("bcdefghij"));
2192    test(S("abcdefghij"), 0, 1, S("12345"), 2, 1, S("3bcdefghij"));
2193    test(S("abcdefghij"), 0, 1, S("12345"), 2, 2, S("34bcdefghij"));
2194    test(S("abcdefghij"), 0, 1, S("12345"), 2, 3, S("345bcdefghij"));
2195    test(S("abcdefghij"), 0, 1, S("12345"), 2, 4, S("345bcdefghij"));
2196    test(S("abcdefghij"), 0, 1, S("12345"), 4, 0, S("bcdefghij"));
2197    test(S("abcdefghij"), 0, 1, S("12345"), 4, 1, S("5bcdefghij"));
2198    test(S("abcdefghij"), 0, 1, S("12345"), 4, 2, S("5bcdefghij"));
2199    test(S("abcdefghij"), 0, 1, S("12345"), 5, 0, S("bcdefghij"));
2200    test(S("abcdefghij"), 0, 1, S("12345"), 5, 1, S("bcdefghij"));
2201    test(S("abcdefghij"), 0, 1, S("12345"), 6, 0, S("can't happen"));
2202    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 0, S("bcdefghij"));
2203    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 1, S("1bcdefghij"));
2204    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 5, S("12345bcdefghij"));
2205    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 9, S("123456789bcdefghij"));
2206    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 10, S("1234567890bcdefghij"));
2207    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 11, S("1234567890bcdefghij"));
2208    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 0, S("bcdefghij"));
2209    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 1, S("2bcdefghij"));
2210    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 4, S("2345bcdefghij"));
2211    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 8, S("23456789bcdefghij"));
2212    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 9, S("234567890bcdefghij"));
2213    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 10, S("234567890bcdefghij"));
2214    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 0, S("bcdefghij"));
2215    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 1, S("6bcdefghij"));
2216    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 2, S("67bcdefghij"));
2217    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 4, S("6789bcdefghij"));
2218    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 5, S("67890bcdefghij"));
2219    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 6, S("67890bcdefghij"));
2220    test(S("abcdefghij"), 0, 1, S("1234567890"), 9, 0, S("bcdefghij"));
2221    test(S("abcdefghij"), 0, 1, S("1234567890"), 9, 1, S("0bcdefghij"));
2222    test(S("abcdefghij"), 0, 1, S("1234567890"), 9, 2, S("0bcdefghij"));
2223    test(S("abcdefghij"), 0, 1, S("1234567890"), 10, 0, S("bcdefghij"));
2224    test(S("abcdefghij"), 0, 1, S("1234567890"), 10, 1, S("bcdefghij"));
2225    test(S("abcdefghij"), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
2226    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 0, S("bcdefghij"));
2227    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 1, S("1bcdefghij"));
2228    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890bcdefghij"));
2229    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789bcdefghij"));
2230    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890bcdefghij"));
2231    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890bcdefghij"));
2232    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 0, S("bcdefghij"));
2233    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 1, S("2bcdefghij"));
2234    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 9, S("234567890bcdefghij"));
2235    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789bcdefghij"));
2236    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890bcdefghij"));
2237    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890bcdefghij"));
2238    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 0, S("bcdefghij"));
2239    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 1, S("1bcdefghij"));
2240    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 5, S("12345bcdefghij"));
2241    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 9, S("123456789bcdefghij"));
2242    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890bcdefghij"));
2243    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890bcdefghij"));
2244    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 19, 0, S("bcdefghij"));
2245    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 19, 1, S("0bcdefghij"));
2246    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 19, 2, S("0bcdefghij"));
2247    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 20, 0, S("bcdefghij"));
2248    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 20, 1, S("bcdefghij"));
2249    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
2250    test(S("abcdefghij"), 0, 5, S(""), 0, 0, S("fghij"));
2251    test(S("abcdefghij"), 0, 5, S(""), 0, 1, S("fghij"));
2252    test(S("abcdefghij"), 0, 5, S(""), 1, 0, S("can't happen"));
2253    test(S("abcdefghij"), 0, 5, S("12345"), 0, 0, S("fghij"));
2254    test(S("abcdefghij"), 0, 5, S("12345"), 0, 1, S("1fghij"));
2255    test(S("abcdefghij"), 0, 5, S("12345"), 0, 2, S("12fghij"));
2256    test(S("abcdefghij"), 0, 5, S("12345"), 0, 4, S("1234fghij"));
2257    test(S("abcdefghij"), 0, 5, S("12345"), 0, 5, S("12345fghij"));
2258    test(S("abcdefghij"), 0, 5, S("12345"), 0, 6, S("12345fghij"));
2259    test(S("abcdefghij"), 0, 5, S("12345"), 1, 0, S("fghij"));
2260    test(S("abcdefghij"), 0, 5, S("12345"), 1, 1, S("2fghij"));
2261    test(S("abcdefghij"), 0, 5, S("12345"), 1, 2, S("23fghij"));
2262    test(S("abcdefghij"), 0, 5, S("12345"), 1, 3, S("234fghij"));
2263    test(S("abcdefghij"), 0, 5, S("12345"), 1, 4, S("2345fghij"));
2264    test(S("abcdefghij"), 0, 5, S("12345"), 1, 5, S("2345fghij"));
2265    test(S("abcdefghij"), 0, 5, S("12345"), 2, 0, S("fghij"));
2266    test(S("abcdefghij"), 0, 5, S("12345"), 2, 1, S("3fghij"));
2267    test(S("abcdefghij"), 0, 5, S("12345"), 2, 2, S("34fghij"));
2268    test(S("abcdefghij"), 0, 5, S("12345"), 2, 3, S("345fghij"));
2269    test(S("abcdefghij"), 0, 5, S("12345"), 2, 4, S("345fghij"));
2270    test(S("abcdefghij"), 0, 5, S("12345"), 4, 0, S("fghij"));
2271    test(S("abcdefghij"), 0, 5, S("12345"), 4, 1, S("5fghij"));
2272    test(S("abcdefghij"), 0, 5, S("12345"), 4, 2, S("5fghij"));
2273    test(S("abcdefghij"), 0, 5, S("12345"), 5, 0, S("fghij"));
2274    test(S("abcdefghij"), 0, 5, S("12345"), 5, 1, S("fghij"));
2275    test(S("abcdefghij"), 0, 5, S("12345"), 6, 0, S("can't happen"));
2276    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 0, S("fghij"));
2277    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 1, S("1fghij"));
2278}
2279
2280template <class S>
2281void test21()
2282{
2283    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 5, S("12345fghij"));
2284    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 9, S("123456789fghij"));
2285    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 10, S("1234567890fghij"));
2286    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 11, S("1234567890fghij"));
2287    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 0, S("fghij"));
2288    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 1, S("2fghij"));
2289    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 4, S("2345fghij"));
2290    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 8, S("23456789fghij"));
2291    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 9, S("234567890fghij"));
2292    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 10, S("234567890fghij"));
2293    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 0, S("fghij"));
2294    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 1, S("6fghij"));
2295    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 2, S("67fghij"));
2296    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 4, S("6789fghij"));
2297    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 5, S("67890fghij"));
2298    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 6, S("67890fghij"));
2299    test(S("abcdefghij"), 0, 5, S("1234567890"), 9, 0, S("fghij"));
2300    test(S("abcdefghij"), 0, 5, S("1234567890"), 9, 1, S("0fghij"));
2301    test(S("abcdefghij"), 0, 5, S("1234567890"), 9, 2, S("0fghij"));
2302    test(S("abcdefghij"), 0, 5, S("1234567890"), 10, 0, S("fghij"));
2303    test(S("abcdefghij"), 0, 5, S("1234567890"), 10, 1, S("fghij"));
2304    test(S("abcdefghij"), 0, 5, S("1234567890"), 11, 0, S("can't happen"));
2305    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 0, S("fghij"));
2306    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 1, S("1fghij"));
2307    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 10, S("1234567890fghij"));
2308    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 19, S("1234567890123456789fghij"));
2309    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 20, S("12345678901234567890fghij"));
2310    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 21, S("12345678901234567890fghij"));
2311    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 0, S("fghij"));
2312    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 1, S("2fghij"));
2313    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 9, S("234567890fghij"));
2314    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 18, S("234567890123456789fghij"));
2315    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 19, S("2345678901234567890fghij"));
2316    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 20, S("2345678901234567890fghij"));
2317    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 0, S("fghij"));
2318    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 1, S("1fghij"));
2319    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 5, S("12345fghij"));
2320    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 9, S("123456789fghij"));
2321    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 10, S("1234567890fghij"));
2322    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 11, S("1234567890fghij"));
2323    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 19, 0, S("fghij"));
2324    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 19, 1, S("0fghij"));
2325    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 19, 2, S("0fghij"));
2326    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 20, 0, S("fghij"));
2327    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 20, 1, S("fghij"));
2328    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
2329    test(S("abcdefghij"), 0, 9, S(""), 0, 0, S("j"));
2330    test(S("abcdefghij"), 0, 9, S(""), 0, 1, S("j"));
2331    test(S("abcdefghij"), 0, 9, S(""), 1, 0, S("can't happen"));
2332    test(S("abcdefghij"), 0, 9, S("12345"), 0, 0, S("j"));
2333    test(S("abcdefghij"), 0, 9, S("12345"), 0, 1, S("1j"));
2334    test(S("abcdefghij"), 0, 9, S("12345"), 0, 2, S("12j"));
2335    test(S("abcdefghij"), 0, 9, S("12345"), 0, 4, S("1234j"));
2336    test(S("abcdefghij"), 0, 9, S("12345"), 0, 5, S("12345j"));
2337    test(S("abcdefghij"), 0, 9, S("12345"), 0, 6, S("12345j"));
2338    test(S("abcdefghij"), 0, 9, S("12345"), 1, 0, S("j"));
2339    test(S("abcdefghij"), 0, 9, S("12345"), 1, 1, S("2j"));
2340    test(S("abcdefghij"), 0, 9, S("12345"), 1, 2, S("23j"));
2341    test(S("abcdefghij"), 0, 9, S("12345"), 1, 3, S("234j"));
2342    test(S("abcdefghij"), 0, 9, S("12345"), 1, 4, S("2345j"));
2343    test(S("abcdefghij"), 0, 9, S("12345"), 1, 5, S("2345j"));
2344    test(S("abcdefghij"), 0, 9, S("12345"), 2, 0, S("j"));
2345    test(S("abcdefghij"), 0, 9, S("12345"), 2, 1, S("3j"));
2346    test(S("abcdefghij"), 0, 9, S("12345"), 2, 2, S("34j"));
2347    test(S("abcdefghij"), 0, 9, S("12345"), 2, 3, S("345j"));
2348    test(S("abcdefghij"), 0, 9, S("12345"), 2, 4, S("345j"));
2349    test(S("abcdefghij"), 0, 9, S("12345"), 4, 0, S("j"));
2350    test(S("abcdefghij"), 0, 9, S("12345"), 4, 1, S("5j"));
2351    test(S("abcdefghij"), 0, 9, S("12345"), 4, 2, S("5j"));
2352    test(S("abcdefghij"), 0, 9, S("12345"), 5, 0, S("j"));
2353    test(S("abcdefghij"), 0, 9, S("12345"), 5, 1, S("j"));
2354    test(S("abcdefghij"), 0, 9, S("12345"), 6, 0, S("can't happen"));
2355    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 0, S("j"));
2356    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 1, S("1j"));
2357    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 5, S("12345j"));
2358    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 9, S("123456789j"));
2359    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 10, S("1234567890j"));
2360    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 11, S("1234567890j"));
2361    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 0, S("j"));
2362    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 1, S("2j"));
2363    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 4, S("2345j"));
2364    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 8, S("23456789j"));
2365    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 9, S("234567890j"));
2366    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 10, S("234567890j"));
2367    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 0, S("j"));
2368    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 1, S("6j"));
2369    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 2, S("67j"));
2370    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 4, S("6789j"));
2371    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 5, S("67890j"));
2372    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 6, S("67890j"));
2373    test(S("abcdefghij"), 0, 9, S("1234567890"), 9, 0, S("j"));
2374    test(S("abcdefghij"), 0, 9, S("1234567890"), 9, 1, S("0j"));
2375    test(S("abcdefghij"), 0, 9, S("1234567890"), 9, 2, S("0j"));
2376    test(S("abcdefghij"), 0, 9, S("1234567890"), 10, 0, S("j"));
2377    test(S("abcdefghij"), 0, 9, S("1234567890"), 10, 1, S("j"));
2378    test(S("abcdefghij"), 0, 9, S("1234567890"), 11, 0, S("can't happen"));
2379    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 0, S("j"));
2380    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 1, S("1j"));
2381    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 10, S("1234567890j"));
2382    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 19, S("1234567890123456789j"));
2383}
2384
2385template <class S>
2386void test22()
2387{
2388    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 20, S("12345678901234567890j"));
2389    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 21, S("12345678901234567890j"));
2390    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 0, S("j"));
2391    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 1, S("2j"));
2392    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 9, S("234567890j"));
2393    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 18, S("234567890123456789j"));
2394    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 19, S("2345678901234567890j"));
2395    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 20, S("2345678901234567890j"));
2396    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 0, S("j"));
2397    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 1, S("1j"));
2398    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 5, S("12345j"));
2399    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 9, S("123456789j"));
2400    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 10, S("1234567890j"));
2401    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 11, S("1234567890j"));
2402    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 19, 0, S("j"));
2403    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 19, 1, S("0j"));
2404    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 19, 2, S("0j"));
2405    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 20, 0, S("j"));
2406    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 20, 1, S("j"));
2407    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
2408    test(S("abcdefghij"), 0, 10, S(""), 0, 0, S(""));
2409    test(S("abcdefghij"), 0, 10, S(""), 0, 1, S(""));
2410    test(S("abcdefghij"), 0, 10, S(""), 1, 0, S("can't happen"));
2411    test(S("abcdefghij"), 0, 10, S("12345"), 0, 0, S(""));
2412    test(S("abcdefghij"), 0, 10, S("12345"), 0, 1, S("1"));
2413    test(S("abcdefghij"), 0, 10, S("12345"), 0, 2, S("12"));
2414    test(S("abcdefghij"), 0, 10, S("12345"), 0, 4, S("1234"));
2415    test(S("abcdefghij"), 0, 10, S("12345"), 0, 5, S("12345"));
2416    test(S("abcdefghij"), 0, 10, S("12345"), 0, 6, S("12345"));
2417    test(S("abcdefghij"), 0, 10, S("12345"), 1, 0, S(""));
2418    test(S("abcdefghij"), 0, 10, S("12345"), 1, 1, S("2"));
2419    test(S("abcdefghij"), 0, 10, S("12345"), 1, 2, S("23"));
2420    test(S("abcdefghij"), 0, 10, S("12345"), 1, 3, S("234"));
2421    test(S("abcdefghij"), 0, 10, S("12345"), 1, 4, S("2345"));
2422    test(S("abcdefghij"), 0, 10, S("12345"), 1, 5, S("2345"));
2423    test(S("abcdefghij"), 0, 10, S("12345"), 2, 0, S(""));
2424    test(S("abcdefghij"), 0, 10, S("12345"), 2, 1, S("3"));
2425    test(S("abcdefghij"), 0, 10, S("12345"), 2, 2, S("34"));
2426    test(S("abcdefghij"), 0, 10, S("12345"), 2, 3, S("345"));
2427    test(S("abcdefghij"), 0, 10, S("12345"), 2, 4, S("345"));
2428    test(S("abcdefghij"), 0, 10, S("12345"), 4, 0, S(""));
2429    test(S("abcdefghij"), 0, 10, S("12345"), 4, 1, S("5"));
2430    test(S("abcdefghij"), 0, 10, S("12345"), 4, 2, S("5"));
2431    test(S("abcdefghij"), 0, 10, S("12345"), 5, 0, S(""));
2432    test(S("abcdefghij"), 0, 10, S("12345"), 5, 1, S(""));
2433    test(S("abcdefghij"), 0, 10, S("12345"), 6, 0, S("can't happen"));
2434    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 0, S(""));
2435    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 1, S("1"));
2436    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 5, S("12345"));
2437    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 9, S("123456789"));
2438    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 10, S("1234567890"));
2439    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 11, S("1234567890"));
2440    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 0, S(""));
2441    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 1, S("2"));
2442    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 4, S("2345"));
2443    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 8, S("23456789"));
2444    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 9, S("234567890"));
2445    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 10, S("234567890"));
2446    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 0, S(""));
2447    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 1, S("6"));
2448    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 2, S("67"));
2449    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 4, S("6789"));
2450    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 5, S("67890"));
2451    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 6, S("67890"));
2452    test(S("abcdefghij"), 0, 10, S("1234567890"), 9, 0, S(""));
2453    test(S("abcdefghij"), 0, 10, S("1234567890"), 9, 1, S("0"));
2454    test(S("abcdefghij"), 0, 10, S("1234567890"), 9, 2, S("0"));
2455    test(S("abcdefghij"), 0, 10, S("1234567890"), 10, 0, S(""));
2456    test(S("abcdefghij"), 0, 10, S("1234567890"), 10, 1, S(""));
2457    test(S("abcdefghij"), 0, 10, S("1234567890"), 11, 0, S("can't happen"));
2458    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 0, S(""));
2459    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 1, S("1"));
2460    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 10, S("1234567890"));
2461    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
2462    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
2463    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
2464    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 0, S(""));
2465    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 1, S("2"));
2466    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 9, S("234567890"));
2467    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 18, S("234567890123456789"));
2468    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
2469    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
2470    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 0, S(""));
2471    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 1, S("1"));
2472    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 5, S("12345"));
2473    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 9, S("123456789"));
2474    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 10, S("1234567890"));
2475    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 11, S("1234567890"));
2476    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 19, 0, S(""));
2477    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 19, 1, S("0"));
2478    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 19, 2, S("0"));
2479    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 20, 0, S(""));
2480    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 20, 1, S(""));
2481    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
2482    test(S("abcdefghij"), 0, 11, S(""), 0, 0, S(""));
2483    test(S("abcdefghij"), 0, 11, S(""), 0, 1, S(""));
2484    test(S("abcdefghij"), 0, 11, S(""), 1, 0, S("can't happen"));
2485    test(S("abcdefghij"), 0, 11, S("12345"), 0, 0, S(""));
2486    test(S("abcdefghij"), 0, 11, S("12345"), 0, 1, S("1"));
2487    test(S("abcdefghij"), 0, 11, S("12345"), 0, 2, S("12"));
2488}
2489
2490template <class S>
2491void test23()
2492{
2493    test(S("abcdefghij"), 0, 11, S("12345"), 0, 4, S("1234"));
2494    test(S("abcdefghij"), 0, 11, S("12345"), 0, 5, S("12345"));
2495    test(S("abcdefghij"), 0, 11, S("12345"), 0, 6, S("12345"));
2496    test(S("abcdefghij"), 0, 11, S("12345"), 1, 0, S(""));
2497    test(S("abcdefghij"), 0, 11, S("12345"), 1, 1, S("2"));
2498    test(S("abcdefghij"), 0, 11, S("12345"), 1, 2, S("23"));
2499    test(S("abcdefghij"), 0, 11, S("12345"), 1, 3, S("234"));
2500    test(S("abcdefghij"), 0, 11, S("12345"), 1, 4, S("2345"));
2501    test(S("abcdefghij"), 0, 11, S("12345"), 1, 5, S("2345"));
2502    test(S("abcdefghij"), 0, 11, S("12345"), 2, 0, S(""));
2503    test(S("abcdefghij"), 0, 11, S("12345"), 2, 1, S("3"));
2504    test(S("abcdefghij"), 0, 11, S("12345"), 2, 2, S("34"));
2505    test(S("abcdefghij"), 0, 11, S("12345"), 2, 3, S("345"));
2506    test(S("abcdefghij"), 0, 11, S("12345"), 2, 4, S("345"));
2507    test(S("abcdefghij"), 0, 11, S("12345"), 4, 0, S(""));
2508    test(S("abcdefghij"), 0, 11, S("12345"), 4, 1, S("5"));
2509    test(S("abcdefghij"), 0, 11, S("12345"), 4, 2, S("5"));
2510    test(S("abcdefghij"), 0, 11, S("12345"), 5, 0, S(""));
2511    test(S("abcdefghij"), 0, 11, S("12345"), 5, 1, S(""));
2512    test(S("abcdefghij"), 0, 11, S("12345"), 6, 0, S("can't happen"));
2513    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 0, S(""));
2514    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 1, S("1"));
2515    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 5, S("12345"));
2516    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 9, S("123456789"));
2517    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 10, S("1234567890"));
2518    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 11, S("1234567890"));
2519    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 0, S(""));
2520    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 1, S("2"));
2521    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 4, S("2345"));
2522    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 8, S("23456789"));
2523    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 9, S("234567890"));
2524    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 10, S("234567890"));
2525    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 0, S(""));
2526    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 1, S("6"));
2527    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 2, S("67"));
2528    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 4, S("6789"));
2529    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 5, S("67890"));
2530    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 6, S("67890"));
2531    test(S("abcdefghij"), 0, 11, S("1234567890"), 9, 0, S(""));
2532    test(S("abcdefghij"), 0, 11, S("1234567890"), 9, 1, S("0"));
2533    test(S("abcdefghij"), 0, 11, S("1234567890"), 9, 2, S("0"));
2534    test(S("abcdefghij"), 0, 11, S("1234567890"), 10, 0, S(""));
2535    test(S("abcdefghij"), 0, 11, S("1234567890"), 10, 1, S(""));
2536    test(S("abcdefghij"), 0, 11, S("1234567890"), 11, 0, S("can't happen"));
2537    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 0, S(""));
2538    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 1, S("1"));
2539    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 10, S("1234567890"));
2540    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
2541    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
2542    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
2543    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 0, S(""));
2544    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 1, S("2"));
2545    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 9, S("234567890"));
2546    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 18, S("234567890123456789"));
2547    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
2548    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
2549    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 0, S(""));
2550    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 1, S("1"));
2551    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 5, S("12345"));
2552    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 9, S("123456789"));
2553    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 10, S("1234567890"));
2554    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 11, S("1234567890"));
2555    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 19, 0, S(""));
2556    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 19, 1, S("0"));
2557    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 19, 2, S("0"));
2558    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 20, 0, S(""));
2559    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 20, 1, S(""));
2560    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 21, 0, S("can't happen"));
2561    test(S("abcdefghij"), 1, 0, S(""), 0, 0, S("abcdefghij"));
2562    test(S("abcdefghij"), 1, 0, S(""), 0, 1, S("abcdefghij"));
2563    test(S("abcdefghij"), 1, 0, S(""), 1, 0, S("can't happen"));
2564    test(S("abcdefghij"), 1, 0, S("12345"), 0, 0, S("abcdefghij"));
2565    test(S("abcdefghij"), 1, 0, S("12345"), 0, 1, S("a1bcdefghij"));
2566    test(S("abcdefghij"), 1, 0, S("12345"), 0, 2, S("a12bcdefghij"));
2567    test(S("abcdefghij"), 1, 0, S("12345"), 0, 4, S("a1234bcdefghij"));
2568    test(S("abcdefghij"), 1, 0, S("12345"), 0, 5, S("a12345bcdefghij"));
2569    test(S("abcdefghij"), 1, 0, S("12345"), 0, 6, S("a12345bcdefghij"));
2570    test(S("abcdefghij"), 1, 0, S("12345"), 1, 0, S("abcdefghij"));
2571    test(S("abcdefghij"), 1, 0, S("12345"), 1, 1, S("a2bcdefghij"));
2572    test(S("abcdefghij"), 1, 0, S("12345"), 1, 2, S("a23bcdefghij"));
2573    test(S("abcdefghij"), 1, 0, S("12345"), 1, 3, S("a234bcdefghij"));
2574    test(S("abcdefghij"), 1, 0, S("12345"), 1, 4, S("a2345bcdefghij"));
2575    test(S("abcdefghij"), 1, 0, S("12345"), 1, 5, S("a2345bcdefghij"));
2576    test(S("abcdefghij"), 1, 0, S("12345"), 2, 0, S("abcdefghij"));
2577    test(S("abcdefghij"), 1, 0, S("12345"), 2, 1, S("a3bcdefghij"));
2578    test(S("abcdefghij"), 1, 0, S("12345"), 2, 2, S("a34bcdefghij"));
2579    test(S("abcdefghij"), 1, 0, S("12345"), 2, 3, S("a345bcdefghij"));
2580    test(S("abcdefghij"), 1, 0, S("12345"), 2, 4, S("a345bcdefghij"));
2581    test(S("abcdefghij"), 1, 0, S("12345"), 4, 0, S("abcdefghij"));
2582    test(S("abcdefghij"), 1, 0, S("12345"), 4, 1, S("a5bcdefghij"));
2583    test(S("abcdefghij"), 1, 0, S("12345"), 4, 2, S("a5bcdefghij"));
2584    test(S("abcdefghij"), 1, 0, S("12345"), 5, 0, S("abcdefghij"));
2585    test(S("abcdefghij"), 1, 0, S("12345"), 5, 1, S("abcdefghij"));
2586    test(S("abcdefghij"), 1, 0, S("12345"), 6, 0, S("can't happen"));
2587    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 0, S("abcdefghij"));
2588    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 1, S("a1bcdefghij"));
2589    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 5, S("a12345bcdefghij"));
2590    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 9, S("a123456789bcdefghij"));
2591    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 10, S("a1234567890bcdefghij"));
2592    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 11, S("a1234567890bcdefghij"));
2593}
2594
2595template <class S>
2596void test24()
2597{
2598    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 0, S("abcdefghij"));
2599    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 1, S("a2bcdefghij"));
2600    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 4, S("a2345bcdefghij"));
2601    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 8, S("a23456789bcdefghij"));
2602    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 9, S("a234567890bcdefghij"));
2603    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 10, S("a234567890bcdefghij"));
2604    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 0, S("abcdefghij"));
2605    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 1, S("a6bcdefghij"));
2606    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 2, S("a67bcdefghij"));
2607    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 4, S("a6789bcdefghij"));
2608    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 5, S("a67890bcdefghij"));
2609    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 6, S("a67890bcdefghij"));
2610    test(S("abcdefghij"), 1, 0, S("1234567890"), 9, 0, S("abcdefghij"));
2611    test(S("abcdefghij"), 1, 0, S("1234567890"), 9, 1, S("a0bcdefghij"));
2612    test(S("abcdefghij"), 1, 0, S("1234567890"), 9, 2, S("a0bcdefghij"));
2613    test(S("abcdefghij"), 1, 0, S("1234567890"), 10, 0, S("abcdefghij"));
2614    test(S("abcdefghij"), 1, 0, S("1234567890"), 10, 1, S("abcdefghij"));
2615    test(S("abcdefghij"), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
2616    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
2617    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 1, S("a1bcdefghij"));
2618    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 10, S("a1234567890bcdefghij"));
2619    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghij"));
2620    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghij"));
2621    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghij"));
2622    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
2623    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 1, S("a2bcdefghij"));
2624    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 9, S("a234567890bcdefghij"));
2625    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghij"));
2626    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghij"));
2627    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghij"));
2628    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
2629    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 1, S("a1bcdefghij"));
2630    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 5, S("a12345bcdefghij"));
2631    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 9, S("a123456789bcdefghij"));
2632    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 10, S("a1234567890bcdefghij"));
2633    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 11, S("a1234567890bcdefghij"));
2634    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
2635    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 19, 1, S("a0bcdefghij"));
2636    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 19, 2, S("a0bcdefghij"));
2637    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
2638    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
2639    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
2640    test(S("abcdefghij"), 1, 1, S(""), 0, 0, S("acdefghij"));
2641    test(S("abcdefghij"), 1, 1, S(""), 0, 1, S("acdefghij"));
2642    test(S("abcdefghij"), 1, 1, S(""), 1, 0, S("can't happen"));
2643    test(S("abcdefghij"), 1, 1, S("12345"), 0, 0, S("acdefghij"));
2644    test(S("abcdefghij"), 1, 1, S("12345"), 0, 1, S("a1cdefghij"));
2645    test(S("abcdefghij"), 1, 1, S("12345"), 0, 2, S("a12cdefghij"));
2646    test(S("abcdefghij"), 1, 1, S("12345"), 0, 4, S("a1234cdefghij"));
2647    test(S("abcdefghij"), 1, 1, S("12345"), 0, 5, S("a12345cdefghij"));
2648    test(S("abcdefghij"), 1, 1, S("12345"), 0, 6, S("a12345cdefghij"));
2649    test(S("abcdefghij"), 1, 1, S("12345"), 1, 0, S("acdefghij"));
2650    test(S("abcdefghij"), 1, 1, S("12345"), 1, 1, S("a2cdefghij"));
2651    test(S("abcdefghij"), 1, 1, S("12345"), 1, 2, S("a23cdefghij"));
2652    test(S("abcdefghij"), 1, 1, S("12345"), 1, 3, S("a234cdefghij"));
2653    test(S("abcdefghij"), 1, 1, S("12345"), 1, 4, S("a2345cdefghij"));
2654    test(S("abcdefghij"), 1, 1, S("12345"), 1, 5, S("a2345cdefghij"));
2655    test(S("abcdefghij"), 1, 1, S("12345"), 2, 0, S("acdefghij"));
2656    test(S("abcdefghij"), 1, 1, S("12345"), 2, 1, S("a3cdefghij"));
2657    test(S("abcdefghij"), 1, 1, S("12345"), 2, 2, S("a34cdefghij"));
2658    test(S("abcdefghij"), 1, 1, S("12345"), 2, 3, S("a345cdefghij"));
2659    test(S("abcdefghij"), 1, 1, S("12345"), 2, 4, S("a345cdefghij"));
2660    test(S("abcdefghij"), 1, 1, S("12345"), 4, 0, S("acdefghij"));
2661    test(S("abcdefghij"), 1, 1, S("12345"), 4, 1, S("a5cdefghij"));
2662    test(S("abcdefghij"), 1, 1, S("12345"), 4, 2, S("a5cdefghij"));
2663    test(S("abcdefghij"), 1, 1, S("12345"), 5, 0, S("acdefghij"));
2664    test(S("abcdefghij"), 1, 1, S("12345"), 5, 1, S("acdefghij"));
2665    test(S("abcdefghij"), 1, 1, S("12345"), 6, 0, S("can't happen"));
2666    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 0, S("acdefghij"));
2667    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 1, S("a1cdefghij"));
2668    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 5, S("a12345cdefghij"));
2669    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 9, S("a123456789cdefghij"));
2670    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 10, S("a1234567890cdefghij"));
2671    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 11, S("a1234567890cdefghij"));
2672    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 0, S("acdefghij"));
2673    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 1, S("a2cdefghij"));
2674    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 4, S("a2345cdefghij"));
2675    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 8, S("a23456789cdefghij"));
2676    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 9, S("a234567890cdefghij"));
2677    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 10, S("a234567890cdefghij"));
2678    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 0, S("acdefghij"));
2679    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 1, S("a6cdefghij"));
2680    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 2, S("a67cdefghij"));
2681    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 4, S("a6789cdefghij"));
2682    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 5, S("a67890cdefghij"));
2683    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 6, S("a67890cdefghij"));
2684    test(S("abcdefghij"), 1, 1, S("1234567890"), 9, 0, S("acdefghij"));
2685    test(S("abcdefghij"), 1, 1, S("1234567890"), 9, 1, S("a0cdefghij"));
2686    test(S("abcdefghij"), 1, 1, S("1234567890"), 9, 2, S("a0cdefghij"));
2687    test(S("abcdefghij"), 1, 1, S("1234567890"), 10, 0, S("acdefghij"));
2688    test(S("abcdefghij"), 1, 1, S("1234567890"), 10, 1, S("acdefghij"));
2689    test(S("abcdefghij"), 1, 1, S("1234567890"), 11, 0, S("can't happen"));
2690    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 0, S("acdefghij"));
2691    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 1, S("a1cdefghij"));
2692    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 10, S("a1234567890cdefghij"));
2693    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789cdefghij"));
2694    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890cdefghij"));
2695    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890cdefghij"));
2696    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 0, S("acdefghij"));
2697    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 1, S("a2cdefghij"));
2698}
2699
2700template <class S>
2701void test25()
2702{
2703    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 9, S("a234567890cdefghij"));
2704    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 18, S("a234567890123456789cdefghij"));
2705    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890cdefghij"));
2706    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890cdefghij"));
2707    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 0, S("acdefghij"));
2708    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 1, S("a1cdefghij"));
2709    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 5, S("a12345cdefghij"));
2710    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 9, S("a123456789cdefghij"));
2711    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 10, S("a1234567890cdefghij"));
2712    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 11, S("a1234567890cdefghij"));
2713    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 19, 0, S("acdefghij"));
2714    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 19, 1, S("a0cdefghij"));
2715    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 19, 2, S("a0cdefghij"));
2716    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 20, 0, S("acdefghij"));
2717    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 20, 1, S("acdefghij"));
2718    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
2719    test(S("abcdefghij"), 1, 4, S(""), 0, 0, S("afghij"));
2720    test(S("abcdefghij"), 1, 4, S(""), 0, 1, S("afghij"));
2721    test(S("abcdefghij"), 1, 4, S(""), 1, 0, S("can't happen"));
2722    test(S("abcdefghij"), 1, 4, S("12345"), 0, 0, S("afghij"));
2723    test(S("abcdefghij"), 1, 4, S("12345"), 0, 1, S("a1fghij"));
2724    test(S("abcdefghij"), 1, 4, S("12345"), 0, 2, S("a12fghij"));
2725    test(S("abcdefghij"), 1, 4, S("12345"), 0, 4, S("a1234fghij"));
2726    test(S("abcdefghij"), 1, 4, S("12345"), 0, 5, S("a12345fghij"));
2727    test(S("abcdefghij"), 1, 4, S("12345"), 0, 6, S("a12345fghij"));
2728    test(S("abcdefghij"), 1, 4, S("12345"), 1, 0, S("afghij"));
2729    test(S("abcdefghij"), 1, 4, S("12345"), 1, 1, S("a2fghij"));
2730    test(S("abcdefghij"), 1, 4, S("12345"), 1, 2, S("a23fghij"));
2731    test(S("abcdefghij"), 1, 4, S("12345"), 1, 3, S("a234fghij"));
2732    test(S("abcdefghij"), 1, 4, S("12345"), 1, 4, S("a2345fghij"));
2733    test(S("abcdefghij"), 1, 4, S("12345"), 1, 5, S("a2345fghij"));
2734    test(S("abcdefghij"), 1, 4, S("12345"), 2, 0, S("afghij"));
2735    test(S("abcdefghij"), 1, 4, S("12345"), 2, 1, S("a3fghij"));
2736    test(S("abcdefghij"), 1, 4, S("12345"), 2, 2, S("a34fghij"));
2737    test(S("abcdefghij"), 1, 4, S("12345"), 2, 3, S("a345fghij"));
2738    test(S("abcdefghij"), 1, 4, S("12345"), 2, 4, S("a345fghij"));
2739    test(S("abcdefghij"), 1, 4, S("12345"), 4, 0, S("afghij"));
2740    test(S("abcdefghij"), 1, 4, S("12345"), 4, 1, S("a5fghij"));
2741    test(S("abcdefghij"), 1, 4, S("12345"), 4, 2, S("a5fghij"));
2742    test(S("abcdefghij"), 1, 4, S("12345"), 5, 0, S("afghij"));
2743    test(S("abcdefghij"), 1, 4, S("12345"), 5, 1, S("afghij"));
2744    test(S("abcdefghij"), 1, 4, S("12345"), 6, 0, S("can't happen"));
2745    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 0, S("afghij"));
2746    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 1, S("a1fghij"));
2747    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 5, S("a12345fghij"));
2748    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 9, S("a123456789fghij"));
2749    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 10, S("a1234567890fghij"));
2750    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 11, S("a1234567890fghij"));
2751    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 0, S("afghij"));
2752    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 1, S("a2fghij"));
2753    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 4, S("a2345fghij"));
2754    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 8, S("a23456789fghij"));
2755    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 9, S("a234567890fghij"));
2756    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 10, S("a234567890fghij"));
2757    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 0, S("afghij"));
2758    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 1, S("a6fghij"));
2759    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 2, S("a67fghij"));
2760    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 4, S("a6789fghij"));
2761    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 5, S("a67890fghij"));
2762    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 6, S("a67890fghij"));
2763    test(S("abcdefghij"), 1, 4, S("1234567890"), 9, 0, S("afghij"));
2764    test(S("abcdefghij"), 1, 4, S("1234567890"), 9, 1, S("a0fghij"));
2765    test(S("abcdefghij"), 1, 4, S("1234567890"), 9, 2, S("a0fghij"));
2766    test(S("abcdefghij"), 1, 4, S("1234567890"), 10, 0, S("afghij"));
2767    test(S("abcdefghij"), 1, 4, S("1234567890"), 10, 1, S("afghij"));
2768    test(S("abcdefghij"), 1, 4, S("1234567890"), 11, 0, S("can't happen"));
2769    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 0, S("afghij"));
2770    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 1, S("a1fghij"));
2771    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 10, S("a1234567890fghij"));
2772    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 19, S("a1234567890123456789fghij"));
2773    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 20, S("a12345678901234567890fghij"));
2774    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 21, S("a12345678901234567890fghij"));
2775    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 0, S("afghij"));
2776    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 1, S("a2fghij"));
2777    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 9, S("a234567890fghij"));
2778    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 18, S("a234567890123456789fghij"));
2779    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 19, S("a2345678901234567890fghij"));
2780    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 20, S("a2345678901234567890fghij"));
2781    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 0, S("afghij"));
2782    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 1, S("a1fghij"));
2783    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 5, S("a12345fghij"));
2784    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 9, S("a123456789fghij"));
2785    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 10, S("a1234567890fghij"));
2786    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 11, S("a1234567890fghij"));
2787    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 19, 0, S("afghij"));
2788    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 19, 1, S("a0fghij"));
2789    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 19, 2, S("a0fghij"));
2790    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 20, 0, S("afghij"));
2791    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 20, 1, S("afghij"));
2792    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
2793    test(S("abcdefghij"), 1, 8, S(""), 0, 0, S("aj"));
2794    test(S("abcdefghij"), 1, 8, S(""), 0, 1, S("aj"));
2795    test(S("abcdefghij"), 1, 8, S(""), 1, 0, S("can't happen"));
2796    test(S("abcdefghij"), 1, 8, S("12345"), 0, 0, S("aj"));
2797    test(S("abcdefghij"), 1, 8, S("12345"), 0, 1, S("a1j"));
2798    test(S("abcdefghij"), 1, 8, S("12345"), 0, 2, S("a12j"));
2799    test(S("abcdefghij"), 1, 8, S("12345"), 0, 4, S("a1234j"));
2800    test(S("abcdefghij"), 1, 8, S("12345"), 0, 5, S("a12345j"));
2801    test(S("abcdefghij"), 1, 8, S("12345"), 0, 6, S("a12345j"));
2802    test(S("abcdefghij"), 1, 8, S("12345"), 1, 0, S("aj"));
2803}
2804
2805template <class S>
2806void test26()
2807{
2808    test(S("abcdefghij"), 1, 8, S("12345"), 1, 1, S("a2j"));
2809    test(S("abcdefghij"), 1, 8, S("12345"), 1, 2, S("a23j"));
2810    test(S("abcdefghij"), 1, 8, S("12345"), 1, 3, S("a234j"));
2811    test(S("abcdefghij"), 1, 8, S("12345"), 1, 4, S("a2345j"));
2812    test(S("abcdefghij"), 1, 8, S("12345"), 1, 5, S("a2345j"));
2813    test(S("abcdefghij"), 1, 8, S("12345"), 2, 0, S("aj"));
2814    test(S("abcdefghij"), 1, 8, S("12345"), 2, 1, S("a3j"));
2815    test(S("abcdefghij"), 1, 8, S("12345"), 2, 2, S("a34j"));
2816    test(S("abcdefghij"), 1, 8, S("12345"), 2, 3, S("a345j"));
2817    test(S("abcdefghij"), 1, 8, S("12345"), 2, 4, S("a345j"));
2818    test(S("abcdefghij"), 1, 8, S("12345"), 4, 0, S("aj"));
2819    test(S("abcdefghij"), 1, 8, S("12345"), 4, 1, S("a5j"));
2820    test(S("abcdefghij"), 1, 8, S("12345"), 4, 2, S("a5j"));
2821    test(S("abcdefghij"), 1, 8, S("12345"), 5, 0, S("aj"));
2822    test(S("abcdefghij"), 1, 8, S("12345"), 5, 1, S("aj"));
2823    test(S("abcdefghij"), 1, 8, S("12345"), 6, 0, S("can't happen"));
2824    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 0, S("aj"));
2825    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 1, S("a1j"));
2826    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 5, S("a12345j"));
2827    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 9, S("a123456789j"));
2828    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 10, S("a1234567890j"));
2829    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 11, S("a1234567890j"));
2830    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 0, S("aj"));
2831    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 1, S("a2j"));
2832    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 4, S("a2345j"));
2833    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 8, S("a23456789j"));
2834    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 9, S("a234567890j"));
2835    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 10, S("a234567890j"));
2836    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 0, S("aj"));
2837    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 1, S("a6j"));
2838    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 2, S("a67j"));
2839    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 4, S("a6789j"));
2840    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 5, S("a67890j"));
2841    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 6, S("a67890j"));
2842    test(S("abcdefghij"), 1, 8, S("1234567890"), 9, 0, S("aj"));
2843    test(S("abcdefghij"), 1, 8, S("1234567890"), 9, 1, S("a0j"));
2844    test(S("abcdefghij"), 1, 8, S("1234567890"), 9, 2, S("a0j"));
2845    test(S("abcdefghij"), 1, 8, S("1234567890"), 10, 0, S("aj"));
2846    test(S("abcdefghij"), 1, 8, S("1234567890"), 10, 1, S("aj"));
2847    test(S("abcdefghij"), 1, 8, S("1234567890"), 11, 0, S("can't happen"));
2848    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 0, S("aj"));
2849    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 1, S("a1j"));
2850    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 10, S("a1234567890j"));
2851    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 19, S("a1234567890123456789j"));
2852    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 20, S("a12345678901234567890j"));
2853    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 21, S("a12345678901234567890j"));
2854    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 0, S("aj"));
2855    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 1, S("a2j"));
2856    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 9, S("a234567890j"));
2857    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 18, S("a234567890123456789j"));
2858    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 19, S("a2345678901234567890j"));
2859    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 20, S("a2345678901234567890j"));
2860    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 0, S("aj"));
2861    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 1, S("a1j"));
2862    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 5, S("a12345j"));
2863    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 9, S("a123456789j"));
2864    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 10, S("a1234567890j"));
2865    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 11, S("a1234567890j"));
2866    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 19, 0, S("aj"));
2867    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 19, 1, S("a0j"));
2868    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 19, 2, S("a0j"));
2869    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 20, 0, S("aj"));
2870    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 20, 1, S("aj"));
2871    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 21, 0, S("can't happen"));
2872    test(S("abcdefghij"), 1, 9, S(""), 0, 0, S("a"));
2873    test(S("abcdefghij"), 1, 9, S(""), 0, 1, S("a"));
2874    test(S("abcdefghij"), 1, 9, S(""), 1, 0, S("can't happen"));
2875    test(S("abcdefghij"), 1, 9, S("12345"), 0, 0, S("a"));
2876    test(S("abcdefghij"), 1, 9, S("12345"), 0, 1, S("a1"));
2877    test(S("abcdefghij"), 1, 9, S("12345"), 0, 2, S("a12"));
2878    test(S("abcdefghij"), 1, 9, S("12345"), 0, 4, S("a1234"));
2879    test(S("abcdefghij"), 1, 9, S("12345"), 0, 5, S("a12345"));
2880    test(S("abcdefghij"), 1, 9, S("12345"), 0, 6, S("a12345"));
2881    test(S("abcdefghij"), 1, 9, S("12345"), 1, 0, S("a"));
2882    test(S("abcdefghij"), 1, 9, S("12345"), 1, 1, S("a2"));
2883    test(S("abcdefghij"), 1, 9, S("12345"), 1, 2, S("a23"));
2884    test(S("abcdefghij"), 1, 9, S("12345"), 1, 3, S("a234"));
2885    test(S("abcdefghij"), 1, 9, S("12345"), 1, 4, S("a2345"));
2886    test(S("abcdefghij"), 1, 9, S("12345"), 1, 5, S("a2345"));
2887    test(S("abcdefghij"), 1, 9, S("12345"), 2, 0, S("a"));
2888    test(S("abcdefghij"), 1, 9, S("12345"), 2, 1, S("a3"));
2889    test(S("abcdefghij"), 1, 9, S("12345"), 2, 2, S("a34"));
2890    test(S("abcdefghij"), 1, 9, S("12345"), 2, 3, S("a345"));
2891    test(S("abcdefghij"), 1, 9, S("12345"), 2, 4, S("a345"));
2892    test(S("abcdefghij"), 1, 9, S("12345"), 4, 0, S("a"));
2893    test(S("abcdefghij"), 1, 9, S("12345"), 4, 1, S("a5"));
2894    test(S("abcdefghij"), 1, 9, S("12345"), 4, 2, S("a5"));
2895    test(S("abcdefghij"), 1, 9, S("12345"), 5, 0, S("a"));
2896    test(S("abcdefghij"), 1, 9, S("12345"), 5, 1, S("a"));
2897    test(S("abcdefghij"), 1, 9, S("12345"), 6, 0, S("can't happen"));
2898    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 0, S("a"));
2899    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 1, S("a1"));
2900    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 5, S("a12345"));
2901    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 9, S("a123456789"));
2902    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 10, S("a1234567890"));
2903    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 11, S("a1234567890"));
2904    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 0, S("a"));
2905    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 1, S("a2"));
2906    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 4, S("a2345"));
2907    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 8, S("a23456789"));
2908}
2909
2910template <class S>
2911void test27()
2912{
2913    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 9, S("a234567890"));
2914    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 10, S("a234567890"));
2915    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 0, S("a"));
2916    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 1, S("a6"));
2917    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 2, S("a67"));
2918    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 4, S("a6789"));
2919    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 5, S("a67890"));
2920    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 6, S("a67890"));
2921    test(S("abcdefghij"), 1, 9, S("1234567890"), 9, 0, S("a"));
2922    test(S("abcdefghij"), 1, 9, S("1234567890"), 9, 1, S("a0"));
2923    test(S("abcdefghij"), 1, 9, S("1234567890"), 9, 2, S("a0"));
2924    test(S("abcdefghij"), 1, 9, S("1234567890"), 10, 0, S("a"));
2925    test(S("abcdefghij"), 1, 9, S("1234567890"), 10, 1, S("a"));
2926    test(S("abcdefghij"), 1, 9, S("1234567890"), 11, 0, S("can't happen"));
2927    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 0, S("a"));
2928    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 1, S("a1"));
2929    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 10, S("a1234567890"));
2930    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
2931    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
2932    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
2933    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 0, S("a"));
2934    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 1, S("a2"));
2935    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 9, S("a234567890"));
2936    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
2937    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
2938    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
2939    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 0, S("a"));
2940    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 1, S("a1"));
2941    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 5, S("a12345"));
2942    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 9, S("a123456789"));
2943    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 10, S("a1234567890"));
2944    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 11, S("a1234567890"));
2945    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 19, 0, S("a"));
2946    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 19, 1, S("a0"));
2947    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 19, 2, S("a0"));
2948    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 20, 0, S("a"));
2949    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 20, 1, S("a"));
2950    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
2951    test(S("abcdefghij"), 1, 10, S(""), 0, 0, S("a"));
2952    test(S("abcdefghij"), 1, 10, S(""), 0, 1, S("a"));
2953    test(S("abcdefghij"), 1, 10, S(""), 1, 0, S("can't happen"));
2954    test(S("abcdefghij"), 1, 10, S("12345"), 0, 0, S("a"));
2955    test(S("abcdefghij"), 1, 10, S("12345"), 0, 1, S("a1"));
2956    test(S("abcdefghij"), 1, 10, S("12345"), 0, 2, S("a12"));
2957    test(S("abcdefghij"), 1, 10, S("12345"), 0, 4, S("a1234"));
2958    test(S("abcdefghij"), 1, 10, S("12345"), 0, 5, S("a12345"));
2959    test(S("abcdefghij"), 1, 10, S("12345"), 0, 6, S("a12345"));
2960    test(S("abcdefghij"), 1, 10, S("12345"), 1, 0, S("a"));
2961    test(S("abcdefghij"), 1, 10, S("12345"), 1, 1, S("a2"));
2962    test(S("abcdefghij"), 1, 10, S("12345"), 1, 2, S("a23"));
2963    test(S("abcdefghij"), 1, 10, S("12345"), 1, 3, S("a234"));
2964    test(S("abcdefghij"), 1, 10, S("12345"), 1, 4, S("a2345"));
2965    test(S("abcdefghij"), 1, 10, S("12345"), 1, 5, S("a2345"));
2966    test(S("abcdefghij"), 1, 10, S("12345"), 2, 0, S("a"));
2967    test(S("abcdefghij"), 1, 10, S("12345"), 2, 1, S("a3"));
2968    test(S("abcdefghij"), 1, 10, S("12345"), 2, 2, S("a34"));
2969    test(S("abcdefghij"), 1, 10, S("12345"), 2, 3, S("a345"));
2970    test(S("abcdefghij"), 1, 10, S("12345"), 2, 4, S("a345"));
2971    test(S("abcdefghij"), 1, 10, S("12345"), 4, 0, S("a"));
2972    test(S("abcdefghij"), 1, 10, S("12345"), 4, 1, S("a5"));
2973    test(S("abcdefghij"), 1, 10, S("12345"), 4, 2, S("a5"));
2974    test(S("abcdefghij"), 1, 10, S("12345"), 5, 0, S("a"));
2975    test(S("abcdefghij"), 1, 10, S("12345"), 5, 1, S("a"));
2976    test(S("abcdefghij"), 1, 10, S("12345"), 6, 0, S("can't happen"));
2977    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 0, S("a"));
2978    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 1, S("a1"));
2979    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 5, S("a12345"));
2980    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 9, S("a123456789"));
2981    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 10, S("a1234567890"));
2982    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 11, S("a1234567890"));
2983    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 0, S("a"));
2984    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 1, S("a2"));
2985    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 4, S("a2345"));
2986    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 8, S("a23456789"));
2987    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 9, S("a234567890"));
2988    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 10, S("a234567890"));
2989    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 0, S("a"));
2990    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 1, S("a6"));
2991    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 2, S("a67"));
2992    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 4, S("a6789"));
2993    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 5, S("a67890"));
2994    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 6, S("a67890"));
2995    test(S("abcdefghij"), 1, 10, S("1234567890"), 9, 0, S("a"));
2996    test(S("abcdefghij"), 1, 10, S("1234567890"), 9, 1, S("a0"));
2997    test(S("abcdefghij"), 1, 10, S("1234567890"), 9, 2, S("a0"));
2998    test(S("abcdefghij"), 1, 10, S("1234567890"), 10, 0, S("a"));
2999    test(S("abcdefghij"), 1, 10, S("1234567890"), 10, 1, S("a"));
3000    test(S("abcdefghij"), 1, 10, S("1234567890"), 11, 0, S("can't happen"));
3001    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 0, S("a"));
3002    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 1, S("a1"));
3003    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 10, S("a1234567890"));
3004    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
3005    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
3006    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
3007    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 0, S("a"));
3008    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 1, S("a2"));
3009    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 9, S("a234567890"));
3010    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
3011    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
3012    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
3013}
3014
3015template <class S>
3016void test28()
3017{
3018    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 0, S("a"));
3019    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 1, S("a1"));
3020    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 5, S("a12345"));
3021    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 9, S("a123456789"));
3022    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 10, S("a1234567890"));
3023    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 11, S("a1234567890"));
3024    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 19, 0, S("a"));
3025    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 19, 1, S("a0"));
3026    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 19, 2, S("a0"));
3027    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 20, 0, S("a"));
3028    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 20, 1, S("a"));
3029    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
3030    test(S("abcdefghij"), 5, 0, S(""), 0, 0, S("abcdefghij"));
3031    test(S("abcdefghij"), 5, 0, S(""), 0, 1, S("abcdefghij"));
3032    test(S("abcdefghij"), 5, 0, S(""), 1, 0, S("can't happen"));
3033    test(S("abcdefghij"), 5, 0, S("12345"), 0, 0, S("abcdefghij"));
3034    test(S("abcdefghij"), 5, 0, S("12345"), 0, 1, S("abcde1fghij"));
3035    test(S("abcdefghij"), 5, 0, S("12345"), 0, 2, S("abcde12fghij"));
3036    test(S("abcdefghij"), 5, 0, S("12345"), 0, 4, S("abcde1234fghij"));
3037    test(S("abcdefghij"), 5, 0, S("12345"), 0, 5, S("abcde12345fghij"));
3038    test(S("abcdefghij"), 5, 0, S("12345"), 0, 6, S("abcde12345fghij"));
3039    test(S("abcdefghij"), 5, 0, S("12345"), 1, 0, S("abcdefghij"));
3040    test(S("abcdefghij"), 5, 0, S("12345"), 1, 1, S("abcde2fghij"));
3041    test(S("abcdefghij"), 5, 0, S("12345"), 1, 2, S("abcde23fghij"));
3042    test(S("abcdefghij"), 5, 0, S("12345"), 1, 3, S("abcde234fghij"));
3043    test(S("abcdefghij"), 5, 0, S("12345"), 1, 4, S("abcde2345fghij"));
3044    test(S("abcdefghij"), 5, 0, S("12345"), 1, 5, S("abcde2345fghij"));
3045    test(S("abcdefghij"), 5, 0, S("12345"), 2, 0, S("abcdefghij"));
3046    test(S("abcdefghij"), 5, 0, S("12345"), 2, 1, S("abcde3fghij"));
3047    test(S("abcdefghij"), 5, 0, S("12345"), 2, 2, S("abcde34fghij"));
3048    test(S("abcdefghij"), 5, 0, S("12345"), 2, 3, S("abcde345fghij"));
3049    test(S("abcdefghij"), 5, 0, S("12345"), 2, 4, S("abcde345fghij"));
3050    test(S("abcdefghij"), 5, 0, S("12345"), 4, 0, S("abcdefghij"));
3051    test(S("abcdefghij"), 5, 0, S("12345"), 4, 1, S("abcde5fghij"));
3052    test(S("abcdefghij"), 5, 0, S("12345"), 4, 2, S("abcde5fghij"));
3053    test(S("abcdefghij"), 5, 0, S("12345"), 5, 0, S("abcdefghij"));
3054    test(S("abcdefghij"), 5, 0, S("12345"), 5, 1, S("abcdefghij"));
3055    test(S("abcdefghij"), 5, 0, S("12345"), 6, 0, S("can't happen"));
3056    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 0, S("abcdefghij"));
3057    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 1, S("abcde1fghij"));
3058    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 5, S("abcde12345fghij"));
3059    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 9, S("abcde123456789fghij"));
3060    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 10, S("abcde1234567890fghij"));
3061    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 11, S("abcde1234567890fghij"));
3062    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 0, S("abcdefghij"));
3063    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 1, S("abcde2fghij"));
3064    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 4, S("abcde2345fghij"));
3065    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 8, S("abcde23456789fghij"));
3066    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 9, S("abcde234567890fghij"));
3067    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 10, S("abcde234567890fghij"));
3068    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 0, S("abcdefghij"));
3069    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 1, S("abcde6fghij"));
3070    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 2, S("abcde67fghij"));
3071    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 4, S("abcde6789fghij"));
3072    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 5, S("abcde67890fghij"));
3073    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 6, S("abcde67890fghij"));
3074    test(S("abcdefghij"), 5, 0, S("1234567890"), 9, 0, S("abcdefghij"));
3075    test(S("abcdefghij"), 5, 0, S("1234567890"), 9, 1, S("abcde0fghij"));
3076    test(S("abcdefghij"), 5, 0, S("1234567890"), 9, 2, S("abcde0fghij"));
3077    test(S("abcdefghij"), 5, 0, S("1234567890"), 10, 0, S("abcdefghij"));
3078    test(S("abcdefghij"), 5, 0, S("1234567890"), 10, 1, S("abcdefghij"));
3079    test(S("abcdefghij"), 5, 0, S("1234567890"), 11, 0, S("can't happen"));
3080    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
3081    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 1, S("abcde1fghij"));
3082    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 10, S("abcde1234567890fghij"));
3083    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789fghij"));
3084    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890fghij"));
3085    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890fghij"));
3086    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
3087    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 1, S("abcde2fghij"));
3088    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 9, S("abcde234567890fghij"));
3089    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 18, S("abcde234567890123456789fghij"));
3090    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890fghij"));
3091    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890fghij"));
3092    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
3093    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 1, S("abcde1fghij"));
3094    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 5, S("abcde12345fghij"));
3095    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 9, S("abcde123456789fghij"));
3096    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 10, S("abcde1234567890fghij"));
3097    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 11, S("abcde1234567890fghij"));
3098    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
3099    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 19, 1, S("abcde0fghij"));
3100    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 19, 2, S("abcde0fghij"));
3101    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
3102    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
3103    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
3104    test(S("abcdefghij"), 5, 1, S(""), 0, 0, S("abcdeghij"));
3105    test(S("abcdefghij"), 5, 1, S(""), 0, 1, S("abcdeghij"));
3106    test(S("abcdefghij"), 5, 1, S(""), 1, 0, S("can't happen"));
3107    test(S("abcdefghij"), 5, 1, S("12345"), 0, 0, S("abcdeghij"));
3108    test(S("abcdefghij"), 5, 1, S("12345"), 0, 1, S("abcde1ghij"));
3109    test(S("abcdefghij"), 5, 1, S("12345"), 0, 2, S("abcde12ghij"));
3110    test(S("abcdefghij"), 5, 1, S("12345"), 0, 4, S("abcde1234ghij"));
3111    test(S("abcdefghij"), 5, 1, S("12345"), 0, 5, S("abcde12345ghij"));
3112    test(S("abcdefghij"), 5, 1, S("12345"), 0, 6, S("abcde12345ghij"));
3113    test(S("abcdefghij"), 5, 1, S("12345"), 1, 0, S("abcdeghij"));
3114    test(S("abcdefghij"), 5, 1, S("12345"), 1, 1, S("abcde2ghij"));
3115    test(S("abcdefghij"), 5, 1, S("12345"), 1, 2, S("abcde23ghij"));
3116    test(S("abcdefghij"), 5, 1, S("12345"), 1, 3, S("abcde234ghij"));
3117    test(S("abcdefghij"), 5, 1, S("12345"), 1, 4, S("abcde2345ghij"));
3118}
3119
3120template <class S>
3121void test29()
3122{
3123    test(S("abcdefghij"), 5, 1, S("12345"), 1, 5, S("abcde2345ghij"));
3124    test(S("abcdefghij"), 5, 1, S("12345"), 2, 0, S("abcdeghij"));
3125    test(S("abcdefghij"), 5, 1, S("12345"), 2, 1, S("abcde3ghij"));
3126    test(S("abcdefghij"), 5, 1, S("12345"), 2, 2, S("abcde34ghij"));
3127    test(S("abcdefghij"), 5, 1, S("12345"), 2, 3, S("abcde345ghij"));
3128    test(S("abcdefghij"), 5, 1, S("12345"), 2, 4, S("abcde345ghij"));
3129    test(S("abcdefghij"), 5, 1, S("12345"), 4, 0, S("abcdeghij"));
3130    test(S("abcdefghij"), 5, 1, S("12345"), 4, 1, S("abcde5ghij"));
3131    test(S("abcdefghij"), 5, 1, S("12345"), 4, 2, S("abcde5ghij"));
3132    test(S("abcdefghij"), 5, 1, S("12345"), 5, 0, S("abcdeghij"));
3133    test(S("abcdefghij"), 5, 1, S("12345"), 5, 1, S("abcdeghij"));
3134    test(S("abcdefghij"), 5, 1, S("12345"), 6, 0, S("can't happen"));
3135    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 0, S("abcdeghij"));
3136    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 1, S("abcde1ghij"));
3137    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 5, S("abcde12345ghij"));
3138    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 9, S("abcde123456789ghij"));
3139    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 10, S("abcde1234567890ghij"));
3140    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 11, S("abcde1234567890ghij"));
3141    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 0, S("abcdeghij"));
3142    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 1, S("abcde2ghij"));
3143    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 4, S("abcde2345ghij"));
3144    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 8, S("abcde23456789ghij"));
3145    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 9, S("abcde234567890ghij"));
3146    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 10, S("abcde234567890ghij"));
3147    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 0, S("abcdeghij"));
3148    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 1, S("abcde6ghij"));
3149    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 2, S("abcde67ghij"));
3150    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 4, S("abcde6789ghij"));
3151    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 5, S("abcde67890ghij"));
3152    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 6, S("abcde67890ghij"));
3153    test(S("abcdefghij"), 5, 1, S("1234567890"), 9, 0, S("abcdeghij"));
3154    test(S("abcdefghij"), 5, 1, S("1234567890"), 9, 1, S("abcde0ghij"));
3155    test(S("abcdefghij"), 5, 1, S("1234567890"), 9, 2, S("abcde0ghij"));
3156    test(S("abcdefghij"), 5, 1, S("1234567890"), 10, 0, S("abcdeghij"));
3157    test(S("abcdefghij"), 5, 1, S("1234567890"), 10, 1, S("abcdeghij"));
3158    test(S("abcdefghij"), 5, 1, S("1234567890"), 11, 0, S("can't happen"));
3159    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 0, S("abcdeghij"));
3160    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 1, S("abcde1ghij"));
3161    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 10, S("abcde1234567890ghij"));
3162    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789ghij"));
3163    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890ghij"));
3164    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890ghij"));
3165    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 0, S("abcdeghij"));
3166    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 1, S("abcde2ghij"));
3167    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 9, S("abcde234567890ghij"));
3168    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 18, S("abcde234567890123456789ghij"));
3169    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890ghij"));
3170    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890ghij"));
3171    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 0, S("abcdeghij"));
3172    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 1, S("abcde1ghij"));
3173    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 5, S("abcde12345ghij"));
3174    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 9, S("abcde123456789ghij"));
3175    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 10, S("abcde1234567890ghij"));
3176    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 11, S("abcde1234567890ghij"));
3177    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 19, 0, S("abcdeghij"));
3178    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 19, 1, S("abcde0ghij"));
3179    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 19, 2, S("abcde0ghij"));
3180    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 20, 0, S("abcdeghij"));
3181    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 20, 1, S("abcdeghij"));
3182    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
3183    test(S("abcdefghij"), 5, 2, S(""), 0, 0, S("abcdehij"));
3184    test(S("abcdefghij"), 5, 2, S(""), 0, 1, S("abcdehij"));
3185    test(S("abcdefghij"), 5, 2, S(""), 1, 0, S("can't happen"));
3186    test(S("abcdefghij"), 5, 2, S("12345"), 0, 0, S("abcdehij"));
3187    test(S("abcdefghij"), 5, 2, S("12345"), 0, 1, S("abcde1hij"));
3188    test(S("abcdefghij"), 5, 2, S("12345"), 0, 2, S("abcde12hij"));
3189    test(S("abcdefghij"), 5, 2, S("12345"), 0, 4, S("abcde1234hij"));
3190    test(S("abcdefghij"), 5, 2, S("12345"), 0, 5, S("abcde12345hij"));
3191    test(S("abcdefghij"), 5, 2, S("12345"), 0, 6, S("abcde12345hij"));
3192    test(S("abcdefghij"), 5, 2, S("12345"), 1, 0, S("abcdehij"));
3193    test(S("abcdefghij"), 5, 2, S("12345"), 1, 1, S("abcde2hij"));
3194    test(S("abcdefghij"), 5, 2, S("12345"), 1, 2, S("abcde23hij"));
3195    test(S("abcdefghij"), 5, 2, S("12345"), 1, 3, S("abcde234hij"));
3196    test(S("abcdefghij"), 5, 2, S("12345"), 1, 4, S("abcde2345hij"));
3197    test(S("abcdefghij"), 5, 2, S("12345"), 1, 5, S("abcde2345hij"));
3198    test(S("abcdefghij"), 5, 2, S("12345"), 2, 0, S("abcdehij"));
3199    test(S("abcdefghij"), 5, 2, S("12345"), 2, 1, S("abcde3hij"));
3200    test(S("abcdefghij"), 5, 2, S("12345"), 2, 2, S("abcde34hij"));
3201    test(S("abcdefghij"), 5, 2, S("12345"), 2, 3, S("abcde345hij"));
3202    test(S("abcdefghij"), 5, 2, S("12345"), 2, 4, S("abcde345hij"));
3203    test(S("abcdefghij"), 5, 2, S("12345"), 4, 0, S("abcdehij"));
3204    test(S("abcdefghij"), 5, 2, S("12345"), 4, 1, S("abcde5hij"));
3205    test(S("abcdefghij"), 5, 2, S("12345"), 4, 2, S("abcde5hij"));
3206    test(S("abcdefghij"), 5, 2, S("12345"), 5, 0, S("abcdehij"));
3207    test(S("abcdefghij"), 5, 2, S("12345"), 5, 1, S("abcdehij"));
3208    test(S("abcdefghij"), 5, 2, S("12345"), 6, 0, S("can't happen"));
3209    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 0, S("abcdehij"));
3210    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 1, S("abcde1hij"));
3211    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 5, S("abcde12345hij"));
3212    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 9, S("abcde123456789hij"));
3213    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 10, S("abcde1234567890hij"));
3214    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 11, S("abcde1234567890hij"));
3215    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 0, S("abcdehij"));
3216    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 1, S("abcde2hij"));
3217    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 4, S("abcde2345hij"));
3218    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 8, S("abcde23456789hij"));
3219    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 9, S("abcde234567890hij"));
3220    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 10, S("abcde234567890hij"));
3221    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 0, S("abcdehij"));
3222    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 1, S("abcde6hij"));
3223}
3224
3225template <class S>
3226void test30()
3227{
3228    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 2, S("abcde67hij"));
3229    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 4, S("abcde6789hij"));
3230    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 5, S("abcde67890hij"));
3231    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 6, S("abcde67890hij"));
3232    test(S("abcdefghij"), 5, 2, S("1234567890"), 9, 0, S("abcdehij"));
3233    test(S("abcdefghij"), 5, 2, S("1234567890"), 9, 1, S("abcde0hij"));
3234    test(S("abcdefghij"), 5, 2, S("1234567890"), 9, 2, S("abcde0hij"));
3235    test(S("abcdefghij"), 5, 2, S("1234567890"), 10, 0, S("abcdehij"));
3236    test(S("abcdefghij"), 5, 2, S("1234567890"), 10, 1, S("abcdehij"));
3237    test(S("abcdefghij"), 5, 2, S("1234567890"), 11, 0, S("can't happen"));
3238    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 0, S("abcdehij"));
3239    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 1, S("abcde1hij"));
3240    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 10, S("abcde1234567890hij"));
3241    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789hij"));
3242    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890hij"));
3243    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890hij"));
3244    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 0, S("abcdehij"));
3245    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 1, S("abcde2hij"));
3246    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 9, S("abcde234567890hij"));
3247    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 18, S("abcde234567890123456789hij"));
3248    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890hij"));
3249    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890hij"));
3250    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 0, S("abcdehij"));
3251    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 1, S("abcde1hij"));
3252    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 5, S("abcde12345hij"));
3253    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 9, S("abcde123456789hij"));
3254    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 10, S("abcde1234567890hij"));
3255    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 11, S("abcde1234567890hij"));
3256    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 19, 0, S("abcdehij"));
3257    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 19, 1, S("abcde0hij"));
3258    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 19, 2, S("abcde0hij"));
3259    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 20, 0, S("abcdehij"));
3260    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 20, 1, S("abcdehij"));
3261    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
3262    test(S("abcdefghij"), 5, 4, S(""), 0, 0, S("abcdej"));
3263    test(S("abcdefghij"), 5, 4, S(""), 0, 1, S("abcdej"));
3264    test(S("abcdefghij"), 5, 4, S(""), 1, 0, S("can't happen"));
3265    test(S("abcdefghij"), 5, 4, S("12345"), 0, 0, S("abcdej"));
3266    test(S("abcdefghij"), 5, 4, S("12345"), 0, 1, S("abcde1j"));
3267    test(S("abcdefghij"), 5, 4, S("12345"), 0, 2, S("abcde12j"));
3268    test(S("abcdefghij"), 5, 4, S("12345"), 0, 4, S("abcde1234j"));
3269    test(S("abcdefghij"), 5, 4, S("12345"), 0, 5, S("abcde12345j"));
3270    test(S("abcdefghij"), 5, 4, S("12345"), 0, 6, S("abcde12345j"));
3271    test(S("abcdefghij"), 5, 4, S("12345"), 1, 0, S("abcdej"));
3272    test(S("abcdefghij"), 5, 4, S("12345"), 1, 1, S("abcde2j"));
3273    test(S("abcdefghij"), 5, 4, S("12345"), 1, 2, S("abcde23j"));
3274    test(S("abcdefghij"), 5, 4, S("12345"), 1, 3, S("abcde234j"));
3275    test(S("abcdefghij"), 5, 4, S("12345"), 1, 4, S("abcde2345j"));
3276    test(S("abcdefghij"), 5, 4, S("12345"), 1, 5, S("abcde2345j"));
3277    test(S("abcdefghij"), 5, 4, S("12345"), 2, 0, S("abcdej"));
3278    test(S("abcdefghij"), 5, 4, S("12345"), 2, 1, S("abcde3j"));
3279    test(S("abcdefghij"), 5, 4, S("12345"), 2, 2, S("abcde34j"));
3280    test(S("abcdefghij"), 5, 4, S("12345"), 2, 3, S("abcde345j"));
3281    test(S("abcdefghij"), 5, 4, S("12345"), 2, 4, S("abcde345j"));
3282    test(S("abcdefghij"), 5, 4, S("12345"), 4, 0, S("abcdej"));
3283    test(S("abcdefghij"), 5, 4, S("12345"), 4, 1, S("abcde5j"));
3284    test(S("abcdefghij"), 5, 4, S("12345"), 4, 2, S("abcde5j"));
3285    test(S("abcdefghij"), 5, 4, S("12345"), 5, 0, S("abcdej"));
3286    test(S("abcdefghij"), 5, 4, S("12345"), 5, 1, S("abcdej"));
3287    test(S("abcdefghij"), 5, 4, S("12345"), 6, 0, S("can't happen"));
3288    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 0, S("abcdej"));
3289    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 1, S("abcde1j"));
3290    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 5, S("abcde12345j"));
3291    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 9, S("abcde123456789j"));
3292    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 10, S("abcde1234567890j"));
3293    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 11, S("abcde1234567890j"));
3294    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 0, S("abcdej"));
3295    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 1, S("abcde2j"));
3296    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 4, S("abcde2345j"));
3297    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 8, S("abcde23456789j"));
3298    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 9, S("abcde234567890j"));
3299    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 10, S("abcde234567890j"));
3300    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 0, S("abcdej"));
3301    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 1, S("abcde6j"));
3302    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 2, S("abcde67j"));
3303    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 4, S("abcde6789j"));
3304    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 5, S("abcde67890j"));
3305    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 6, S("abcde67890j"));
3306    test(S("abcdefghij"), 5, 4, S("1234567890"), 9, 0, S("abcdej"));
3307    test(S("abcdefghij"), 5, 4, S("1234567890"), 9, 1, S("abcde0j"));
3308    test(S("abcdefghij"), 5, 4, S("1234567890"), 9, 2, S("abcde0j"));
3309    test(S("abcdefghij"), 5, 4, S("1234567890"), 10, 0, S("abcdej"));
3310    test(S("abcdefghij"), 5, 4, S("1234567890"), 10, 1, S("abcdej"));
3311    test(S("abcdefghij"), 5, 4, S("1234567890"), 11, 0, S("can't happen"));
3312    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 0, S("abcdej"));
3313    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 1, S("abcde1j"));
3314    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 10, S("abcde1234567890j"));
3315    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789j"));
3316    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890j"));
3317    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890j"));
3318    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 0, S("abcdej"));
3319    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 1, S("abcde2j"));
3320    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 9, S("abcde234567890j"));
3321    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 18, S("abcde234567890123456789j"));
3322    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890j"));
3323    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890j"));
3324    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 0, S("abcdej"));
3325    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 1, S("abcde1j"));
3326    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 5, S("abcde12345j"));
3327    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 9, S("abcde123456789j"));
3328}
3329
3330template <class S>
3331void test31()
3332{
3333    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 10, S("abcde1234567890j"));
3334    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 11, S("abcde1234567890j"));
3335    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 19, 0, S("abcdej"));
3336    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 19, 1, S("abcde0j"));
3337    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 19, 2, S("abcde0j"));
3338    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 20, 0, S("abcdej"));
3339    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 20, 1, S("abcdej"));
3340    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
3341    test(S("abcdefghij"), 5, 5, S(""), 0, 0, S("abcde"));
3342    test(S("abcdefghij"), 5, 5, S(""), 0, 1, S("abcde"));
3343    test(S("abcdefghij"), 5, 5, S(""), 1, 0, S("can't happen"));
3344    test(S("abcdefghij"), 5, 5, S("12345"), 0, 0, S("abcde"));
3345    test(S("abcdefghij"), 5, 5, S("12345"), 0, 1, S("abcde1"));
3346    test(S("abcdefghij"), 5, 5, S("12345"), 0, 2, S("abcde12"));
3347    test(S("abcdefghij"), 5, 5, S("12345"), 0, 4, S("abcde1234"));
3348    test(S("abcdefghij"), 5, 5, S("12345"), 0, 5, S("abcde12345"));
3349    test(S("abcdefghij"), 5, 5, S("12345"), 0, 6, S("abcde12345"));
3350    test(S("abcdefghij"), 5, 5, S("12345"), 1, 0, S("abcde"));
3351    test(S("abcdefghij"), 5, 5, S("12345"), 1, 1, S("abcde2"));
3352    test(S("abcdefghij"), 5, 5, S("12345"), 1, 2, S("abcde23"));
3353    test(S("abcdefghij"), 5, 5, S("12345"), 1, 3, S("abcde234"));
3354    test(S("abcdefghij"), 5, 5, S("12345"), 1, 4, S("abcde2345"));
3355    test(S("abcdefghij"), 5, 5, S("12345"), 1, 5, S("abcde2345"));
3356    test(S("abcdefghij"), 5, 5, S("12345"), 2, 0, S("abcde"));
3357    test(S("abcdefghij"), 5, 5, S("12345"), 2, 1, S("abcde3"));
3358    test(S("abcdefghij"), 5, 5, S("12345"), 2, 2, S("abcde34"));
3359    test(S("abcdefghij"), 5, 5, S("12345"), 2, 3, S("abcde345"));
3360    test(S("abcdefghij"), 5, 5, S("12345"), 2, 4, S("abcde345"));
3361    test(S("abcdefghij"), 5, 5, S("12345"), 4, 0, S("abcde"));
3362    test(S("abcdefghij"), 5, 5, S("12345"), 4, 1, S("abcde5"));
3363    test(S("abcdefghij"), 5, 5, S("12345"), 4, 2, S("abcde5"));
3364    test(S("abcdefghij"), 5, 5, S("12345"), 5, 0, S("abcde"));
3365    test(S("abcdefghij"), 5, 5, S("12345"), 5, 1, S("abcde"));
3366    test(S("abcdefghij"), 5, 5, S("12345"), 6, 0, S("can't happen"));
3367    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 0, S("abcde"));
3368    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 1, S("abcde1"));
3369    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 5, S("abcde12345"));
3370    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 9, S("abcde123456789"));
3371    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 10, S("abcde1234567890"));
3372    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 11, S("abcde1234567890"));
3373    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 0, S("abcde"));
3374    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 1, S("abcde2"));
3375    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 4, S("abcde2345"));
3376    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 8, S("abcde23456789"));
3377    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 9, S("abcde234567890"));
3378    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 10, S("abcde234567890"));
3379    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 0, S("abcde"));
3380    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 1, S("abcde6"));
3381    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 2, S("abcde67"));
3382    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 4, S("abcde6789"));
3383    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 5, S("abcde67890"));
3384    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 6, S("abcde67890"));
3385    test(S("abcdefghij"), 5, 5, S("1234567890"), 9, 0, S("abcde"));
3386    test(S("abcdefghij"), 5, 5, S("1234567890"), 9, 1, S("abcde0"));
3387    test(S("abcdefghij"), 5, 5, S("1234567890"), 9, 2, S("abcde0"));
3388    test(S("abcdefghij"), 5, 5, S("1234567890"), 10, 0, S("abcde"));
3389    test(S("abcdefghij"), 5, 5, S("1234567890"), 10, 1, S("abcde"));
3390    test(S("abcdefghij"), 5, 5, S("1234567890"), 11, 0, S("can't happen"));
3391    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 0, S("abcde"));
3392    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 1, S("abcde1"));
3393    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
3394    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
3395    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
3396    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
3397    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 0, S("abcde"));
3398    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 1, S("abcde2"));
3399    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 9, S("abcde234567890"));
3400    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
3401    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
3402    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
3403    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 0, S("abcde"));
3404    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 1, S("abcde1"));
3405    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 5, S("abcde12345"));
3406    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 9, S("abcde123456789"));
3407    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
3408    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
3409    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 19, 0, S("abcde"));
3410    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 19, 1, S("abcde0"));
3411    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 19, 2, S("abcde0"));
3412    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 20, 0, S("abcde"));
3413    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 20, 1, S("abcde"));
3414    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
3415    test(S("abcdefghij"), 5, 6, S(""), 0, 0, S("abcde"));
3416    test(S("abcdefghij"), 5, 6, S(""), 0, 1, S("abcde"));
3417    test(S("abcdefghij"), 5, 6, S(""), 1, 0, S("can't happen"));
3418    test(S("abcdefghij"), 5, 6, S("12345"), 0, 0, S("abcde"));
3419    test(S("abcdefghij"), 5, 6, S("12345"), 0, 1, S("abcde1"));
3420    test(S("abcdefghij"), 5, 6, S("12345"), 0, 2, S("abcde12"));
3421    test(S("abcdefghij"), 5, 6, S("12345"), 0, 4, S("abcde1234"));
3422    test(S("abcdefghij"), 5, 6, S("12345"), 0, 5, S("abcde12345"));
3423    test(S("abcdefghij"), 5, 6, S("12345"), 0, 6, S("abcde12345"));
3424    test(S("abcdefghij"), 5, 6, S("12345"), 1, 0, S("abcde"));
3425    test(S("abcdefghij"), 5, 6, S("12345"), 1, 1, S("abcde2"));
3426    test(S("abcdefghij"), 5, 6, S("12345"), 1, 2, S("abcde23"));
3427    test(S("abcdefghij"), 5, 6, S("12345"), 1, 3, S("abcde234"));
3428    test(S("abcdefghij"), 5, 6, S("12345"), 1, 4, S("abcde2345"));
3429    test(S("abcdefghij"), 5, 6, S("12345"), 1, 5, S("abcde2345"));
3430    test(S("abcdefghij"), 5, 6, S("12345"), 2, 0, S("abcde"));
3431    test(S("abcdefghij"), 5, 6, S("12345"), 2, 1, S("abcde3"));
3432    test(S("abcdefghij"), 5, 6, S("12345"), 2, 2, S("abcde34"));
3433}
3434
3435template <class S>
3436void test32()
3437{
3438    test(S("abcdefghij"), 5, 6, S("12345"), 2, 3, S("abcde345"));
3439    test(S("abcdefghij"), 5, 6, S("12345"), 2, 4, S("abcde345"));
3440    test(S("abcdefghij"), 5, 6, S("12345"), 4, 0, S("abcde"));
3441    test(S("abcdefghij"), 5, 6, S("12345"), 4, 1, S("abcde5"));
3442    test(S("abcdefghij"), 5, 6, S("12345"), 4, 2, S("abcde5"));
3443    test(S("abcdefghij"), 5, 6, S("12345"), 5, 0, S("abcde"));
3444    test(S("abcdefghij"), 5, 6, S("12345"), 5, 1, S("abcde"));
3445    test(S("abcdefghij"), 5, 6, S("12345"), 6, 0, S("can't happen"));
3446    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 0, S("abcde"));
3447    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 1, S("abcde1"));
3448    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 5, S("abcde12345"));
3449    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 9, S("abcde123456789"));
3450    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 10, S("abcde1234567890"));
3451    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 11, S("abcde1234567890"));
3452    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 0, S("abcde"));
3453    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 1, S("abcde2"));
3454    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 4, S("abcde2345"));
3455    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 8, S("abcde23456789"));
3456    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 9, S("abcde234567890"));
3457    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 10, S("abcde234567890"));
3458    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 0, S("abcde"));
3459    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 1, S("abcde6"));
3460    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 2, S("abcde67"));
3461    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 4, S("abcde6789"));
3462    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 5, S("abcde67890"));
3463    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 6, S("abcde67890"));
3464    test(S("abcdefghij"), 5, 6, S("1234567890"), 9, 0, S("abcde"));
3465    test(S("abcdefghij"), 5, 6, S("1234567890"), 9, 1, S("abcde0"));
3466    test(S("abcdefghij"), 5, 6, S("1234567890"), 9, 2, S("abcde0"));
3467    test(S("abcdefghij"), 5, 6, S("1234567890"), 10, 0, S("abcde"));
3468    test(S("abcdefghij"), 5, 6, S("1234567890"), 10, 1, S("abcde"));
3469    test(S("abcdefghij"), 5, 6, S("1234567890"), 11, 0, S("can't happen"));
3470    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 0, S("abcde"));
3471    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 1, S("abcde1"));
3472    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
3473    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
3474    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
3475    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
3476    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 0, S("abcde"));
3477    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 1, S("abcde2"));
3478    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 9, S("abcde234567890"));
3479    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
3480    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
3481    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
3482    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 0, S("abcde"));
3483    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 1, S("abcde1"));
3484    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 5, S("abcde12345"));
3485    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 9, S("abcde123456789"));
3486    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
3487    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
3488    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 19, 0, S("abcde"));
3489    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 19, 1, S("abcde0"));
3490    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 19, 2, S("abcde0"));
3491    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 20, 0, S("abcde"));
3492    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 20, 1, S("abcde"));
3493    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 21, 0, S("can't happen"));
3494    test(S("abcdefghij"), 9, 0, S(""), 0, 0, S("abcdefghij"));
3495    test(S("abcdefghij"), 9, 0, S(""), 0, 1, S("abcdefghij"));
3496    test(S("abcdefghij"), 9, 0, S(""), 1, 0, S("can't happen"));
3497    test(S("abcdefghij"), 9, 0, S("12345"), 0, 0, S("abcdefghij"));
3498    test(S("abcdefghij"), 9, 0, S("12345"), 0, 1, S("abcdefghi1j"));
3499    test(S("abcdefghij"), 9, 0, S("12345"), 0, 2, S("abcdefghi12j"));
3500    test(S("abcdefghij"), 9, 0, S("12345"), 0, 4, S("abcdefghi1234j"));
3501    test(S("abcdefghij"), 9, 0, S("12345"), 0, 5, S("abcdefghi12345j"));
3502    test(S("abcdefghij"), 9, 0, S("12345"), 0, 6, S("abcdefghi12345j"));
3503    test(S("abcdefghij"), 9, 0, S("12345"), 1, 0, S("abcdefghij"));
3504    test(S("abcdefghij"), 9, 0, S("12345"), 1, 1, S("abcdefghi2j"));
3505    test(S("abcdefghij"), 9, 0, S("12345"), 1, 2, S("abcdefghi23j"));
3506    test(S("abcdefghij"), 9, 0, S("12345"), 1, 3, S("abcdefghi234j"));
3507    test(S("abcdefghij"), 9, 0, S("12345"), 1, 4, S("abcdefghi2345j"));
3508    test(S("abcdefghij"), 9, 0, S("12345"), 1, 5, S("abcdefghi2345j"));
3509    test(S("abcdefghij"), 9, 0, S("12345"), 2, 0, S("abcdefghij"));
3510    test(S("abcdefghij"), 9, 0, S("12345"), 2, 1, S("abcdefghi3j"));
3511    test(S("abcdefghij"), 9, 0, S("12345"), 2, 2, S("abcdefghi34j"));
3512    test(S("abcdefghij"), 9, 0, S("12345"), 2, 3, S("abcdefghi345j"));
3513    test(S("abcdefghij"), 9, 0, S("12345"), 2, 4, S("abcdefghi345j"));
3514    test(S("abcdefghij"), 9, 0, S("12345"), 4, 0, S("abcdefghij"));
3515    test(S("abcdefghij"), 9, 0, S("12345"), 4, 1, S("abcdefghi5j"));
3516    test(S("abcdefghij"), 9, 0, S("12345"), 4, 2, S("abcdefghi5j"));
3517    test(S("abcdefghij"), 9, 0, S("12345"), 5, 0, S("abcdefghij"));
3518    test(S("abcdefghij"), 9, 0, S("12345"), 5, 1, S("abcdefghij"));
3519    test(S("abcdefghij"), 9, 0, S("12345"), 6, 0, S("can't happen"));
3520    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 0, S("abcdefghij"));
3521    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 1, S("abcdefghi1j"));
3522    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 5, S("abcdefghi12345j"));
3523    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 9, S("abcdefghi123456789j"));
3524    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 10, S("abcdefghi1234567890j"));
3525    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 11, S("abcdefghi1234567890j"));
3526    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 0, S("abcdefghij"));
3527    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 1, S("abcdefghi2j"));
3528    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 4, S("abcdefghi2345j"));
3529    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 8, S("abcdefghi23456789j"));
3530    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 9, S("abcdefghi234567890j"));
3531    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 10, S("abcdefghi234567890j"));
3532    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 0, S("abcdefghij"));
3533    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 1, S("abcdefghi6j"));
3534    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 2, S("abcdefghi67j"));
3535    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 4, S("abcdefghi6789j"));
3536    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 5, S("abcdefghi67890j"));
3537    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 6, S("abcdefghi67890j"));
3538}
3539
3540template <class S>
3541void test33()
3542{
3543    test(S("abcdefghij"), 9, 0, S("1234567890"), 9, 0, S("abcdefghij"));
3544    test(S("abcdefghij"), 9, 0, S("1234567890"), 9, 1, S("abcdefghi0j"));
3545    test(S("abcdefghij"), 9, 0, S("1234567890"), 9, 2, S("abcdefghi0j"));
3546    test(S("abcdefghij"), 9, 0, S("1234567890"), 10, 0, S("abcdefghij"));
3547    test(S("abcdefghij"), 9, 0, S("1234567890"), 10, 1, S("abcdefghij"));
3548    test(S("abcdefghij"), 9, 0, S("1234567890"), 11, 0, S("can't happen"));
3549    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
3550    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 1, S("abcdefghi1j"));
3551    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 10, S("abcdefghi1234567890j"));
3552    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789j"));
3553    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890j"));
3554    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890j"));
3555    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
3556    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 1, S("abcdefghi2j"));
3557    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 9, S("abcdefghi234567890j"));
3558    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789j"));
3559    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890j"));
3560    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890j"));
3561    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
3562    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 1, S("abcdefghi1j"));
3563    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 5, S("abcdefghi12345j"));
3564    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 9, S("abcdefghi123456789j"));
3565    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 10, S("abcdefghi1234567890j"));
3566    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 11, S("abcdefghi1234567890j"));
3567    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
3568    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 19, 1, S("abcdefghi0j"));
3569    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 19, 2, S("abcdefghi0j"));
3570    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
3571    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
3572    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
3573    test(S("abcdefghij"), 9, 1, S(""), 0, 0, S("abcdefghi"));
3574    test(S("abcdefghij"), 9, 1, S(""), 0, 1, S("abcdefghi"));
3575    test(S("abcdefghij"), 9, 1, S(""), 1, 0, S("can't happen"));
3576    test(S("abcdefghij"), 9, 1, S("12345"), 0, 0, S("abcdefghi"));
3577    test(S("abcdefghij"), 9, 1, S("12345"), 0, 1, S("abcdefghi1"));
3578    test(S("abcdefghij"), 9, 1, S("12345"), 0, 2, S("abcdefghi12"));
3579    test(S("abcdefghij"), 9, 1, S("12345"), 0, 4, S("abcdefghi1234"));
3580    test(S("abcdefghij"), 9, 1, S("12345"), 0, 5, S("abcdefghi12345"));
3581    test(S("abcdefghij"), 9, 1, S("12345"), 0, 6, S("abcdefghi12345"));
3582    test(S("abcdefghij"), 9, 1, S("12345"), 1, 0, S("abcdefghi"));
3583    test(S("abcdefghij"), 9, 1, S("12345"), 1, 1, S("abcdefghi2"));
3584    test(S("abcdefghij"), 9, 1, S("12345"), 1, 2, S("abcdefghi23"));
3585    test(S("abcdefghij"), 9, 1, S("12345"), 1, 3, S("abcdefghi234"));
3586    test(S("abcdefghij"), 9, 1, S("12345"), 1, 4, S("abcdefghi2345"));
3587    test(S("abcdefghij"), 9, 1, S("12345"), 1, 5, S("abcdefghi2345"));
3588    test(S("abcdefghij"), 9, 1, S("12345"), 2, 0, S("abcdefghi"));
3589    test(S("abcdefghij"), 9, 1, S("12345"), 2, 1, S("abcdefghi3"));
3590    test(S("abcdefghij"), 9, 1, S("12345"), 2, 2, S("abcdefghi34"));
3591    test(S("abcdefghij"), 9, 1, S("12345"), 2, 3, S("abcdefghi345"));
3592    test(S("abcdefghij"), 9, 1, S("12345"), 2, 4, S("abcdefghi345"));
3593    test(S("abcdefghij"), 9, 1, S("12345"), 4, 0, S("abcdefghi"));
3594    test(S("abcdefghij"), 9, 1, S("12345"), 4, 1, S("abcdefghi5"));
3595    test(S("abcdefghij"), 9, 1, S("12345"), 4, 2, S("abcdefghi5"));
3596    test(S("abcdefghij"), 9, 1, S("12345"), 5, 0, S("abcdefghi"));
3597    test(S("abcdefghij"), 9, 1, S("12345"), 5, 1, S("abcdefghi"));
3598    test(S("abcdefghij"), 9, 1, S("12345"), 6, 0, S("can't happen"));
3599    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 0, S("abcdefghi"));
3600    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 1, S("abcdefghi1"));
3601    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 5, S("abcdefghi12345"));
3602    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 9, S("abcdefghi123456789"));
3603    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 10, S("abcdefghi1234567890"));
3604    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 11, S("abcdefghi1234567890"));
3605    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 0, S("abcdefghi"));
3606    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 1, S("abcdefghi2"));
3607    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 4, S("abcdefghi2345"));
3608    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 8, S("abcdefghi23456789"));
3609    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 9, S("abcdefghi234567890"));
3610    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 10, S("abcdefghi234567890"));
3611    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 0, S("abcdefghi"));
3612    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 1, S("abcdefghi6"));
3613    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 2, S("abcdefghi67"));
3614    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 4, S("abcdefghi6789"));
3615    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 5, S("abcdefghi67890"));
3616    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 6, S("abcdefghi67890"));
3617    test(S("abcdefghij"), 9, 1, S("1234567890"), 9, 0, S("abcdefghi"));
3618    test(S("abcdefghij"), 9, 1, S("1234567890"), 9, 1, S("abcdefghi0"));
3619    test(S("abcdefghij"), 9, 1, S("1234567890"), 9, 2, S("abcdefghi0"));
3620    test(S("abcdefghij"), 9, 1, S("1234567890"), 10, 0, S("abcdefghi"));
3621    test(S("abcdefghij"), 9, 1, S("1234567890"), 10, 1, S("abcdefghi"));
3622    test(S("abcdefghij"), 9, 1, S("1234567890"), 11, 0, S("can't happen"));
3623    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 0, S("abcdefghi"));
3624    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 1, S("abcdefghi1"));
3625    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 10, S("abcdefghi1234567890"));
3626    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789"));
3627    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890"));
3628    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890"));
3629    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 0, S("abcdefghi"));
3630    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 1, S("abcdefghi2"));
3631    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 9, S("abcdefghi234567890"));
3632    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789"));
3633    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890"));
3634    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890"));
3635    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 0, S("abcdefghi"));
3636    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 1, S("abcdefghi1"));
3637    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 5, S("abcdefghi12345"));
3638    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 9, S("abcdefghi123456789"));
3639    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 10, S("abcdefghi1234567890"));
3640    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 11, S("abcdefghi1234567890"));
3641    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, 0, S("abcdefghi"));
3642    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, 1, S("abcdefghi0"));
3643}
3644
3645template <class S>
3646void test34()
3647{
3648    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, 2, S("abcdefghi0"));
3649    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, 0, S("abcdefghi"));
3650    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, 1, S("abcdefghi"));
3651    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
3652    test(S("abcdefghij"), 9, 2, S(""), 0, 0, S("abcdefghi"));
3653    test(S("abcdefghij"), 9, 2, S(""), 0, 1, S("abcdefghi"));
3654    test(S("abcdefghij"), 9, 2, S(""), 1, 0, S("can't happen"));
3655    test(S("abcdefghij"), 9, 2, S("12345"), 0, 0, S("abcdefghi"));
3656    test(S("abcdefghij"), 9, 2, S("12345"), 0, 1, S("abcdefghi1"));
3657    test(S("abcdefghij"), 9, 2, S("12345"), 0, 2, S("abcdefghi12"));
3658    test(S("abcdefghij"), 9, 2, S("12345"), 0, 4, S("abcdefghi1234"));
3659    test(S("abcdefghij"), 9, 2, S("12345"), 0, 5, S("abcdefghi12345"));
3660    test(S("abcdefghij"), 9, 2, S("12345"), 0, 6, S("abcdefghi12345"));
3661    test(S("abcdefghij"), 9, 2, S("12345"), 1, 0, S("abcdefghi"));
3662    test(S("abcdefghij"), 9, 2, S("12345"), 1, 1, S("abcdefghi2"));
3663    test(S("abcdefghij"), 9, 2, S("12345"), 1, 2, S("abcdefghi23"));
3664    test(S("abcdefghij"), 9, 2, S("12345"), 1, 3, S("abcdefghi234"));
3665    test(S("abcdefghij"), 9, 2, S("12345"), 1, 4, S("abcdefghi2345"));
3666    test(S("abcdefghij"), 9, 2, S("12345"), 1, 5, S("abcdefghi2345"));
3667    test(S("abcdefghij"), 9, 2, S("12345"), 2, 0, S("abcdefghi"));
3668    test(S("abcdefghij"), 9, 2, S("12345"), 2, 1, S("abcdefghi3"));
3669    test(S("abcdefghij"), 9, 2, S("12345"), 2, 2, S("abcdefghi34"));
3670    test(S("abcdefghij"), 9, 2, S("12345"), 2, 3, S("abcdefghi345"));
3671    test(S("abcdefghij"), 9, 2, S("12345"), 2, 4, S("abcdefghi345"));
3672    test(S("abcdefghij"), 9, 2, S("12345"), 4, 0, S("abcdefghi"));
3673    test(S("abcdefghij"), 9, 2, S("12345"), 4, 1, S("abcdefghi5"));
3674    test(S("abcdefghij"), 9, 2, S("12345"), 4, 2, S("abcdefghi5"));
3675    test(S("abcdefghij"), 9, 2, S("12345"), 5, 0, S("abcdefghi"));
3676    test(S("abcdefghij"), 9, 2, S("12345"), 5, 1, S("abcdefghi"));
3677    test(S("abcdefghij"), 9, 2, S("12345"), 6, 0, S("can't happen"));
3678    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 0, S("abcdefghi"));
3679    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 1, S("abcdefghi1"));
3680    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 5, S("abcdefghi12345"));
3681    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 9, S("abcdefghi123456789"));
3682    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 10, S("abcdefghi1234567890"));
3683    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 11, S("abcdefghi1234567890"));
3684    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 0, S("abcdefghi"));
3685    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 1, S("abcdefghi2"));
3686    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 4, S("abcdefghi2345"));
3687    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 8, S("abcdefghi23456789"));
3688    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 9, S("abcdefghi234567890"));
3689    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 10, S("abcdefghi234567890"));
3690    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 0, S("abcdefghi"));
3691    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 1, S("abcdefghi6"));
3692    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 2, S("abcdefghi67"));
3693    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 4, S("abcdefghi6789"));
3694    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 5, S("abcdefghi67890"));
3695    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 6, S("abcdefghi67890"));
3696    test(S("abcdefghij"), 9, 2, S("1234567890"), 9, 0, S("abcdefghi"));
3697    test(S("abcdefghij"), 9, 2, S("1234567890"), 9, 1, S("abcdefghi0"));
3698    test(S("abcdefghij"), 9, 2, S("1234567890"), 9, 2, S("abcdefghi0"));
3699    test(S("abcdefghij"), 9, 2, S("1234567890"), 10, 0, S("abcdefghi"));
3700    test(S("abcdefghij"), 9, 2, S("1234567890"), 10, 1, S("abcdefghi"));
3701    test(S("abcdefghij"), 9, 2, S("1234567890"), 11, 0, S("can't happen"));
3702    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 0, S("abcdefghi"));
3703    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 1, S("abcdefghi1"));
3704    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 10, S("abcdefghi1234567890"));
3705    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789"));
3706    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890"));
3707    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890"));
3708    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 0, S("abcdefghi"));
3709    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 1, S("abcdefghi2"));
3710    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 9, S("abcdefghi234567890"));
3711    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789"));
3712    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890"));
3713    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890"));
3714    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 0, S("abcdefghi"));
3715    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 1, S("abcdefghi1"));
3716    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 5, S("abcdefghi12345"));
3717    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 9, S("abcdefghi123456789"));
3718    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 10, S("abcdefghi1234567890"));
3719    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 11, S("abcdefghi1234567890"));
3720    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 19, 0, S("abcdefghi"));
3721    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 19, 1, S("abcdefghi0"));
3722    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 19, 2, S("abcdefghi0"));
3723    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 20, 0, S("abcdefghi"));
3724    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 20, 1, S("abcdefghi"));
3725    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
3726    test(S("abcdefghij"), 10, 0, S(""), 0, 0, S("abcdefghij"));
3727    test(S("abcdefghij"), 10, 0, S(""), 0, 1, S("abcdefghij"));
3728    test(S("abcdefghij"), 10, 0, S(""), 1, 0, S("can't happen"));
3729    test(S("abcdefghij"), 10, 0, S("12345"), 0, 0, S("abcdefghij"));
3730    test(S("abcdefghij"), 10, 0, S("12345"), 0, 1, S("abcdefghij1"));
3731    test(S("abcdefghij"), 10, 0, S("12345"), 0, 2, S("abcdefghij12"));
3732    test(S("abcdefghij"), 10, 0, S("12345"), 0, 4, S("abcdefghij1234"));
3733    test(S("abcdefghij"), 10, 0, S("12345"), 0, 5, S("abcdefghij12345"));
3734    test(S("abcdefghij"), 10, 0, S("12345"), 0, 6, S("abcdefghij12345"));
3735    test(S("abcdefghij"), 10, 0, S("12345"), 1, 0, S("abcdefghij"));
3736    test(S("abcdefghij"), 10, 0, S("12345"), 1, 1, S("abcdefghij2"));
3737    test(S("abcdefghij"), 10, 0, S("12345"), 1, 2, S("abcdefghij23"));
3738    test(S("abcdefghij"), 10, 0, S("12345"), 1, 3, S("abcdefghij234"));
3739    test(S("abcdefghij"), 10, 0, S("12345"), 1, 4, S("abcdefghij2345"));
3740    test(S("abcdefghij"), 10, 0, S("12345"), 1, 5, S("abcdefghij2345"));
3741    test(S("abcdefghij"), 10, 0, S("12345"), 2, 0, S("abcdefghij"));
3742    test(S("abcdefghij"), 10, 0, S("12345"), 2, 1, S("abcdefghij3"));
3743    test(S("abcdefghij"), 10, 0, S("12345"), 2, 2, S("abcdefghij34"));
3744    test(S("abcdefghij"), 10, 0, S("12345"), 2, 3, S("abcdefghij345"));
3745    test(S("abcdefghij"), 10, 0, S("12345"), 2, 4, S("abcdefghij345"));
3746    test(S("abcdefghij"), 10, 0, S("12345"), 4, 0, S("abcdefghij"));
3747    test(S("abcdefghij"), 10, 0, S("12345"), 4, 1, S("abcdefghij5"));
3748}
3749
3750template <class S>
3751void test35()
3752{
3753    test(S("abcdefghij"), 10, 0, S("12345"), 4, 2, S("abcdefghij5"));
3754    test(S("abcdefghij"), 10, 0, S("12345"), 5, 0, S("abcdefghij"));
3755    test(S("abcdefghij"), 10, 0, S("12345"), 5, 1, S("abcdefghij"));
3756    test(S("abcdefghij"), 10, 0, S("12345"), 6, 0, S("can't happen"));
3757    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 0, S("abcdefghij"));
3758    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 1, S("abcdefghij1"));
3759    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 5, S("abcdefghij12345"));
3760    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 9, S("abcdefghij123456789"));
3761    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
3762    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
3763    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 0, S("abcdefghij"));
3764    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 1, S("abcdefghij2"));
3765    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 4, S("abcdefghij2345"));
3766    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 8, S("abcdefghij23456789"));
3767    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 9, S("abcdefghij234567890"));
3768    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 10, S("abcdefghij234567890"));
3769    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 0, S("abcdefghij"));
3770    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 1, S("abcdefghij6"));
3771    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 2, S("abcdefghij67"));
3772    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 4, S("abcdefghij6789"));
3773    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 5, S("abcdefghij67890"));
3774    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 6, S("abcdefghij67890"));
3775    test(S("abcdefghij"), 10, 0, S("1234567890"), 9, 0, S("abcdefghij"));
3776    test(S("abcdefghij"), 10, 0, S("1234567890"), 9, 1, S("abcdefghij0"));
3777    test(S("abcdefghij"), 10, 0, S("1234567890"), 9, 2, S("abcdefghij0"));
3778    test(S("abcdefghij"), 10, 0, S("1234567890"), 10, 0, S("abcdefghij"));
3779    test(S("abcdefghij"), 10, 0, S("1234567890"), 10, 1, S("abcdefghij"));
3780    test(S("abcdefghij"), 10, 0, S("1234567890"), 11, 0, S("can't happen"));
3781    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
3782    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
3783    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
3784    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
3785    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
3786    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
3787    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
3788    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
3789    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
3790    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
3791    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
3792    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
3793    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
3794    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
3795    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
3796    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
3797    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
3798    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
3799    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
3800    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
3801    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
3802    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
3803    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
3804    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
3805    test(S("abcdefghij"), 10, 1, S(""), 0, 0, S("abcdefghij"));
3806    test(S("abcdefghij"), 10, 1, S(""), 0, 1, S("abcdefghij"));
3807    test(S("abcdefghij"), 10, 1, S(""), 1, 0, S("can't happen"));
3808    test(S("abcdefghij"), 10, 1, S("12345"), 0, 0, S("abcdefghij"));
3809    test(S("abcdefghij"), 10, 1, S("12345"), 0, 1, S("abcdefghij1"));
3810    test(S("abcdefghij"), 10, 1, S("12345"), 0, 2, S("abcdefghij12"));
3811    test(S("abcdefghij"), 10, 1, S("12345"), 0, 4, S("abcdefghij1234"));
3812    test(S("abcdefghij"), 10, 1, S("12345"), 0, 5, S("abcdefghij12345"));
3813    test(S("abcdefghij"), 10, 1, S("12345"), 0, 6, S("abcdefghij12345"));
3814    test(S("abcdefghij"), 10, 1, S("12345"), 1, 0, S("abcdefghij"));
3815    test(S("abcdefghij"), 10, 1, S("12345"), 1, 1, S("abcdefghij2"));
3816    test(S("abcdefghij"), 10, 1, S("12345"), 1, 2, S("abcdefghij23"));
3817    test(S("abcdefghij"), 10, 1, S("12345"), 1, 3, S("abcdefghij234"));
3818    test(S("abcdefghij"), 10, 1, S("12345"), 1, 4, S("abcdefghij2345"));
3819    test(S("abcdefghij"), 10, 1, S("12345"), 1, 5, S("abcdefghij2345"));
3820    test(S("abcdefghij"), 10, 1, S("12345"), 2, 0, S("abcdefghij"));
3821    test(S("abcdefghij"), 10, 1, S("12345"), 2, 1, S("abcdefghij3"));
3822    test(S("abcdefghij"), 10, 1, S("12345"), 2, 2, S("abcdefghij34"));
3823    test(S("abcdefghij"), 10, 1, S("12345"), 2, 3, S("abcdefghij345"));
3824    test(S("abcdefghij"), 10, 1, S("12345"), 2, 4, S("abcdefghij345"));
3825    test(S("abcdefghij"), 10, 1, S("12345"), 4, 0, S("abcdefghij"));
3826    test(S("abcdefghij"), 10, 1, S("12345"), 4, 1, S("abcdefghij5"));
3827    test(S("abcdefghij"), 10, 1, S("12345"), 4, 2, S("abcdefghij5"));
3828    test(S("abcdefghij"), 10, 1, S("12345"), 5, 0, S("abcdefghij"));
3829    test(S("abcdefghij"), 10, 1, S("12345"), 5, 1, S("abcdefghij"));
3830    test(S("abcdefghij"), 10, 1, S("12345"), 6, 0, S("can't happen"));
3831    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 0, S("abcdefghij"));
3832    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 1, S("abcdefghij1"));
3833    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 5, S("abcdefghij12345"));
3834    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 9, S("abcdefghij123456789"));
3835    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
3836    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
3837    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 0, S("abcdefghij"));
3838    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 1, S("abcdefghij2"));
3839    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 4, S("abcdefghij2345"));
3840    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 8, S("abcdefghij23456789"));
3841    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 9, S("abcdefghij234567890"));
3842    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 10, S("abcdefghij234567890"));
3843    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 0, S("abcdefghij"));
3844    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 1, S("abcdefghij6"));
3845    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 2, S("abcdefghij67"));
3846    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 4, S("abcdefghij6789"));
3847    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 5, S("abcdefghij67890"));
3848    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 6, S("abcdefghij67890"));
3849    test(S("abcdefghij"), 10, 1, S("1234567890"), 9, 0, S("abcdefghij"));
3850    test(S("abcdefghij"), 10, 1, S("1234567890"), 9, 1, S("abcdefghij0"));
3851    test(S("abcdefghij"), 10, 1, S("1234567890"), 9, 2, S("abcdefghij0"));
3852    test(S("abcdefghij"), 10, 1, S("1234567890"), 10, 0, S("abcdefghij"));
3853}
3854
3855template <class S>
3856void test36()
3857{
3858    test(S("abcdefghij"), 10, 1, S("1234567890"), 10, 1, S("abcdefghij"));
3859    test(S("abcdefghij"), 10, 1, S("1234567890"), 11, 0, S("can't happen"));
3860    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 0, S("abcdefghij"));
3861    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
3862    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
3863    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
3864    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
3865    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
3866    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 0, S("abcdefghij"));
3867    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
3868    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
3869    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
3870    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
3871    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
3872    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 0, S("abcdefghij"));
3873    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
3874    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
3875    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
3876    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
3877    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
3878    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 19, 0, S("abcdefghij"));
3879    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
3880    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
3881    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 20, 0, S("abcdefghij"));
3882    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 20, 1, S("abcdefghij"));
3883    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
3884    test(S("abcdefghij"), 11, 0, S(""), 0, 0, S("can't happen"));
3885    test(S("abcdefghij"), 11, 0, S(""), 0, 1, S("can't happen"));
3886    test(S("abcdefghij"), 11, 0, S(""), 1, 0, S("can't happen"));
3887    test(S("abcdefghij"), 11, 0, S("12345"), 0, 0, S("can't happen"));
3888    test(S("abcdefghij"), 11, 0, S("12345"), 0, 1, S("can't happen"));
3889    test(S("abcdefghij"), 11, 0, S("12345"), 0, 2, S("can't happen"));
3890    test(S("abcdefghij"), 11, 0, S("12345"), 0, 4, S("can't happen"));
3891    test(S("abcdefghij"), 11, 0, S("12345"), 0, 5, S("can't happen"));
3892    test(S("abcdefghij"), 11, 0, S("12345"), 0, 6, S("can't happen"));
3893    test(S("abcdefghij"), 11, 0, S("12345"), 1, 0, S("can't happen"));
3894    test(S("abcdefghij"), 11, 0, S("12345"), 1, 1, S("can't happen"));
3895    test(S("abcdefghij"), 11, 0, S("12345"), 1, 2, S("can't happen"));
3896    test(S("abcdefghij"), 11, 0, S("12345"), 1, 3, S("can't happen"));
3897    test(S("abcdefghij"), 11, 0, S("12345"), 1, 4, S("can't happen"));
3898    test(S("abcdefghij"), 11, 0, S("12345"), 1, 5, S("can't happen"));
3899    test(S("abcdefghij"), 11, 0, S("12345"), 2, 0, S("can't happen"));
3900    test(S("abcdefghij"), 11, 0, S("12345"), 2, 1, S("can't happen"));
3901    test(S("abcdefghij"), 11, 0, S("12345"), 2, 2, S("can't happen"));
3902    test(S("abcdefghij"), 11, 0, S("12345"), 2, 3, S("can't happen"));
3903    test(S("abcdefghij"), 11, 0, S("12345"), 2, 4, S("can't happen"));
3904    test(S("abcdefghij"), 11, 0, S("12345"), 4, 0, S("can't happen"));
3905    test(S("abcdefghij"), 11, 0, S("12345"), 4, 1, S("can't happen"));
3906    test(S("abcdefghij"), 11, 0, S("12345"), 4, 2, S("can't happen"));
3907    test(S("abcdefghij"), 11, 0, S("12345"), 5, 0, S("can't happen"));
3908    test(S("abcdefghij"), 11, 0, S("12345"), 5, 1, S("can't happen"));
3909    test(S("abcdefghij"), 11, 0, S("12345"), 6, 0, S("can't happen"));
3910    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 0, S("can't happen"));
3911    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 1, S("can't happen"));
3912    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 5, S("can't happen"));
3913    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 9, S("can't happen"));
3914    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 10, S("can't happen"));
3915    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 11, S("can't happen"));
3916    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 0, S("can't happen"));
3917    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 1, S("can't happen"));
3918    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 4, S("can't happen"));
3919    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 8, S("can't happen"));
3920    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 9, S("can't happen"));
3921    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 10, S("can't happen"));
3922    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 0, S("can't happen"));
3923    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 1, S("can't happen"));
3924    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 2, S("can't happen"));
3925    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 4, S("can't happen"));
3926    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 5, S("can't happen"));
3927    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 6, S("can't happen"));
3928    test(S("abcdefghij"), 11, 0, S("1234567890"), 9, 0, S("can't happen"));
3929    test(S("abcdefghij"), 11, 0, S("1234567890"), 9, 1, S("can't happen"));
3930    test(S("abcdefghij"), 11, 0, S("1234567890"), 9, 2, S("can't happen"));
3931    test(S("abcdefghij"), 11, 0, S("1234567890"), 10, 0, S("can't happen"));
3932    test(S("abcdefghij"), 11, 0, S("1234567890"), 10, 1, S("can't happen"));
3933    test(S("abcdefghij"), 11, 0, S("1234567890"), 11, 0, S("can't happen"));
3934    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
3935    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
3936    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
3937    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
3938    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
3939    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
3940    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
3941    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
3942    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
3943    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
3944    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
3945    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
3946    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
3947    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
3948    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
3949    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
3950    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
3951    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
3952    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
3953    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
3954    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
3955    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
3956    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
3957    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
3958}
3959
3960template <class S>
3961void test37()
3962{
3963    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
3964    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
3965    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 1, 0, S("can't happen"));
3966    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
3967    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 1, S("1abcdefghijklmnopqrst"));
3968    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 2, S("12abcdefghijklmnopqrst"));
3969    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 4, S("1234abcdefghijklmnopqrst"));
3970    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 5, S("12345abcdefghijklmnopqrst"));
3971    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 6, S("12345abcdefghijklmnopqrst"));
3972    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
3973    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 1, S("2abcdefghijklmnopqrst"));
3974    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 2, S("23abcdefghijklmnopqrst"));
3975    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 3, S("234abcdefghijklmnopqrst"));
3976    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 4, S("2345abcdefghijklmnopqrst"));
3977    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 5, S("2345abcdefghijklmnopqrst"));
3978    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
3979    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 1, S("3abcdefghijklmnopqrst"));
3980    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 2, S("34abcdefghijklmnopqrst"));
3981    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 3, S("345abcdefghijklmnopqrst"));
3982    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 4, S("345abcdefghijklmnopqrst"));
3983    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
3984    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 4, 1, S("5abcdefghijklmnopqrst"));
3985    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 4, 2, S("5abcdefghijklmnopqrst"));
3986    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
3987    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
3988    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 6, 0, S("can't happen"));
3989    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
3990    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
3991    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 5, S("12345abcdefghijklmnopqrst"));
3992    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 9, S("123456789abcdefghijklmnopqrst"));
3993    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
3994    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 11, S("1234567890abcdefghijklmnopqrst"));
3995    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
3996    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
3997    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 4, S("2345abcdefghijklmnopqrst"));
3998    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 8, S("23456789abcdefghijklmnopqrst"));
3999    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
4000    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 10, S("234567890abcdefghijklmnopqrst"));
4001    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
4002    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 1, S("6abcdefghijklmnopqrst"));
4003    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 2, S("67abcdefghijklmnopqrst"));
4004    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 4, S("6789abcdefghijklmnopqrst"));
4005    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 5, S("67890abcdefghijklmnopqrst"));
4006    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 6, S("67890abcdefghijklmnopqrst"));
4007    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
4008    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 9, 1, S("0abcdefghijklmnopqrst"));
4009    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 9, 2, S("0abcdefghijklmnopqrst"));
4010    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4011    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
4012    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
4013    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4014    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
4015    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
4016    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghijklmnopqrst"));
4017    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghijklmnopqrst"));
4018    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghijklmnopqrst"));
4019    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4020    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
4021    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
4022    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcdefghijklmnopqrst"));
4023    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghijklmnopqrst"));
4024    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghijklmnopqrst"));
4025    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4026    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 1, S("1abcdefghijklmnopqrst"));
4027    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 5, S("12345abcdefghijklmnopqrst"));
4028    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 9, S("123456789abcdefghijklmnopqrst"));
4029    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890abcdefghijklmnopqrst"));
4030    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890abcdefghijklmnopqrst"));
4031    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
4032    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 19, 1, S("0abcdefghijklmnopqrst"));
4033    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 19, 2, S("0abcdefghijklmnopqrst"));
4034    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
4035    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
4036    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
4037    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 0, 0, S("bcdefghijklmnopqrst"));
4038    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 0, 1, S("bcdefghijklmnopqrst"));
4039    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 1, 0, S("can't happen"));
4040    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 0, S("bcdefghijklmnopqrst"));
4041    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 1, S("1bcdefghijklmnopqrst"));
4042    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 2, S("12bcdefghijklmnopqrst"));
4043    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 4, S("1234bcdefghijklmnopqrst"));
4044    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 5, S("12345bcdefghijklmnopqrst"));
4045    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 6, S("12345bcdefghijklmnopqrst"));
4046    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 0, S("bcdefghijklmnopqrst"));
4047    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 1, S("2bcdefghijklmnopqrst"));
4048    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 2, S("23bcdefghijklmnopqrst"));
4049    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 3, S("234bcdefghijklmnopqrst"));
4050    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 4, S("2345bcdefghijklmnopqrst"));
4051    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 5, S("2345bcdefghijklmnopqrst"));
4052    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 0, S("bcdefghijklmnopqrst"));
4053    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 1, S("3bcdefghijklmnopqrst"));
4054    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 2, S("34bcdefghijklmnopqrst"));
4055    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 3, S("345bcdefghijklmnopqrst"));
4056    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 4, S("345bcdefghijklmnopqrst"));
4057    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 4, 0, S("bcdefghijklmnopqrst"));
4058    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 4, 1, S("5bcdefghijklmnopqrst"));
4059    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 4, 2, S("5bcdefghijklmnopqrst"));
4060    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 5, 0, S("bcdefghijklmnopqrst"));
4061    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 5, 1, S("bcdefghijklmnopqrst"));
4062    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 6, 0, S("can't happen"));
4063}
4064
4065template <class S>
4066void test38()
4067{
4068    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 0, S("bcdefghijklmnopqrst"));
4069    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 1, S("1bcdefghijklmnopqrst"));
4070    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 5, S("12345bcdefghijklmnopqrst"));
4071    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 9, S("123456789bcdefghijklmnopqrst"));
4072    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 10, S("1234567890bcdefghijklmnopqrst"));
4073    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 11, S("1234567890bcdefghijklmnopqrst"));
4074    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 0, S("bcdefghijklmnopqrst"));
4075    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 1, S("2bcdefghijklmnopqrst"));
4076    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 4, S("2345bcdefghijklmnopqrst"));
4077    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 8, S("23456789bcdefghijklmnopqrst"));
4078    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 9, S("234567890bcdefghijklmnopqrst"));
4079    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 10, S("234567890bcdefghijklmnopqrst"));
4080    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 0, S("bcdefghijklmnopqrst"));
4081    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 1, S("6bcdefghijklmnopqrst"));
4082    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 2, S("67bcdefghijklmnopqrst"));
4083    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 4, S("6789bcdefghijklmnopqrst"));
4084    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 5, S("67890bcdefghijklmnopqrst"));
4085    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 6, S("67890bcdefghijklmnopqrst"));
4086    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 9, 0, S("bcdefghijklmnopqrst"));
4087    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 9, 1, S("0bcdefghijklmnopqrst"));
4088    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 9, 2, S("0bcdefghijklmnopqrst"));
4089    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 10, 0, S("bcdefghijklmnopqrst"));
4090    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 10, 1, S("bcdefghijklmnopqrst"));
4091    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
4092    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 0, S("bcdefghijklmnopqrst"));
4093    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 1, S("1bcdefghijklmnopqrst"));
4094    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890bcdefghijklmnopqrst"));
4095    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789bcdefghijklmnopqrst"));
4096    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890bcdefghijklmnopqrst"));
4097    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890bcdefghijklmnopqrst"));
4098    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 0, S("bcdefghijklmnopqrst"));
4099    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 1, S("2bcdefghijklmnopqrst"));
4100    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 9, S("234567890bcdefghijklmnopqrst"));
4101    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789bcdefghijklmnopqrst"));
4102    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890bcdefghijklmnopqrst"));
4103    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890bcdefghijklmnopqrst"));
4104    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 0, S("bcdefghijklmnopqrst"));
4105    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 1, S("1bcdefghijklmnopqrst"));
4106    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 5, S("12345bcdefghijklmnopqrst"));
4107    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 9, S("123456789bcdefghijklmnopqrst"));
4108    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890bcdefghijklmnopqrst"));
4109    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890bcdefghijklmnopqrst"));
4110    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 19, 0, S("bcdefghijklmnopqrst"));
4111    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 19, 1, S("0bcdefghijklmnopqrst"));
4112    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 19, 2, S("0bcdefghijklmnopqrst"));
4113    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 20, 0, S("bcdefghijklmnopqrst"));
4114    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 20, 1, S("bcdefghijklmnopqrst"));
4115    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
4116    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 0, 0, S("klmnopqrst"));
4117    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 0, 1, S("klmnopqrst"));
4118    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 1, 0, S("can't happen"));
4119    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 0, S("klmnopqrst"));
4120    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 1, S("1klmnopqrst"));
4121    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 2, S("12klmnopqrst"));
4122    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 4, S("1234klmnopqrst"));
4123    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 5, S("12345klmnopqrst"));
4124    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 6, S("12345klmnopqrst"));
4125    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 0, S("klmnopqrst"));
4126    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 1, S("2klmnopqrst"));
4127    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 2, S("23klmnopqrst"));
4128    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 3, S("234klmnopqrst"));
4129    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 4, S("2345klmnopqrst"));
4130    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 5, S("2345klmnopqrst"));
4131    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 0, S("klmnopqrst"));
4132    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 1, S("3klmnopqrst"));
4133    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 2, S("34klmnopqrst"));
4134    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 3, S("345klmnopqrst"));
4135    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 4, S("345klmnopqrst"));
4136    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 4, 0, S("klmnopqrst"));
4137    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 4, 1, S("5klmnopqrst"));
4138    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 4, 2, S("5klmnopqrst"));
4139    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 5, 0, S("klmnopqrst"));
4140    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 5, 1, S("klmnopqrst"));
4141    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 6, 0, S("can't happen"));
4142    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 0, S("klmnopqrst"));
4143    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 1, S("1klmnopqrst"));
4144    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 5, S("12345klmnopqrst"));
4145    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 9, S("123456789klmnopqrst"));
4146    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 10, S("1234567890klmnopqrst"));
4147    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 11, S("1234567890klmnopqrst"));
4148    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 0, S("klmnopqrst"));
4149    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 1, S("2klmnopqrst"));
4150    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 4, S("2345klmnopqrst"));
4151    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 8, S("23456789klmnopqrst"));
4152    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 9, S("234567890klmnopqrst"));
4153    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 10, S("234567890klmnopqrst"));
4154    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 0, S("klmnopqrst"));
4155    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 1, S("6klmnopqrst"));
4156    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 2, S("67klmnopqrst"));
4157    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 4, S("6789klmnopqrst"));
4158    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 5, S("67890klmnopqrst"));
4159    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 6, S("67890klmnopqrst"));
4160    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 9, 0, S("klmnopqrst"));
4161    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 9, 1, S("0klmnopqrst"));
4162    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 9, 2, S("0klmnopqrst"));
4163    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 10, 0, S("klmnopqrst"));
4164    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 10, 1, S("klmnopqrst"));
4165    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 11, 0, S("can't happen"));
4166    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 0, S("klmnopqrst"));
4167    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 1, S("1klmnopqrst"));
4168}
4169
4170template <class S>
4171void test39()
4172{
4173    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 10, S("1234567890klmnopqrst"));
4174    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 19, S("1234567890123456789klmnopqrst"));
4175    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 20, S("12345678901234567890klmnopqrst"));
4176    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 21, S("12345678901234567890klmnopqrst"));
4177    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 0, S("klmnopqrst"));
4178    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 1, S("2klmnopqrst"));
4179    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 9, S("234567890klmnopqrst"));
4180    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 18, S("234567890123456789klmnopqrst"));
4181    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 19, S("2345678901234567890klmnopqrst"));
4182    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 20, S("2345678901234567890klmnopqrst"));
4183    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 0, S("klmnopqrst"));
4184    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 1, S("1klmnopqrst"));
4185    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 5, S("12345klmnopqrst"));
4186    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 9, S("123456789klmnopqrst"));
4187    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 10, S("1234567890klmnopqrst"));
4188    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 11, S("1234567890klmnopqrst"));
4189    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 19, 0, S("klmnopqrst"));
4190    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 19, 1, S("0klmnopqrst"));
4191    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 19, 2, S("0klmnopqrst"));
4192    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 20, 0, S("klmnopqrst"));
4193    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 20, 1, S("klmnopqrst"));
4194    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
4195    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 0, 0, S("t"));
4196    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 0, 1, S("t"));
4197    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 1, 0, S("can't happen"));
4198    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 0, S("t"));
4199    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 1, S("1t"));
4200    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 2, S("12t"));
4201    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 4, S("1234t"));
4202    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 5, S("12345t"));
4203    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 6, S("12345t"));
4204    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 0, S("t"));
4205    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 1, S("2t"));
4206    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 2, S("23t"));
4207    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 3, S("234t"));
4208    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 4, S("2345t"));
4209    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 5, S("2345t"));
4210    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 0, S("t"));
4211    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 1, S("3t"));
4212    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 2, S("34t"));
4213    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 3, S("345t"));
4214    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 4, S("345t"));
4215    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 4, 0, S("t"));
4216    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 4, 1, S("5t"));
4217    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 4, 2, S("5t"));
4218    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 5, 0, S("t"));
4219    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 5, 1, S("t"));
4220    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 6, 0, S("can't happen"));
4221    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 0, S("t"));
4222    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 1, S("1t"));
4223    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 5, S("12345t"));
4224    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 9, S("123456789t"));
4225    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 10, S("1234567890t"));
4226    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 11, S("1234567890t"));
4227    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 0, S("t"));
4228    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 1, S("2t"));
4229    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 4, S("2345t"));
4230    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 8, S("23456789t"));
4231    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 9, S("234567890t"));
4232    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 10, S("234567890t"));
4233    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 0, S("t"));
4234    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 1, S("6t"));
4235    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 2, S("67t"));
4236    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 4, S("6789t"));
4237    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 5, S("67890t"));
4238    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 6, S("67890t"));
4239    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 9, 0, S("t"));
4240    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 9, 1, S("0t"));
4241    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 9, 2, S("0t"));
4242    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 10, 0, S("t"));
4243    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 10, 1, S("t"));
4244    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 11, 0, S("can't happen"));
4245    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 0, S("t"));
4246    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 1, S("1t"));
4247    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 10, S("1234567890t"));
4248    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 19, S("1234567890123456789t"));
4249    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 20, S("12345678901234567890t"));
4250    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 21, S("12345678901234567890t"));
4251    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 0, S("t"));
4252    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 1, S("2t"));
4253    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 9, S("234567890t"));
4254    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 18, S("234567890123456789t"));
4255    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 19, S("2345678901234567890t"));
4256    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 20, S("2345678901234567890t"));
4257    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 0, S("t"));
4258    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 1, S("1t"));
4259    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 5, S("12345t"));
4260    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 9, S("123456789t"));
4261    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 10, S("1234567890t"));
4262    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 11, S("1234567890t"));
4263    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 19, 0, S("t"));
4264    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 19, 1, S("0t"));
4265    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 19, 2, S("0t"));
4266    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 20, 0, S("t"));
4267    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 20, 1, S("t"));
4268    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 21, 0, S("can't happen"));
4269    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 0, 0, S(""));
4270    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 0, 1, S(""));
4271    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 1, 0, S("can't happen"));
4272    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 0, S(""));
4273}
4274
4275template <class S>
4276void test40()
4277{
4278    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 1, S("1"));
4279    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 2, S("12"));
4280    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 4, S("1234"));
4281    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 5, S("12345"));
4282    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 6, S("12345"));
4283    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 0, S(""));
4284    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 1, S("2"));
4285    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 2, S("23"));
4286    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 3, S("234"));
4287    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 4, S("2345"));
4288    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 5, S("2345"));
4289    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 0, S(""));
4290    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 1, S("3"));
4291    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 2, S("34"));
4292    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 3, S("345"));
4293    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 4, S("345"));
4294    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 4, 0, S(""));
4295    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 4, 1, S("5"));
4296    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 4, 2, S("5"));
4297    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 5, 0, S(""));
4298    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 5, 1, S(""));
4299    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 6, 0, S("can't happen"));
4300    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 0, S(""));
4301    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 1, S("1"));
4302    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 5, S("12345"));
4303    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 9, S("123456789"));
4304    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 10, S("1234567890"));
4305    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 11, S("1234567890"));
4306    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 0, S(""));
4307    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 1, S("2"));
4308    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 4, S("2345"));
4309    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 8, S("23456789"));
4310    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 9, S("234567890"));
4311    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 10, S("234567890"));
4312    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 0, S(""));
4313    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 1, S("6"));
4314    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 2, S("67"));
4315    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 4, S("6789"));
4316    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 5, S("67890"));
4317    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 6, S("67890"));
4318    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 9, 0, S(""));
4319    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 9, 1, S("0"));
4320    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 9, 2, S("0"));
4321    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 10, 0, S(""));
4322    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 10, 1, S(""));
4323    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 11, 0, S("can't happen"));
4324    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 0, S(""));
4325    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 1, S("1"));
4326    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 10, S("1234567890"));
4327    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
4328    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
4329    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
4330    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 0, S(""));
4331    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 1, S("2"));
4332    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 9, S("234567890"));
4333    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 18, S("234567890123456789"));
4334    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
4335    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
4336    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 0, S(""));
4337    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 1, S("1"));
4338    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 5, S("12345"));
4339    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 9, S("123456789"));
4340    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 10, S("1234567890"));
4341    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 11, S("1234567890"));
4342    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 19, 0, S(""));
4343    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 19, 1, S("0"));
4344    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 19, 2, S("0"));
4345    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 20, 0, S(""));
4346    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 20, 1, S(""));
4347    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 21, 0, S("can't happen"));
4348    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 0, 0, S(""));
4349    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 0, 1, S(""));
4350    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 1, 0, S("can't happen"));
4351    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 0, S(""));
4352    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 1, S("1"));
4353    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 2, S("12"));
4354    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 4, S("1234"));
4355    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 5, S("12345"));
4356    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 6, S("12345"));
4357    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 0, S(""));
4358    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 1, S("2"));
4359    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 2, S("23"));
4360    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 3, S("234"));
4361    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 4, S("2345"));
4362    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 5, S("2345"));
4363    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 0, S(""));
4364    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 1, S("3"));
4365    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 2, S("34"));
4366    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 3, S("345"));
4367    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 4, S("345"));
4368    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 4, 0, S(""));
4369    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 4, 1, S("5"));
4370    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 4, 2, S("5"));
4371    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 5, 0, S(""));
4372    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 5, 1, S(""));
4373    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 6, 0, S("can't happen"));
4374    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 0, S(""));
4375    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 1, S("1"));
4376    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 5, S("12345"));
4377    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 9, S("123456789"));
4378}
4379
4380template <class S>
4381void test41()
4382{
4383    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 10, S("1234567890"));
4384    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 11, S("1234567890"));
4385    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 0, S(""));
4386    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 1, S("2"));
4387    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 4, S("2345"));
4388    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 8, S("23456789"));
4389    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 9, S("234567890"));
4390    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 10, S("234567890"));
4391    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 0, S(""));
4392    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 1, S("6"));
4393    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 2, S("67"));
4394    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 4, S("6789"));
4395    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 5, S("67890"));
4396    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 6, S("67890"));
4397    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 9, 0, S(""));
4398    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 9, 1, S("0"));
4399    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 9, 2, S("0"));
4400    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 10, 0, S(""));
4401    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 10, 1, S(""));
4402    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 11, 0, S("can't happen"));
4403    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 0, S(""));
4404    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 1, S("1"));
4405    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 10, S("1234567890"));
4406    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
4407    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
4408    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
4409    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 0, S(""));
4410    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 1, S("2"));
4411    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 9, S("234567890"));
4412    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 18, S("234567890123456789"));
4413    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
4414    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
4415    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 0, S(""));
4416    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 1, S("1"));
4417    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 5, S("12345"));
4418    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 9, S("123456789"));
4419    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 10, S("1234567890"));
4420    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 11, S("1234567890"));
4421    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 19, 0, S(""));
4422    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 19, 1, S("0"));
4423    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 19, 2, S("0"));
4424    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 20, 0, S(""));
4425    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 20, 1, S(""));
4426    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 21, 0, S("can't happen"));
4427    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
4428    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
4429    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 1, 0, S("can't happen"));
4430    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
4431    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 1, S("a1bcdefghijklmnopqrst"));
4432    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 2, S("a12bcdefghijklmnopqrst"));
4433    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 4, S("a1234bcdefghijklmnopqrst"));
4434    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 5, S("a12345bcdefghijklmnopqrst"));
4435    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 6, S("a12345bcdefghijklmnopqrst"));
4436    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
4437    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 1, S("a2bcdefghijklmnopqrst"));
4438    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 2, S("a23bcdefghijklmnopqrst"));
4439    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 3, S("a234bcdefghijklmnopqrst"));
4440    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 4, S("a2345bcdefghijklmnopqrst"));
4441    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 5, S("a2345bcdefghijklmnopqrst"));
4442    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
4443    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 1, S("a3bcdefghijklmnopqrst"));
4444    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 2, S("a34bcdefghijklmnopqrst"));
4445    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 3, S("a345bcdefghijklmnopqrst"));
4446    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 4, S("a345bcdefghijklmnopqrst"));
4447    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
4448    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 4, 1, S("a5bcdefghijklmnopqrst"));
4449    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 4, 2, S("a5bcdefghijklmnopqrst"));
4450    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
4451    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
4452    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 6, 0, S("can't happen"));
4453    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4454    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
4455    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 5, S("a12345bcdefghijklmnopqrst"));
4456    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 9, S("a123456789bcdefghijklmnopqrst"));
4457    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
4458    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 11, S("a1234567890bcdefghijklmnopqrst"));
4459    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4460    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
4461    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 4, S("a2345bcdefghijklmnopqrst"));
4462    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 8, S("a23456789bcdefghijklmnopqrst"));
4463    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
4464    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 10, S("a234567890bcdefghijklmnopqrst"));
4465    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
4466    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 1, S("a6bcdefghijklmnopqrst"));
4467    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 2, S("a67bcdefghijklmnopqrst"));
4468    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 4, S("a6789bcdefghijklmnopqrst"));
4469    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 5, S("a67890bcdefghijklmnopqrst"));
4470    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 6, S("a67890bcdefghijklmnopqrst"));
4471    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
4472    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 9, 1, S("a0bcdefghijklmnopqrst"));
4473    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 9, 2, S("a0bcdefghijklmnopqrst"));
4474    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4475    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
4476    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
4477    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4478    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
4479    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
4480    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghijklmnopqrst"));
4481    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghijklmnopqrst"));
4482    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghijklmnopqrst"));
4483}
4484
4485template <class S>
4486void test42()
4487{
4488    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4489    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
4490    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
4491    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghijklmnopqrst"));
4492    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghijklmnopqrst"));
4493    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghijklmnopqrst"));
4494    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4495    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 1, S("a1bcdefghijklmnopqrst"));
4496    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 5, S("a12345bcdefghijklmnopqrst"));
4497    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 9, S("a123456789bcdefghijklmnopqrst"));
4498    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 10, S("a1234567890bcdefghijklmnopqrst"));
4499    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 11, S("a1234567890bcdefghijklmnopqrst"));
4500    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
4501    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 19, 1, S("a0bcdefghijklmnopqrst"));
4502    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 19, 2, S("a0bcdefghijklmnopqrst"));
4503    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
4504    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
4505    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
4506    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 0, 0, S("acdefghijklmnopqrst"));
4507    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 0, 1, S("acdefghijklmnopqrst"));
4508    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 1, 0, S("can't happen"));
4509    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 0, S("acdefghijklmnopqrst"));
4510    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 1, S("a1cdefghijklmnopqrst"));
4511    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 2, S("a12cdefghijklmnopqrst"));
4512    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 4, S("a1234cdefghijklmnopqrst"));
4513    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 5, S("a12345cdefghijklmnopqrst"));
4514    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 6, S("a12345cdefghijklmnopqrst"));
4515    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 0, S("acdefghijklmnopqrst"));
4516    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 1, S("a2cdefghijklmnopqrst"));
4517    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 2, S("a23cdefghijklmnopqrst"));
4518    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 3, S("a234cdefghijklmnopqrst"));
4519    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 4, S("a2345cdefghijklmnopqrst"));
4520    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 5, S("a2345cdefghijklmnopqrst"));
4521    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 0, S("acdefghijklmnopqrst"));
4522    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 1, S("a3cdefghijklmnopqrst"));
4523    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 2, S("a34cdefghijklmnopqrst"));
4524    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 3, S("a345cdefghijklmnopqrst"));
4525    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 4, S("a345cdefghijklmnopqrst"));
4526    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 4, 0, S("acdefghijklmnopqrst"));
4527    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 4, 1, S("a5cdefghijklmnopqrst"));
4528    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 4, 2, S("a5cdefghijklmnopqrst"));
4529    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 5, 0, S("acdefghijklmnopqrst"));
4530    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 5, 1, S("acdefghijklmnopqrst"));
4531    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 6, 0, S("can't happen"));
4532    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 0, S("acdefghijklmnopqrst"));
4533    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 1, S("a1cdefghijklmnopqrst"));
4534    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 5, S("a12345cdefghijklmnopqrst"));
4535    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 9, S("a123456789cdefghijklmnopqrst"));
4536    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 10, S("a1234567890cdefghijklmnopqrst"));
4537    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 11, S("a1234567890cdefghijklmnopqrst"));
4538    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 0, S("acdefghijklmnopqrst"));
4539    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 1, S("a2cdefghijklmnopqrst"));
4540    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 4, S("a2345cdefghijklmnopqrst"));
4541    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 8, S("a23456789cdefghijklmnopqrst"));
4542    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 9, S("a234567890cdefghijklmnopqrst"));
4543    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 10, S("a234567890cdefghijklmnopqrst"));
4544    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 0, S("acdefghijklmnopqrst"));
4545    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 1, S("a6cdefghijklmnopqrst"));
4546    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 2, S("a67cdefghijklmnopqrst"));
4547    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 4, S("a6789cdefghijklmnopqrst"));
4548    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 5, S("a67890cdefghijklmnopqrst"));
4549    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 6, S("a67890cdefghijklmnopqrst"));
4550    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 9, 0, S("acdefghijklmnopqrst"));
4551    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 9, 1, S("a0cdefghijklmnopqrst"));
4552    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 9, 2, S("a0cdefghijklmnopqrst"));
4553    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 10, 0, S("acdefghijklmnopqrst"));
4554    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 10, 1, S("acdefghijklmnopqrst"));
4555    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 11, 0, S("can't happen"));
4556    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 0, S("acdefghijklmnopqrst"));
4557    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 1, S("a1cdefghijklmnopqrst"));
4558    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 10, S("a1234567890cdefghijklmnopqrst"));
4559    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789cdefghijklmnopqrst"));
4560    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890cdefghijklmnopqrst"));
4561    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890cdefghijklmnopqrst"));
4562    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 0, S("acdefghijklmnopqrst"));
4563    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 1, S("a2cdefghijklmnopqrst"));
4564    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 9, S("a234567890cdefghijklmnopqrst"));
4565    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 18, S("a234567890123456789cdefghijklmnopqrst"));
4566    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890cdefghijklmnopqrst"));
4567    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890cdefghijklmnopqrst"));
4568    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 0, S("acdefghijklmnopqrst"));
4569    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 1, S("a1cdefghijklmnopqrst"));
4570    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 5, S("a12345cdefghijklmnopqrst"));
4571    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 9, S("a123456789cdefghijklmnopqrst"));
4572    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 10, S("a1234567890cdefghijklmnopqrst"));
4573    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 11, S("a1234567890cdefghijklmnopqrst"));
4574    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 19, 0, S("acdefghijklmnopqrst"));
4575    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 19, 1, S("a0cdefghijklmnopqrst"));
4576    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 19, 2, S("a0cdefghijklmnopqrst"));
4577    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 20, 0, S("acdefghijklmnopqrst"));
4578    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 20, 1, S("acdefghijklmnopqrst"));
4579    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
4580    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 0, 0, S("aklmnopqrst"));
4581    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 0, 1, S("aklmnopqrst"));
4582    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 1, 0, S("can't happen"));
4583    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 0, S("aklmnopqrst"));
4584    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 1, S("a1klmnopqrst"));
4585    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 2, S("a12klmnopqrst"));
4586    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 4, S("a1234klmnopqrst"));
4587    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 5, S("a12345klmnopqrst"));
4588}
4589
4590template <class S>
4591void test43()
4592{
4593    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 6, S("a12345klmnopqrst"));
4594    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 0, S("aklmnopqrst"));
4595    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 1, S("a2klmnopqrst"));
4596    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 2, S("a23klmnopqrst"));
4597    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 3, S("a234klmnopqrst"));
4598    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 4, S("a2345klmnopqrst"));
4599    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 5, S("a2345klmnopqrst"));
4600    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 0, S("aklmnopqrst"));
4601    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 1, S("a3klmnopqrst"));
4602    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 2, S("a34klmnopqrst"));
4603    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 3, S("a345klmnopqrst"));
4604    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 4, S("a345klmnopqrst"));
4605    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 4, 0, S("aklmnopqrst"));
4606    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 4, 1, S("a5klmnopqrst"));
4607    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 4, 2, S("a5klmnopqrst"));
4608    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 5, 0, S("aklmnopqrst"));
4609    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 5, 1, S("aklmnopqrst"));
4610    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 6, 0, S("can't happen"));
4611    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 0, S("aklmnopqrst"));
4612    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 1, S("a1klmnopqrst"));
4613    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 5, S("a12345klmnopqrst"));
4614    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 9, S("a123456789klmnopqrst"));
4615    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 10, S("a1234567890klmnopqrst"));
4616    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 11, S("a1234567890klmnopqrst"));
4617    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 0, S("aklmnopqrst"));
4618    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 1, S("a2klmnopqrst"));
4619    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 4, S("a2345klmnopqrst"));
4620    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 8, S("a23456789klmnopqrst"));
4621    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 9, S("a234567890klmnopqrst"));
4622    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 10, S("a234567890klmnopqrst"));
4623    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 0, S("aklmnopqrst"));
4624    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 1, S("a6klmnopqrst"));
4625    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 2, S("a67klmnopqrst"));
4626    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 4, S("a6789klmnopqrst"));
4627    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 5, S("a67890klmnopqrst"));
4628    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 6, S("a67890klmnopqrst"));
4629    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 9, 0, S("aklmnopqrst"));
4630    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 9, 1, S("a0klmnopqrst"));
4631    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 9, 2, S("a0klmnopqrst"));
4632    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 10, 0, S("aklmnopqrst"));
4633    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 10, 1, S("aklmnopqrst"));
4634    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 11, 0, S("can't happen"));
4635    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 0, S("aklmnopqrst"));
4636    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 1, S("a1klmnopqrst"));
4637    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 10, S("a1234567890klmnopqrst"));
4638    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 19, S("a1234567890123456789klmnopqrst"));
4639    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 20, S("a12345678901234567890klmnopqrst"));
4640    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 21, S("a12345678901234567890klmnopqrst"));
4641    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 0, S("aklmnopqrst"));
4642    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 1, S("a2klmnopqrst"));
4643    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 9, S("a234567890klmnopqrst"));
4644    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 18, S("a234567890123456789klmnopqrst"));
4645    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 19, S("a2345678901234567890klmnopqrst"));
4646    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 20, S("a2345678901234567890klmnopqrst"));
4647    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 0, S("aklmnopqrst"));
4648    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 1, S("a1klmnopqrst"));
4649    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 5, S("a12345klmnopqrst"));
4650    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 9, S("a123456789klmnopqrst"));
4651    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 10, S("a1234567890klmnopqrst"));
4652    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 11, S("a1234567890klmnopqrst"));
4653    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 19, 0, S("aklmnopqrst"));
4654    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 19, 1, S("a0klmnopqrst"));
4655    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 19, 2, S("a0klmnopqrst"));
4656    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 20, 0, S("aklmnopqrst"));
4657    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 20, 1, S("aklmnopqrst"));
4658    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
4659    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 0, 0, S("at"));
4660    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 0, 1, S("at"));
4661    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 1, 0, S("can't happen"));
4662    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 0, S("at"));
4663    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 1, S("a1t"));
4664    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 2, S("a12t"));
4665    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 4, S("a1234t"));
4666    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 5, S("a12345t"));
4667    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 6, S("a12345t"));
4668    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 0, S("at"));
4669    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 1, S("a2t"));
4670    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 2, S("a23t"));
4671    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 3, S("a234t"));
4672    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 4, S("a2345t"));
4673    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 5, S("a2345t"));
4674    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 0, S("at"));
4675    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 1, S("a3t"));
4676    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 2, S("a34t"));
4677    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 3, S("a345t"));
4678    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 4, S("a345t"));
4679    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 4, 0, S("at"));
4680    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 4, 1, S("a5t"));
4681    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 4, 2, S("a5t"));
4682    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 5, 0, S("at"));
4683    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 5, 1, S("at"));
4684    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 6, 0, S("can't happen"));
4685    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 0, S("at"));
4686    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 1, S("a1t"));
4687    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 5, S("a12345t"));
4688    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 9, S("a123456789t"));
4689    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 10, S("a1234567890t"));
4690    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 11, S("a1234567890t"));
4691    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 0, S("at"));
4692    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 1, S("a2t"));
4693}
4694
4695template <class S>
4696void test44()
4697{
4698    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 4, S("a2345t"));
4699    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 8, S("a23456789t"));
4700    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 9, S("a234567890t"));
4701    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 10, S("a234567890t"));
4702    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 0, S("at"));
4703    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 1, S("a6t"));
4704    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 2, S("a67t"));
4705    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 4, S("a6789t"));
4706    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 5, S("a67890t"));
4707    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 6, S("a67890t"));
4708    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 9, 0, S("at"));
4709    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 9, 1, S("a0t"));
4710    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 9, 2, S("a0t"));
4711    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 10, 0, S("at"));
4712    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 10, 1, S("at"));
4713    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 11, 0, S("can't happen"));
4714    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 0, S("at"));
4715    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 1, S("a1t"));
4716    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 10, S("a1234567890t"));
4717    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 19, S("a1234567890123456789t"));
4718    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 20, S("a12345678901234567890t"));
4719    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 21, S("a12345678901234567890t"));
4720    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 0, S("at"));
4721    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 1, S("a2t"));
4722    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 9, S("a234567890t"));
4723    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 18, S("a234567890123456789t"));
4724    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 19, S("a2345678901234567890t"));
4725    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 20, S("a2345678901234567890t"));
4726    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 0, S("at"));
4727    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 1, S("a1t"));
4728    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 5, S("a12345t"));
4729    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 9, S("a123456789t"));
4730    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 10, S("a1234567890t"));
4731    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 11, S("a1234567890t"));
4732    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 19, 0, S("at"));
4733    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 19, 1, S("a0t"));
4734    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 19, 2, S("a0t"));
4735    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 20, 0, S("at"));
4736    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 20, 1, S("at"));
4737    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 21, 0, S("can't happen"));
4738    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 0, 0, S("a"));
4739    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 0, 1, S("a"));
4740    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 1, 0, S("can't happen"));
4741    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 0, S("a"));
4742    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 1, S("a1"));
4743    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 2, S("a12"));
4744    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 4, S("a1234"));
4745    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 5, S("a12345"));
4746    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 6, S("a12345"));
4747    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 0, S("a"));
4748    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 1, S("a2"));
4749    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 2, S("a23"));
4750    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 3, S("a234"));
4751    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 4, S("a2345"));
4752    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 5, S("a2345"));
4753    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 0, S("a"));
4754    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 1, S("a3"));
4755    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 2, S("a34"));
4756    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 3, S("a345"));
4757    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 4, S("a345"));
4758    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 4, 0, S("a"));
4759    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 4, 1, S("a5"));
4760    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 4, 2, S("a5"));
4761    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 5, 0, S("a"));
4762    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 5, 1, S("a"));
4763    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 6, 0, S("can't happen"));
4764    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 0, S("a"));
4765    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 1, S("a1"));
4766    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 5, S("a12345"));
4767    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 9, S("a123456789"));
4768    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 10, S("a1234567890"));
4769    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 11, S("a1234567890"));
4770    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 0, S("a"));
4771    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 1, S("a2"));
4772    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 4, S("a2345"));
4773    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 8, S("a23456789"));
4774    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 9, S("a234567890"));
4775    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 10, S("a234567890"));
4776    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 0, S("a"));
4777    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 1, S("a6"));
4778    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 2, S("a67"));
4779    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 4, S("a6789"));
4780    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 5, S("a67890"));
4781    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 6, S("a67890"));
4782    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 9, 0, S("a"));
4783    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 9, 1, S("a0"));
4784    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 9, 2, S("a0"));
4785    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 10, 0, S("a"));
4786    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 10, 1, S("a"));
4787    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 11, 0, S("can't happen"));
4788    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 0, S("a"));
4789    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 1, S("a1"));
4790    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 10, S("a1234567890"));
4791    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
4792    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
4793    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
4794    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 0, S("a"));
4795    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 1, S("a2"));
4796    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 9, S("a234567890"));
4797    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
4798}
4799
4800template <class S>
4801void test45()
4802{
4803    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
4804    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
4805    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 0, S("a"));
4806    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 1, S("a1"));
4807    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 5, S("a12345"));
4808    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 9, S("a123456789"));
4809    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 10, S("a1234567890"));
4810    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 11, S("a1234567890"));
4811    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 19, 0, S("a"));
4812    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 19, 1, S("a0"));
4813    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 19, 2, S("a0"));
4814    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 20, 0, S("a"));
4815    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 20, 1, S("a"));
4816    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 21, 0, S("can't happen"));
4817    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 0, 0, S("a"));
4818    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 0, 1, S("a"));
4819    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 1, 0, S("can't happen"));
4820    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 0, S("a"));
4821    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 1, S("a1"));
4822    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 2, S("a12"));
4823    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 4, S("a1234"));
4824    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 5, S("a12345"));
4825    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 6, S("a12345"));
4826    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 0, S("a"));
4827    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 1, S("a2"));
4828    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 2, S("a23"));
4829    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 3, S("a234"));
4830    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 4, S("a2345"));
4831    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 5, S("a2345"));
4832    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 0, S("a"));
4833    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 1, S("a3"));
4834    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 2, S("a34"));
4835    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 3, S("a345"));
4836    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 4, S("a345"));
4837    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 4, 0, S("a"));
4838    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 4, 1, S("a5"));
4839    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 4, 2, S("a5"));
4840    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 5, 0, S("a"));
4841    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 5, 1, S("a"));
4842    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 6, 0, S("can't happen"));
4843    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 0, S("a"));
4844    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 1, S("a1"));
4845    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 5, S("a12345"));
4846    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 9, S("a123456789"));
4847    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 10, S("a1234567890"));
4848    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 11, S("a1234567890"));
4849    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 0, S("a"));
4850    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 1, S("a2"));
4851    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 4, S("a2345"));
4852    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 8, S("a23456789"));
4853    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 9, S("a234567890"));
4854    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 10, S("a234567890"));
4855    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 0, S("a"));
4856    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 1, S("a6"));
4857    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 2, S("a67"));
4858    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 4, S("a6789"));
4859    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 5, S("a67890"));
4860    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 6, S("a67890"));
4861    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 9, 0, S("a"));
4862    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 9, 1, S("a0"));
4863    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 9, 2, S("a0"));
4864    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 10, 0, S("a"));
4865    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 10, 1, S("a"));
4866    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 11, 0, S("can't happen"));
4867    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 0, S("a"));
4868    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 1, S("a1"));
4869    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 10, S("a1234567890"));
4870    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
4871    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
4872    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
4873    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 0, S("a"));
4874    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 1, S("a2"));
4875    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 9, S("a234567890"));
4876    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
4877    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
4878    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
4879    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 0, S("a"));
4880    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 1, S("a1"));
4881    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 5, S("a12345"));
4882    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 9, S("a123456789"));
4883    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 10, S("a1234567890"));
4884    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 11, S("a1234567890"));
4885    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 19, 0, S("a"));
4886    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 19, 1, S("a0"));
4887    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 19, 2, S("a0"));
4888    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 20, 0, S("a"));
4889    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 20, 1, S("a"));
4890    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 21, 0, S("can't happen"));
4891    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
4892    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
4893    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 1, 0, S("can't happen"));
4894    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
4895    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 1, S("abcdefghij1klmnopqrst"));
4896    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 2, S("abcdefghij12klmnopqrst"));
4897    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 4, S("abcdefghij1234klmnopqrst"));
4898    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 5, S("abcdefghij12345klmnopqrst"));
4899    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 6, S("abcdefghij12345klmnopqrst"));
4900    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
4901    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 1, S("abcdefghij2klmnopqrst"));
4902    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 2, S("abcdefghij23klmnopqrst"));
4903}
4904
4905template <class S>
4906void test46()
4907{
4908    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 3, S("abcdefghij234klmnopqrst"));
4909    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 4, S("abcdefghij2345klmnopqrst"));
4910    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 5, S("abcdefghij2345klmnopqrst"));
4911    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
4912    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 1, S("abcdefghij3klmnopqrst"));
4913    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 2, S("abcdefghij34klmnopqrst"));
4914    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 3, S("abcdefghij345klmnopqrst"));
4915    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 4, S("abcdefghij345klmnopqrst"));
4916    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
4917    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 4, 1, S("abcdefghij5klmnopqrst"));
4918    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 4, 2, S("abcdefghij5klmnopqrst"));
4919    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
4920    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
4921    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 6, 0, S("can't happen"));
4922    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4923    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
4924    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 5, S("abcdefghij12345klmnopqrst"));
4925    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 9, S("abcdefghij123456789klmnopqrst"));
4926    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
4927    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 11, S("abcdefghij1234567890klmnopqrst"));
4928    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4929    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
4930    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 4, S("abcdefghij2345klmnopqrst"));
4931    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 8, S("abcdefghij23456789klmnopqrst"));
4932    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
4933    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 10, S("abcdefghij234567890klmnopqrst"));
4934    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
4935    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 1, S("abcdefghij6klmnopqrst"));
4936    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 2, S("abcdefghij67klmnopqrst"));
4937    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 4, S("abcdefghij6789klmnopqrst"));
4938    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 5, S("abcdefghij67890klmnopqrst"));
4939    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 6, S("abcdefghij67890klmnopqrst"));
4940    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
4941    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 9, 1, S("abcdefghij0klmnopqrst"));
4942    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 9, 2, S("abcdefghij0klmnopqrst"));
4943    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4944    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
4945    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 11, 0, S("can't happen"));
4946    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
4947    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
4948    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
4949    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789klmnopqrst"));
4950    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890klmnopqrst"));
4951    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890klmnopqrst"));
4952    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
4953    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
4954    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
4955    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789klmnopqrst"));
4956    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890klmnopqrst"));
4957    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890klmnopqrst"));
4958    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
4959    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 1, S("abcdefghij1klmnopqrst"));
4960    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 5, S("abcdefghij12345klmnopqrst"));
4961    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 9, S("abcdefghij123456789klmnopqrst"));
4962    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890klmnopqrst"));
4963    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890klmnopqrst"));
4964    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
4965    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 19, 1, S("abcdefghij0klmnopqrst"));
4966    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 19, 2, S("abcdefghij0klmnopqrst"));
4967    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
4968    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
4969    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
4970    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 0, 0, S("abcdefghijlmnopqrst"));
4971    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 0, 1, S("abcdefghijlmnopqrst"));
4972    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 1, 0, S("can't happen"));
4973    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 0, S("abcdefghijlmnopqrst"));
4974    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 1, S("abcdefghij1lmnopqrst"));
4975    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 2, S("abcdefghij12lmnopqrst"));
4976    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 4, S("abcdefghij1234lmnopqrst"));
4977    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 5, S("abcdefghij12345lmnopqrst"));
4978    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 6, S("abcdefghij12345lmnopqrst"));
4979    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 0, S("abcdefghijlmnopqrst"));
4980    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 1, S("abcdefghij2lmnopqrst"));
4981    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 2, S("abcdefghij23lmnopqrst"));
4982    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 3, S("abcdefghij234lmnopqrst"));
4983    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 4, S("abcdefghij2345lmnopqrst"));
4984    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 5, S("abcdefghij2345lmnopqrst"));
4985    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 0, S("abcdefghijlmnopqrst"));
4986    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 1, S("abcdefghij3lmnopqrst"));
4987    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 2, S("abcdefghij34lmnopqrst"));
4988    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 3, S("abcdefghij345lmnopqrst"));
4989    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 4, S("abcdefghij345lmnopqrst"));
4990    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 4, 0, S("abcdefghijlmnopqrst"));
4991    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 4, 1, S("abcdefghij5lmnopqrst"));
4992    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 4, 2, S("abcdefghij5lmnopqrst"));
4993    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 5, 0, S("abcdefghijlmnopqrst"));
4994    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 5, 1, S("abcdefghijlmnopqrst"));
4995    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 6, 0, S("can't happen"));
4996    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 0, S("abcdefghijlmnopqrst"));
4997    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 1, S("abcdefghij1lmnopqrst"));
4998    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 5, S("abcdefghij12345lmnopqrst"));
4999    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 9, S("abcdefghij123456789lmnopqrst"));
5000    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 10, S("abcdefghij1234567890lmnopqrst"));
5001    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 11, S("abcdefghij1234567890lmnopqrst"));
5002    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 0, S("abcdefghijlmnopqrst"));
5003    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 1, S("abcdefghij2lmnopqrst"));
5004    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 4, S("abcdefghij2345lmnopqrst"));
5005    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 8, S("abcdefghij23456789lmnopqrst"));
5006    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 9, S("abcdefghij234567890lmnopqrst"));
5007    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 10, S("abcdefghij234567890lmnopqrst"));
5008}
5009
5010template <class S>
5011void test47()
5012{
5013    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 0, S("abcdefghijlmnopqrst"));
5014    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 1, S("abcdefghij6lmnopqrst"));
5015    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 2, S("abcdefghij67lmnopqrst"));
5016    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 4, S("abcdefghij6789lmnopqrst"));
5017    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 5, S("abcdefghij67890lmnopqrst"));
5018    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 6, S("abcdefghij67890lmnopqrst"));
5019    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 9, 0, S("abcdefghijlmnopqrst"));
5020    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 9, 1, S("abcdefghij0lmnopqrst"));
5021    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 9, 2, S("abcdefghij0lmnopqrst"));
5022    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 10, 0, S("abcdefghijlmnopqrst"));
5023    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 10, 1, S("abcdefghijlmnopqrst"));
5024    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 11, 0, S("can't happen"));
5025    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 0, S("abcdefghijlmnopqrst"));
5026    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 1, S("abcdefghij1lmnopqrst"));
5027    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890lmnopqrst"));
5028    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789lmnopqrst"));
5029    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890lmnopqrst"));
5030    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890lmnopqrst"));
5031    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 0, S("abcdefghijlmnopqrst"));
5032    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 1, S("abcdefghij2lmnopqrst"));
5033    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 9, S("abcdefghij234567890lmnopqrst"));
5034    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789lmnopqrst"));
5035    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890lmnopqrst"));
5036    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890lmnopqrst"));
5037    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 0, S("abcdefghijlmnopqrst"));
5038    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 1, S("abcdefghij1lmnopqrst"));
5039    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 5, S("abcdefghij12345lmnopqrst"));
5040    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 9, S("abcdefghij123456789lmnopqrst"));
5041    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890lmnopqrst"));
5042    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890lmnopqrst"));
5043    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 19, 0, S("abcdefghijlmnopqrst"));
5044    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 19, 1, S("abcdefghij0lmnopqrst"));
5045    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 19, 2, S("abcdefghij0lmnopqrst"));
5046    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 20, 0, S("abcdefghijlmnopqrst"));
5047    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 20, 1, S("abcdefghijlmnopqrst"));
5048    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
5049    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 0, 0, S("abcdefghijpqrst"));
5050    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 0, 1, S("abcdefghijpqrst"));
5051    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 1, 0, S("can't happen"));
5052    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 0, S("abcdefghijpqrst"));
5053    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 1, S("abcdefghij1pqrst"));
5054    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 2, S("abcdefghij12pqrst"));
5055    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 4, S("abcdefghij1234pqrst"));
5056    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 5, S("abcdefghij12345pqrst"));
5057    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 6, S("abcdefghij12345pqrst"));
5058    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 0, S("abcdefghijpqrst"));
5059    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 1, S("abcdefghij2pqrst"));
5060    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 2, S("abcdefghij23pqrst"));
5061    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 3, S("abcdefghij234pqrst"));
5062    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 4, S("abcdefghij2345pqrst"));
5063    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 5, S("abcdefghij2345pqrst"));
5064    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 0, S("abcdefghijpqrst"));
5065    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 1, S("abcdefghij3pqrst"));
5066    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 2, S("abcdefghij34pqrst"));
5067    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 3, S("abcdefghij345pqrst"));
5068    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 4, S("abcdefghij345pqrst"));
5069    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 4, 0, S("abcdefghijpqrst"));
5070    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 4, 1, S("abcdefghij5pqrst"));
5071    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 4, 2, S("abcdefghij5pqrst"));
5072    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 5, 0, S("abcdefghijpqrst"));
5073    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 5, 1, S("abcdefghijpqrst"));
5074    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 6, 0, S("can't happen"));
5075    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 0, S("abcdefghijpqrst"));
5076    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 1, S("abcdefghij1pqrst"));
5077    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 5, S("abcdefghij12345pqrst"));
5078    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 9, S("abcdefghij123456789pqrst"));
5079    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 10, S("abcdefghij1234567890pqrst"));
5080    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 11, S("abcdefghij1234567890pqrst"));
5081    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 0, S("abcdefghijpqrst"));
5082    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 1, S("abcdefghij2pqrst"));
5083    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 4, S("abcdefghij2345pqrst"));
5084    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 8, S("abcdefghij23456789pqrst"));
5085    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 9, S("abcdefghij234567890pqrst"));
5086    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 10, S("abcdefghij234567890pqrst"));
5087    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 0, S("abcdefghijpqrst"));
5088    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 1, S("abcdefghij6pqrst"));
5089    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 2, S("abcdefghij67pqrst"));
5090    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 4, S("abcdefghij6789pqrst"));
5091    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 5, S("abcdefghij67890pqrst"));
5092    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 6, S("abcdefghij67890pqrst"));
5093    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 9, 0, S("abcdefghijpqrst"));
5094    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 9, 1, S("abcdefghij0pqrst"));
5095    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 9, 2, S("abcdefghij0pqrst"));
5096    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 10, 0, S("abcdefghijpqrst"));
5097    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 10, 1, S("abcdefghijpqrst"));
5098    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 11, 0, S("can't happen"));
5099    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 0, S("abcdefghijpqrst"));
5100    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 1, S("abcdefghij1pqrst"));
5101    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890pqrst"));
5102    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789pqrst"));
5103    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890pqrst"));
5104    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890pqrst"));
5105    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 0, S("abcdefghijpqrst"));
5106    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 1, S("abcdefghij2pqrst"));
5107    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 9, S("abcdefghij234567890pqrst"));
5108    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789pqrst"));
5109    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890pqrst"));
5110    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890pqrst"));
5111    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 0, S("abcdefghijpqrst"));
5112    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 1, S("abcdefghij1pqrst"));
5113}
5114
5115template <class S>
5116void test48()
5117{
5118    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 5, S("abcdefghij12345pqrst"));
5119    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 9, S("abcdefghij123456789pqrst"));
5120    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890pqrst"));
5121    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890pqrst"));
5122    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 19, 0, S("abcdefghijpqrst"));
5123    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 19, 1, S("abcdefghij0pqrst"));
5124    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 19, 2, S("abcdefghij0pqrst"));
5125    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 20, 0, S("abcdefghijpqrst"));
5126    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 20, 1, S("abcdefghijpqrst"));
5127    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
5128    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 0, 0, S("abcdefghijt"));
5129    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 0, 1, S("abcdefghijt"));
5130    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 1, 0, S("can't happen"));
5131    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 0, S("abcdefghijt"));
5132    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 1, S("abcdefghij1t"));
5133    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 2, S("abcdefghij12t"));
5134    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 4, S("abcdefghij1234t"));
5135    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 5, S("abcdefghij12345t"));
5136    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 6, S("abcdefghij12345t"));
5137    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 0, S("abcdefghijt"));
5138    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 1, S("abcdefghij2t"));
5139    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 2, S("abcdefghij23t"));
5140    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 3, S("abcdefghij234t"));
5141    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 4, S("abcdefghij2345t"));
5142    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 5, S("abcdefghij2345t"));
5143    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 0, S("abcdefghijt"));
5144    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 1, S("abcdefghij3t"));
5145    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 2, S("abcdefghij34t"));
5146    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 3, S("abcdefghij345t"));
5147    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 4, S("abcdefghij345t"));
5148    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 4, 0, S("abcdefghijt"));
5149    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 4, 1, S("abcdefghij5t"));
5150    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 4, 2, S("abcdefghij5t"));
5151    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 5, 0, S("abcdefghijt"));
5152    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 5, 1, S("abcdefghijt"));
5153    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 6, 0, S("can't happen"));
5154    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 0, S("abcdefghijt"));
5155    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 1, S("abcdefghij1t"));
5156    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 5, S("abcdefghij12345t"));
5157    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 9, S("abcdefghij123456789t"));
5158    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 10, S("abcdefghij1234567890t"));
5159    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 11, S("abcdefghij1234567890t"));
5160    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 0, S("abcdefghijt"));
5161    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 1, S("abcdefghij2t"));
5162    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 4, S("abcdefghij2345t"));
5163    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 8, S("abcdefghij23456789t"));
5164    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 9, S("abcdefghij234567890t"));
5165    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 10, S("abcdefghij234567890t"));
5166    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 0, S("abcdefghijt"));
5167    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 1, S("abcdefghij6t"));
5168    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 2, S("abcdefghij67t"));
5169    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 4, S("abcdefghij6789t"));
5170    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 5, S("abcdefghij67890t"));
5171    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 6, S("abcdefghij67890t"));
5172    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 9, 0, S("abcdefghijt"));
5173    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 9, 1, S("abcdefghij0t"));
5174    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 9, 2, S("abcdefghij0t"));
5175    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 10, 0, S("abcdefghijt"));
5176    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 10, 1, S("abcdefghijt"));
5177    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 11, 0, S("can't happen"));
5178    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 0, S("abcdefghijt"));
5179    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 1, S("abcdefghij1t"));
5180    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890t"));
5181    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789t"));
5182    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890t"));
5183    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890t"));
5184    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 0, S("abcdefghijt"));
5185    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 1, S("abcdefghij2t"));
5186    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 9, S("abcdefghij234567890t"));
5187    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789t"));
5188    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890t"));
5189    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890t"));
5190    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 0, S("abcdefghijt"));
5191    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 1, S("abcdefghij1t"));
5192    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 5, S("abcdefghij12345t"));
5193    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 9, S("abcdefghij123456789t"));
5194    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890t"));
5195    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890t"));
5196    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 19, 0, S("abcdefghijt"));
5197    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 19, 1, S("abcdefghij0t"));
5198    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 19, 2, S("abcdefghij0t"));
5199    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 20, 0, S("abcdefghijt"));
5200    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 20, 1, S("abcdefghijt"));
5201    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
5202    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 0, 0, S("abcdefghij"));
5203    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 0, 1, S("abcdefghij"));
5204    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 1, 0, S("can't happen"));
5205    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 0, S("abcdefghij"));
5206    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 1, S("abcdefghij1"));
5207    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 2, S("abcdefghij12"));
5208    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 4, S("abcdefghij1234"));
5209    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 5, S("abcdefghij12345"));
5210    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 6, S("abcdefghij12345"));
5211    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 0, S("abcdefghij"));
5212    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 1, S("abcdefghij2"));
5213    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 2, S("abcdefghij23"));
5214    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 3, S("abcdefghij234"));
5215    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 4, S("abcdefghij2345"));
5216    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 5, S("abcdefghij2345"));
5217    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 0, S("abcdefghij"));
5218}
5219
5220template <class S>
5221void test49()
5222{
5223    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 1, S("abcdefghij3"));
5224    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 2, S("abcdefghij34"));
5225    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 3, S("abcdefghij345"));
5226    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 4, S("abcdefghij345"));
5227    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 4, 0, S("abcdefghij"));
5228    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 4, 1, S("abcdefghij5"));
5229    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 4, 2, S("abcdefghij5"));
5230    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 5, 0, S("abcdefghij"));
5231    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 5, 1, S("abcdefghij"));
5232    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 6, 0, S("can't happen"));
5233    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 0, S("abcdefghij"));
5234    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 1, S("abcdefghij1"));
5235    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 5, S("abcdefghij12345"));
5236    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 9, S("abcdefghij123456789"));
5237    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
5238    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
5239    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 0, S("abcdefghij"));
5240    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 1, S("abcdefghij2"));
5241    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 4, S("abcdefghij2345"));
5242    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 8, S("abcdefghij23456789"));
5243    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 9, S("abcdefghij234567890"));
5244    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 10, S("abcdefghij234567890"));
5245    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 0, S("abcdefghij"));
5246    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 1, S("abcdefghij6"));
5247    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 2, S("abcdefghij67"));
5248    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 4, S("abcdefghij6789"));
5249    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 5, S("abcdefghij67890"));
5250    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 6, S("abcdefghij67890"));
5251    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 9, 0, S("abcdefghij"));
5252    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 9, 1, S("abcdefghij0"));
5253    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 9, 2, S("abcdefghij0"));
5254    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 10, 0, S("abcdefghij"));
5255    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 10, 1, S("abcdefghij"));
5256    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 11, 0, S("can't happen"));
5257    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 0, S("abcdefghij"));
5258    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
5259    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
5260    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
5261    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
5262    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
5263    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 0, S("abcdefghij"));
5264    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
5265    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
5266    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
5267    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
5268    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
5269    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 0, S("abcdefghij"));
5270    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
5271    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
5272    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
5273    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
5274    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
5275    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 19, 0, S("abcdefghij"));
5276    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
5277    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
5278    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 20, 0, S("abcdefghij"));
5279    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 20, 1, S("abcdefghij"));
5280    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
5281    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 0, 0, S("abcdefghij"));
5282    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 0, 1, S("abcdefghij"));
5283    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 1, 0, S("can't happen"));
5284    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 0, S("abcdefghij"));
5285    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 1, S("abcdefghij1"));
5286    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 2, S("abcdefghij12"));
5287    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 4, S("abcdefghij1234"));
5288    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 5, S("abcdefghij12345"));
5289    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 6, S("abcdefghij12345"));
5290    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 0, S("abcdefghij"));
5291    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 1, S("abcdefghij2"));
5292    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 2, S("abcdefghij23"));
5293    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 3, S("abcdefghij234"));
5294    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 4, S("abcdefghij2345"));
5295    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 5, S("abcdefghij2345"));
5296    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 0, S("abcdefghij"));
5297    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 1, S("abcdefghij3"));
5298    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 2, S("abcdefghij34"));
5299    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 3, S("abcdefghij345"));
5300    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 4, S("abcdefghij345"));
5301    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 4, 0, S("abcdefghij"));
5302    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 4, 1, S("abcdefghij5"));
5303    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 4, 2, S("abcdefghij5"));
5304    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 5, 0, S("abcdefghij"));
5305    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 5, 1, S("abcdefghij"));
5306    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 6, 0, S("can't happen"));
5307    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 0, S("abcdefghij"));
5308    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 1, S("abcdefghij1"));
5309    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 5, S("abcdefghij12345"));
5310    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 9, S("abcdefghij123456789"));
5311    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
5312    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
5313    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 0, S("abcdefghij"));
5314    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 1, S("abcdefghij2"));
5315    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 4, S("abcdefghij2345"));
5316    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 8, S("abcdefghij23456789"));
5317    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 9, S("abcdefghij234567890"));
5318    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 10, S("abcdefghij234567890"));
5319    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 0, S("abcdefghij"));
5320    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 1, S("abcdefghij6"));
5321    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 2, S("abcdefghij67"));
5322    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 4, S("abcdefghij6789"));
5323}
5324
5325template <class S>
5326void test50()
5327{
5328    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 5, S("abcdefghij67890"));
5329    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 6, S("abcdefghij67890"));
5330    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 9, 0, S("abcdefghij"));
5331    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 9, 1, S("abcdefghij0"));
5332    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 9, 2, S("abcdefghij0"));
5333    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 10, 0, S("abcdefghij"));
5334    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 10, 1, S("abcdefghij"));
5335    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 11, 0, S("can't happen"));
5336    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 0, S("abcdefghij"));
5337    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
5338    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
5339    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
5340    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
5341    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
5342    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 0, S("abcdefghij"));
5343    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
5344    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
5345    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
5346    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
5347    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
5348    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 0, S("abcdefghij"));
5349    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
5350    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
5351    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
5352    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
5353    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
5354    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 19, 0, S("abcdefghij"));
5355    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
5356    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
5357    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 20, 0, S("abcdefghij"));
5358    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 20, 1, S("abcdefghij"));
5359    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 21, 0, S("can't happen"));
5360    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
5361    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
5362    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 1, 0, S("can't happen"));
5363    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
5364    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 1, S("abcdefghijklmnopqrs1t"));
5365    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 2, S("abcdefghijklmnopqrs12t"));
5366    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 4, S("abcdefghijklmnopqrs1234t"));
5367    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 5, S("abcdefghijklmnopqrs12345t"));
5368    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 6, S("abcdefghijklmnopqrs12345t"));
5369    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
5370    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 1, S("abcdefghijklmnopqrs2t"));
5371    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 2, S("abcdefghijklmnopqrs23t"));
5372    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 3, S("abcdefghijklmnopqrs234t"));
5373    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 4, S("abcdefghijklmnopqrs2345t"));
5374    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 5, S("abcdefghijklmnopqrs2345t"));
5375    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
5376    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 1, S("abcdefghijklmnopqrs3t"));
5377    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 2, S("abcdefghijklmnopqrs34t"));
5378    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 3, S("abcdefghijklmnopqrs345t"));
5379    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 4, S("abcdefghijklmnopqrs345t"));
5380    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
5381    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 4, 1, S("abcdefghijklmnopqrs5t"));
5382    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 4, 2, S("abcdefghijklmnopqrs5t"));
5383    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
5384    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
5385    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 6, 0, S("can't happen"));
5386    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5387    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
5388    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345t"));
5389    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789t"));
5390    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
5391    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890t"));
5392    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5393    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
5394    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345t"));
5395    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789t"));
5396    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
5397    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890t"));
5398    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
5399    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6t"));
5400    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67t"));
5401    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789t"));
5402    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890t"));
5403    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890t"));
5404    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
5405    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 9, 1, S("abcdefghijklmnopqrs0t"));
5406    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 9, 2, S("abcdefghijklmnopqrs0t"));
5407    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5408    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
5409    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 11, 0, S("can't happen"));
5410    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5411    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
5412    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
5413    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789t"));
5414    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890t"));
5415    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890t"));
5416    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5417    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
5418    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
5419    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789t"));
5420    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890t"));
5421    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890t"));
5422    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5423    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1t"));
5424    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345t"));
5425    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789t"));
5426    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890t"));
5427    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890t"));
5428}
5429
5430template <class S>
5431void test51()
5432{
5433    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
5434    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0t"));
5435    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0t"));
5436    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
5437    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
5438    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
5439    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 0, 0, S("abcdefghijklmnopqrs"));
5440    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 0, 1, S("abcdefghijklmnopqrs"));
5441    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 1, 0, S("can't happen"));
5442    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 0, S("abcdefghijklmnopqrs"));
5443    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 1, S("abcdefghijklmnopqrs1"));
5444    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 2, S("abcdefghijklmnopqrs12"));
5445    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 4, S("abcdefghijklmnopqrs1234"));
5446    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 5, S("abcdefghijklmnopqrs12345"));
5447    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 6, S("abcdefghijklmnopqrs12345"));
5448    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 0, S("abcdefghijklmnopqrs"));
5449    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 1, S("abcdefghijklmnopqrs2"));
5450    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 2, S("abcdefghijklmnopqrs23"));
5451    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 3, S("abcdefghijklmnopqrs234"));
5452    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 4, S("abcdefghijklmnopqrs2345"));
5453    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 5, S("abcdefghijklmnopqrs2345"));
5454    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 0, S("abcdefghijklmnopqrs"));
5455    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 1, S("abcdefghijklmnopqrs3"));
5456    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 2, S("abcdefghijklmnopqrs34"));
5457    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 3, S("abcdefghijklmnopqrs345"));
5458    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 4, S("abcdefghijklmnopqrs345"));
5459    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 4, 0, S("abcdefghijklmnopqrs"));
5460    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 4, 1, S("abcdefghijklmnopqrs5"));
5461    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 4, 2, S("abcdefghijklmnopqrs5"));
5462    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 5, 0, S("abcdefghijklmnopqrs"));
5463    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 5, 1, S("abcdefghijklmnopqrs"));
5464    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 6, 0, S("can't happen"));
5465    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5466    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5467    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345"));
5468    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789"));
5469    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5470    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890"));
5471    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5472    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5473    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345"));
5474    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789"));
5475    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5476    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890"));
5477    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 0, S("abcdefghijklmnopqrs"));
5478    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6"));
5479    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67"));
5480    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789"));
5481    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890"));
5482    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890"));
5483    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 9, 0, S("abcdefghijklmnopqrs"));
5484    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 9, 1, S("abcdefghijklmnopqrs0"));
5485    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 9, 2, S("abcdefghijklmnopqrs0"));
5486    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5487    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 10, 1, S("abcdefghijklmnopqrs"));
5488    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 11, 0, S("can't happen"));
5489    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5490    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5491    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5492    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789"));
5493    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890"));
5494    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890"));
5495    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5496    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5497    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5498    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789"));
5499    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890"));
5500    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890"));
5501    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5502    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1"));
5503    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345"));
5504    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789"));
5505    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890"));
5506    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890"));
5507    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrs"));
5508    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0"));
5509    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0"));
5510    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrs"));
5511    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrs"));
5512    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
5513    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 0, 0, S("abcdefghijklmnopqrs"));
5514    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 0, 1, S("abcdefghijklmnopqrs"));
5515    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 1, 0, S("can't happen"));
5516    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 0, S("abcdefghijklmnopqrs"));
5517    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 1, S("abcdefghijklmnopqrs1"));
5518    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 2, S("abcdefghijklmnopqrs12"));
5519    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 4, S("abcdefghijklmnopqrs1234"));
5520    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 5, S("abcdefghijklmnopqrs12345"));
5521    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 6, S("abcdefghijklmnopqrs12345"));
5522    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 0, S("abcdefghijklmnopqrs"));
5523    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 1, S("abcdefghijklmnopqrs2"));
5524    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 2, S("abcdefghijklmnopqrs23"));
5525    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 3, S("abcdefghijklmnopqrs234"));
5526    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 4, S("abcdefghijklmnopqrs2345"));
5527    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 5, S("abcdefghijklmnopqrs2345"));
5528    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 0, S("abcdefghijklmnopqrs"));
5529    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 1, S("abcdefghijklmnopqrs3"));
5530    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 2, S("abcdefghijklmnopqrs34"));
5531    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 3, S("abcdefghijklmnopqrs345"));
5532    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 4, S("abcdefghijklmnopqrs345"));
5533}
5534
5535template <class S>
5536void test52()
5537{
5538    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 4, 0, S("abcdefghijklmnopqrs"));
5539    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 4, 1, S("abcdefghijklmnopqrs5"));
5540    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 4, 2, S("abcdefghijklmnopqrs5"));
5541    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 5, 0, S("abcdefghijklmnopqrs"));
5542    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 5, 1, S("abcdefghijklmnopqrs"));
5543    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 6, 0, S("can't happen"));
5544    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5545    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5546    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345"));
5547    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789"));
5548    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5549    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890"));
5550    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5551    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5552    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345"));
5553    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789"));
5554    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5555    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890"));
5556    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 0, S("abcdefghijklmnopqrs"));
5557    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6"));
5558    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67"));
5559    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789"));
5560    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890"));
5561    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890"));
5562    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 9, 0, S("abcdefghijklmnopqrs"));
5563    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 9, 1, S("abcdefghijklmnopqrs0"));
5564    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 9, 2, S("abcdefghijklmnopqrs0"));
5565    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5566    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 10, 1, S("abcdefghijklmnopqrs"));
5567    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 11, 0, S("can't happen"));
5568    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrs"));
5569    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
5570    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
5571    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789"));
5572    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890"));
5573    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890"));
5574    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrs"));
5575    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
5576    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
5577    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789"));
5578    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890"));
5579    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890"));
5580    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrs"));
5581    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1"));
5582    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345"));
5583    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789"));
5584    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890"));
5585    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890"));
5586    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrs"));
5587    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0"));
5588    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0"));
5589    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrs"));
5590    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrs"));
5591    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
5592    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
5593    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
5594    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 1, 0, S("can't happen"));
5595    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
5596    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 1, S("abcdefghijklmnopqrst1"));
5597    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 2, S("abcdefghijklmnopqrst12"));
5598    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 4, S("abcdefghijklmnopqrst1234"));
5599    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 5, S("abcdefghijklmnopqrst12345"));
5600    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 6, S("abcdefghijklmnopqrst12345"));
5601    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
5602    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 1, S("abcdefghijklmnopqrst2"));
5603    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 2, S("abcdefghijklmnopqrst23"));
5604    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 3, S("abcdefghijklmnopqrst234"));
5605    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 4, S("abcdefghijklmnopqrst2345"));
5606    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 5, S("abcdefghijklmnopqrst2345"));
5607    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
5608    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
5609    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
5610    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
5611    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
5612    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
5613    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 4, 1, S("abcdefghijklmnopqrst5"));
5614    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 4, 2, S("abcdefghijklmnopqrst5"));
5615    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
5616    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
5617    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 6, 0, S("can't happen"));
5618    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5619    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5620    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 5, S("abcdefghijklmnopqrst12345"));
5621    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 9, S("abcdefghijklmnopqrst123456789"));
5622    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5623    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 11, S("abcdefghijklmnopqrst1234567890"));
5624    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5625    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5626    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 4, S("abcdefghijklmnopqrst2345"));
5627    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 8, S("abcdefghijklmnopqrst23456789"));
5628    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5629    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 10, S("abcdefghijklmnopqrst234567890"));
5630    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
5631    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 1, S("abcdefghijklmnopqrst6"));
5632    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 2, S("abcdefghijklmnopqrst67"));
5633    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 4, S("abcdefghijklmnopqrst6789"));
5634    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 5, S("abcdefghijklmnopqrst67890"));
5635    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 6, S("abcdefghijklmnopqrst67890"));
5636    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
5637    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 9, 1, S("abcdefghijklmnopqrst0"));
5638}
5639
5640template <class S>
5641void test53()
5642{
5643    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 9, 2, S("abcdefghijklmnopqrst0"));
5644    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5645    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
5646    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 11, 0, S("can't happen"));
5647    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5648    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5649    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5650    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrst1234567890123456789"));
5651    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrst12345678901234567890"));
5652    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrst12345678901234567890"));
5653    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5654    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5655    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5656    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrst234567890123456789"));
5657    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrst2345678901234567890"));
5658    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrst2345678901234567890"));
5659    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5660    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrst1"));
5661    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrst12345"));
5662    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
5663    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
5664    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
5665    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
5666    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
5667    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrst0"));
5668    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
5669    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
5670    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
5671    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 0, 0, S("abcdefghijklmnopqrst"));
5672    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 0, 1, S("abcdefghijklmnopqrst"));
5673    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 1, 0, S("can't happen"));
5674    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
5675    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 1, S("abcdefghijklmnopqrst1"));
5676    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 2, S("abcdefghijklmnopqrst12"));
5677    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 4, S("abcdefghijklmnopqrst1234"));
5678    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 5, S("abcdefghijklmnopqrst12345"));
5679    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 6, S("abcdefghijklmnopqrst12345"));
5680    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
5681    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 1, S("abcdefghijklmnopqrst2"));
5682    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 2, S("abcdefghijklmnopqrst23"));
5683    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 3, S("abcdefghijklmnopqrst234"));
5684    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 4, S("abcdefghijklmnopqrst2345"));
5685    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 5, S("abcdefghijklmnopqrst2345"));
5686    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
5687    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
5688    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
5689    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
5690    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
5691    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
5692    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 4, 1, S("abcdefghijklmnopqrst5"));
5693    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 4, 2, S("abcdefghijklmnopqrst5"));
5694    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
5695    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
5696    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 6, 0, S("can't happen"));
5697    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5698    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5699    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 5, S("abcdefghijklmnopqrst12345"));
5700    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 9, S("abcdefghijklmnopqrst123456789"));
5701    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5702    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 11, S("abcdefghijklmnopqrst1234567890"));
5703    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5704    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5705    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 4, S("abcdefghijklmnopqrst2345"));
5706    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 8, S("abcdefghijklmnopqrst23456789"));
5707    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5708    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 10, S("abcdefghijklmnopqrst234567890"));
5709    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
5710    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 1, S("abcdefghijklmnopqrst6"));
5711    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 2, S("abcdefghijklmnopqrst67"));
5712    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 4, S("abcdefghijklmnopqrst6789"));
5713    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 5, S("abcdefghijklmnopqrst67890"));
5714    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 6, S("abcdefghijklmnopqrst67890"));
5715    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
5716    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 9, 1, S("abcdefghijklmnopqrst0"));
5717    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 9, 2, S("abcdefghijklmnopqrst0"));
5718    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5719    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
5720    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 11, 0, S("can't happen"));
5721    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
5722    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
5723    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
5724    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrst1234567890123456789"));
5725    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrst12345678901234567890"));
5726    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrst12345678901234567890"));
5727    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
5728    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
5729    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
5730    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrst234567890123456789"));
5731    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrst2345678901234567890"));
5732    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrst2345678901234567890"));
5733    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
5734    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrst1"));
5735    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrst12345"));
5736    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
5737    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
5738    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
5739    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
5740    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
5741    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrst0"));
5742    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
5743}
5744
5745template <class S>
5746void test54()
5747{
5748    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
5749    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
5750    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 0, 0, S("can't happen"));
5751    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 0, 1, S("can't happen"));
5752    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 1, 0, S("can't happen"));
5753    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 0, S("can't happen"));
5754    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 1, S("can't happen"));
5755    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 2, S("can't happen"));
5756    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 4, S("can't happen"));
5757    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 5, S("can't happen"));
5758    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 6, S("can't happen"));
5759    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 0, S("can't happen"));
5760    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 1, S("can't happen"));
5761    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 2, S("can't happen"));
5762    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 3, S("can't happen"));
5763    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 4, S("can't happen"));
5764    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 5, S("can't happen"));
5765    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 0, S("can't happen"));
5766    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 1, S("can't happen"));
5767    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 2, S("can't happen"));
5768    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 3, S("can't happen"));
5769    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 4, S("can't happen"));
5770    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 4, 0, S("can't happen"));
5771    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 4, 1, S("can't happen"));
5772    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 4, 2, S("can't happen"));
5773    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 5, 0, S("can't happen"));
5774    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 5, 1, S("can't happen"));
5775    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 6, 0, S("can't happen"));
5776    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 0, S("can't happen"));
5777    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 1, S("can't happen"));
5778    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 5, S("can't happen"));
5779    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 9, S("can't happen"));
5780    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 10, S("can't happen"));
5781    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 11, S("can't happen"));
5782    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 0, S("can't happen"));
5783    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 1, S("can't happen"));
5784    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 4, S("can't happen"));
5785    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 8, S("can't happen"));
5786    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 9, S("can't happen"));
5787    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 10, S("can't happen"));
5788    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 0, S("can't happen"));
5789    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 1, S("can't happen"));
5790    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 2, S("can't happen"));
5791    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 4, S("can't happen"));
5792    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 5, S("can't happen"));
5793    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 6, S("can't happen"));
5794    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 9, 0, S("can't happen"));
5795    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 9, 1, S("can't happen"));
5796    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 9, 2, S("can't happen"));
5797    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 10, 0, S("can't happen"));
5798    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 10, 1, S("can't happen"));
5799    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 11, 0, S("can't happen"));
5800    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
5801    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
5802    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
5803    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
5804    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
5805    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
5806    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
5807    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
5808    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
5809    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
5810    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
5811    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
5812    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
5813    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
5814    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
5815    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
5816    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
5817    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
5818    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
5819    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
5820    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
5821    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
5822    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
5823    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
5824}
5825
5826template <class S>
5827void test55()
5828{
5829    test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, S("abcdefghi1234567890"));
5830    test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, S("abcdefghi0"));
5831    test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, S("abcdefghi"));
5832    test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, S("abcdefghi"));
5833    test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 21, S("can't happen"));
5834    test_npos(S("abcdefghij"), 9, 2, S(""), 0, S("abcdefghi"));
5835    test_npos(S("abcdefghij"), 9, 2, S(""), 1, S("can't happen"));
5836    test_npos(S("abcdefghij"), 9, 2, S("12345"), 0, S("abcdefghi12345"));
5837    test_npos(S("abcdefghij"), 9, 2, S("12345"), 1, S("abcdefghi2345"));
5838    test_npos(S("abcdefghij"), 9, 2, S("12345"), 2, S("abcdefghi345"));
5839    test_npos(S("abcdefghij"), 9, 2, S("12345"), 4, S("abcdefghi5"));
5840    test_npos(S("abcdefghij"), 9, 2, S("12345"), 5, S("abcdefghi"));
5841    test_npos(S("abcdefghij"), 9, 2, S("12345"), 6, S("can't happen"));
5842}
5843
5844int main()
5845{
5846    {
5847    typedef std::string S;
5848    test0<S>();
5849    test1<S>();
5850    test2<S>();
5851    test3<S>();
5852    test4<S>();
5853    test5<S>();
5854    test6<S>();
5855    test7<S>();
5856    test8<S>();
5857    test9<S>();
5858    test10<S>();
5859    test11<S>();
5860    test12<S>();
5861    test13<S>();
5862    test14<S>();
5863    test15<S>();
5864    test16<S>();
5865    test17<S>();
5866    test18<S>();
5867    test19<S>();
5868    test20<S>();
5869    test21<S>();
5870    test22<S>();
5871    test23<S>();
5872    test24<S>();
5873    test25<S>();
5874    test26<S>();
5875    test27<S>();
5876    test28<S>();
5877    test29<S>();
5878    test30<S>();
5879    test31<S>();
5880    test32<S>();
5881    test33<S>();
5882    test34<S>();
5883    test35<S>();
5884    test36<S>();
5885    test37<S>();
5886    test38<S>();
5887    test39<S>();
5888    test40<S>();
5889    test41<S>();
5890    test42<S>();
5891    test43<S>();
5892    test44<S>();
5893    test45<S>();
5894    test46<S>();
5895    test47<S>();
5896    test48<S>();
5897    test49<S>();
5898    test50<S>();
5899    test51<S>();
5900    test52<S>();
5901    test53<S>();
5902    test54<S>();
5903    test55<S>();
5904    }
5905#if __cplusplus >= 201103L
5906    {
5907    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
5908    test0<S>();
5909    test1<S>();
5910    test2<S>();
5911    test3<S>();
5912    test4<S>();
5913    test5<S>();
5914    test6<S>();
5915    test7<S>();
5916    test8<S>();
5917    test9<S>();
5918    test10<S>();
5919    test11<S>();
5920    test12<S>();
5921    test13<S>();
5922    test14<S>();
5923    test15<S>();
5924    test16<S>();
5925    test17<S>();
5926    test18<S>();
5927    test19<S>();
5928    test20<S>();
5929    test21<S>();
5930    test22<S>();
5931    test23<S>();
5932    test24<S>();
5933    test25<S>();
5934    test26<S>();
5935    test27<S>();
5936    test28<S>();
5937    test29<S>();
5938    test30<S>();
5939    test31<S>();
5940    test32<S>();
5941    test33<S>();
5942    test34<S>();
5943    test35<S>();
5944    test36<S>();
5945    test37<S>();
5946    test38<S>();
5947    test39<S>();
5948    test40<S>();
5949    test41<S>();
5950    test42<S>();
5951    test43<S>();
5952    test44<S>();
5953    test45<S>();
5954    test46<S>();
5955    test47<S>();
5956    test48<S>();
5957    test49<S>();
5958    test50<S>();
5959    test51<S>();
5960    test52<S>();
5961    test53<S>();
5962    test54<S>();
5963    test55<S>();
5964    }
5965#endif
5966}
5967