| 1 | // Copyright (C) 2004-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // rope (SGI extension) |
| 19 | |
| 20 | #include <ext/rope> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | const char base[] = |
| 24 | "Happy families are all alike; every unhappy family is unhappy in \ |
| 25 | its own way. \ |
| 26 | \ |
| 27 | Everything was in confusion in the Oblonskys' house. The wife \ |
| 28 | had discovered that the husband was carrying on an intrigue with \ |
| 29 | a French girl, who had been a governess in their family, and she \ |
| 30 | had announced to her husband that she could not go on living in \ |
| 31 | the same house with him. This position of affairs had now lasted \ |
| 32 | three days, and not only the husband and wife themselves, but all \ |
| 33 | the members of their family and household, were painfully \ |
| 34 | conscious of it. Every person in the house felt that there was \ |
| 35 | so sense in their living together, and that the stray people \ |
| 36 | brought together by chance in any inn had more in common with one \ |
| 37 | another than they, the members of the family and household of the \ |
| 38 | Oblonskys. The wife did not leave her own room, the husband had \ |
| 39 | not been at home for three days. The children ran wild all over \ |
| 40 | the house; the English governess quarreled with the housekeeper, \ |
| 41 | and wrote to a friend asking her to look out for a new situation \ |
| 42 | for her; the man-cook had walked off the day before just at \ |
| 43 | dinner time; the kitchen-maid, and the coachman had given \ |
| 44 | warning." |
| 45 | ; |
| 46 | |
| 47 | int baselen = sizeof(base) - 1; |
| 48 | |
| 49 | template<class StringType> |
| 50 | StringType |
| 51 | multiply(const StringType& s, int n) |
| 52 | { |
| 53 | StringType result; |
| 54 | while (n > 0) |
| 55 | { |
| 56 | result += s; |
| 57 | --n; |
| 58 | } |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | template <class StringType> |
| 63 | StringType |
| 64 | mung_substrings(const StringType& s, int len, int n, int skip) |
| 65 | { |
| 66 | StringType result; |
| 67 | int start = 0; |
| 68 | while (n > 0) |
| 69 | { |
| 70 | StringType tmp = s.substr (start, len); |
| 71 | result += tmp; |
| 72 | --n; |
| 73 | start += skip; |
| 74 | } |
| 75 | return result; |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | test01() |
| 80 | { |
| 81 | using namespace __gnu_cxx; |
| 82 | |
| 83 | crope r; |
| 84 | r = multiply(crope(base), 100000); |
| 85 | |
| 86 | crope r1; |
| 87 | r1 = mung_substrings(r, 100000, 500, 73); |
| 88 | |
| 89 | VERIFY( r1.size() == 50000000 ); |
| 90 | VERIFY( r1.substr(88888, 6)[0] == 's' ); |
| 91 | VERIFY( r1.substr(88888, 6)[2] == 'h' ); |
| 92 | } |
| 93 | |
| 94 | int main() |
| 95 | { |
| 96 | test01(); |
| 97 | return 0; |
| 98 | } |