forked from ulthiel/Bocses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathString.i.m
42 lines (30 loc) · 943 Bytes
/
String.i.m
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Bocses - A Magma package for computing with bocses.
By
Julian Külshammer ([email protected])
and
Ulrich Thiel ([email protected])
File: String.i.m
*/
//=============================================================================
intrinsic Replace(str::MonStgElt, reg::MonStgElt, rep::MonStgElt) -> MonStgElt
/*
Intrinsic: Replace
Declaration:
:intrinsic Replace(str::MonStgElt, reg::MonStgElt, rep::MonStgElt) -> MonStgElt
Description:
Replaces all occurences of the regular expression +reg+ by +rep+ in the string +str+.
*/
{Replaces all occurences of the regular expression reg by rep in the string str.}
newstr := "";
while true do
t,m := Regexp(reg,str);
if t eq false then
return newstr*str;
else
N := Position(str,m);
newstr *:= str[1..N-1]*rep;
str := str[N+#m..#str];
end if;
end while;
end intrinsic;