| 1 |
#include <tads.h> |
| 2 |
|
| 3 |
counter: object |
| 4 |
n_ = 1 |
| 5 |
; |
| 6 |
|
| 7 |
echo(id, str) |
| 8 |
{ |
| 9 |
"[<<counter.n_++>>: <<id>>] <<str>>\n"; |
| 10 |
} |
| 11 |
|
| 12 |
main(args) |
| 13 |
{ |
| 14 |
local i, j; |
| 15 |
|
| 16 |
echo('all s->S', rexReplace('s', 'this is a test', 'S')); |
| 17 |
echo('one s->S', rexReplace('s', 'this is a test', 'S', ReplaceOnce)); |
| 18 |
echo('all s->S from 5', rexReplace('s', 'this is a test', 'S', |
| 19 |
ReplaceAll, 5)); |
| 20 |
echo('one s->S from 5', rexReplace('s', 'this is a test', 'S', |
| 21 |
ReplaceOnce, 5)); |
| 22 |
echo('all s->S from 4', rexReplace('s', 'this is a test', 'S', |
| 23 |
ReplaceAll, 4)); |
| 24 |
echo('one s->S from 4', rexReplace('s', 'this is a test', 'S', |
| 25 |
ReplaceOnce, 4)); |
| 26 |
|
| 27 |
echo('a->x, b->y, c->z, case sensitive', |
| 28 |
rexReplace(['a', 'b', 'c'], 'abc ABC this is an abc ABC test', |
| 29 |
['x', 'y', 'z'])); |
| 30 |
echo('a->x, b->y, c->z, case insensitive', |
| 31 |
rexReplace(['a', 'b', 'c'], 'abc ABC this is an abc ABC test', |
| 32 |
['x', 'y', 'z'], ReplaceIgnoreCase)); |
| 33 |
echo('a->x, b->y, c->z, case insensitive, follow case', |
| 34 |
rexReplace(['a', 'b', 'c'], 'abc ABC this is an abc ABC test', |
| 35 |
['x', 'y', 'z'], |
| 36 |
ReplaceAll | ReplaceIgnoreCase | ReplaceFollowCase)); |
| 37 |
echo('and->und, or->oder, the->der, case sensitive', |
| 38 |
rexReplace(['and', 'or', 'the'], |
| 39 |
'This and That AND These and Those OR ' |
| 40 |
+ 'the Other Thing Or Whatever And Done!', |
| 41 |
['und', 'oder', 'der'], |
| 42 |
ReplaceAll)); |
| 43 |
echo('and->und, or->oder, the->der, case sensitive', |
| 44 |
rexReplace(['and', 'or', 'the'], |
| 45 |
'This and That AND These and Those OR ' |
| 46 |
+ 'the Other Thing Or Whatever And Done!', |
| 47 |
['und', 'oder', 'der'], |
| 48 |
ReplaceAll | ReplaceIgnoreCase)); |
| 49 |
echo('and->und, or->oder, the->der, case sensitive', |
| 50 |
rexReplace(['and', 'or', 'the'], |
| 51 |
'This and That AND These and Those OR ' |
| 52 |
+ 'the Other Thing Or Whatever And Done!', |
| 53 |
['und', 'oder', 'der'], |
| 54 |
ReplaceIgnoreCase | ReplaceFollowCase)); |
| 55 |
|
| 56 |
echo('digits->(digits)', |
| 57 |
rexReplace('(<digit>+)', '123, 4567, and 891011', '(%1)')); |
| 58 |
|
| 59 |
echo('all s->SS, t->TT', |
| 60 |
rexReplace(['s', 't'], 'this is a test', ['SS', 'TT'])); |
| 61 |
echo('one s->SS, t->TT', |
| 62 |
rexReplace(['s', 't'], 'this is a test', ['SS', 'TT'], |
| 63 |
ReplaceOnce)); |
| 64 |
|
| 65 |
echo('serial s->SS, t->TT', |
| 66 |
rexReplace(['s', 't'], 'this is a test', ['SS', 'TT'], |
| 67 |
ReplaceSerial)); |
| 68 |
echo('serial,one s->SS, t->TT', |
| 69 |
rexReplace(['s', 't'], 'this is a test', ['SS', 'TT'], |
| 70 |
ReplaceOnce | ReplaceSerial)); |
| 71 |
echo('serial,one q->QQ, t->TT', |
| 72 |
rexReplace(['q', 't'], 'this is a test', ['QQ', 'TT'], |
| 73 |
ReplaceOnce | ReplaceSerial)); |
| 74 |
echo('parallel s->SS, t->TT', |
| 75 |
rexReplace(['s', 't'], 'this is a test', ['SS', 'TT'])); |
| 76 |
|
| 77 |
echo('serial a->bb, b->cc, c->dd', |
| 78 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 79 |
['bb', 'cc', 'dd'], |
| 80 |
ReplaceAll | ReplaceSerial)); |
| 81 |
echo('parallel a->bb, b->cc, c->dd', |
| 82 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 83 |
['bb', 'cc', 'dd'], |
| 84 |
ReplaceAll)); |
| 85 |
|
| 86 |
echo('serial a->bb, b->cc, c->dd from 5', |
| 87 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 88 |
['bb', 'cc', 'dd'], |
| 89 |
ReplaceAll | ReplaceSerial, 5)); |
| 90 |
echo('parallel a->bb, b->cc, c->dd from 5', |
| 91 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 92 |
['bb', 'cc', 'dd'], |
| 93 |
ReplaceAll, 5)); |
| 94 |
|
| 95 |
echo('serial a->bb, b->cc, c->dd limit=0', |
| 96 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 97 |
['bb', 'cc', 'dd'], |
| 98 |
ReplaceAll | ReplaceSerial, nil, 0)); |
| 99 |
echo('serial a->bb, b->cc, c->dd limit=2', |
| 100 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 101 |
['bb', 'cc', 'dd'], |
| 102 |
ReplaceAll | ReplaceSerial, nil, 1)); |
| 103 |
echo('serial a->bb, b->cc, c->dd limit=2', |
| 104 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 105 |
['bb', 'cc', 'dd'], |
| 106 |
ReplaceAll | ReplaceSerial, nil, 2)); |
| 107 |
echo('serial a->bb, b->cc, c->dd limit=3', |
| 108 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 109 |
['bb', 'cc', 'dd'], |
| 110 |
ReplaceAll | ReplaceSerial, nil, 3)); |
| 111 |
|
| 112 |
echo('parallel a->bb, b->cc, c->dd limit=0', |
| 113 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 114 |
['bb', 'cc', 'dd'], nil, nil, 0)); |
| 115 |
echo('parallel a->bb, b->cc, c->dd limit=2', |
| 116 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 117 |
['bb', 'cc', 'dd'], nil, nil, 1)); |
| 118 |
echo('parallel a->bb, b->cc, c->dd limit=2', |
| 119 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 120 |
['bb', 'cc', 'dd'], nil, nil, 2)); |
| 121 |
echo('parallel a->bb, b->cc, c->dd limit=3', |
| 122 |
rexReplace(['a', 'b', 'c'], 'abc this is an abc test', |
| 123 |
['bb', 'cc', 'dd'], nil, nil, 3)); |
| 124 |
|
| 125 |
i = 1; |
| 126 |
echo('alpha->func(even \'s\' only)', |
| 127 |
rexReplace('<alpha>', 'this is a test of some special stuff', |
| 128 |
{ match, idx, orig: match == 's' && (i++ & 1) == 0 |
| 129 |
? match.toUpper() : match })); |
| 130 |
|
| 131 |
i = 1; |
| 132 |
echo('t,s->func(even only)', |
| 133 |
rexReplace(['s', 't'], 'this is a test of some special stuff', |
| 134 |
{ match, idx, orig: (i++ & 1) == 0 |
| 135 |
? match.toUpper() : match })); |
| 136 |
|
| 137 |
i = j = 1; |
| 138 |
echo('s->func(even only), t->func(odd only)', |
| 139 |
rexReplace(['s', 't'], 'this is a test of some special stuff', |
| 140 |
[{ m, idx, o: (i++ & 1) == 0 ? m.toUpper() : m }, |
| 141 |
{ m, idx, o: (j++ & 1) != 0 ? m.toUpper() : m }])); |
| 142 |
|
| 143 |
echo('s,t->func(m), func(m,i)', |
| 144 |
rexReplace(['s', 't'], 'this is a test of some special stuff', |
| 145 |
[{ m: '[<<m>>]'}, { m, i: '[<<m>>:<<i>>]' }])); |
| 146 |
} |