blob: de3d39703d03f3da38271cfe5a4df1b533ab27a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include "internal.h"
// replace will replace all occurences of the given bytes 'from' to bytes 'to'
// edits are done in place and modify the string.
// NOTE: as of now strings from and to must be the same size.
void
string·replace(string s, byte* from, byte* to)
{
vlong fromL = str·len(from);
vlong toL = str·len(to);
if (toL != fromL) { panicf("different sized replacement string not supported"); }
vlong l = string·len(s);
vlong i = l;
vlong j = l;
for (i = 0; i < l; i++) {
for (j = 0; j < toL; j++) {
if (s[i] == from[j]) {
s[i] = to[j];
break;
}
}
}
}
|