-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathReplace.cpp
83 lines (81 loc) · 1.53 KB
/
Replace.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "common.h"
#include <mU/Pattern.h>
#include <mU/System.h>
using namespace mU;
CAPI CPROC(System_MatchQ)
{
map_t m;
return MatchQ(m,Pat(At(x,1)),At(x,0)) ? True : False;
}
CAPI CPROC(System_MemberQ)
{
return MemberQ(At(x,0),At(x,1)) ? True : False;
}
CAPI CPROC(System_Dispatch)
{
if(VecQ(At(x,0)))
return Dispatch(At(x,0));
return Dispatch(x);
}
CAPI CPROC(System_Replace)
{
var a = At(x,0);
var b = At(x,1);
if(VecQ(b))
{
size_t n = Size(b);
for(size_t i = 0; i < n; ++i)
a = Replace(a,At(b,i));
return a;
}
return Replace(a,b);
}
CAPI CPROC(System_ReplaceAll)
{
var a = At(x,0);
var b = At(x,1);
if(VecQ(b))
{
size_t n = Size(b);
for(size_t i = 0; i < n; ++i)
a = ReplaceAll(a,At(b,i));
return a;
}
return ReplaceAll(a,b);
}
CAPI CPROC(System_ReplaceRepeated)
{
var r = System_ReplaceAll(x);
while(!Same(r,At(x,0)))
{
At(x,0) = r;
r = System_ReplaceAll(x);
}
return r;
}
CAPI CPROC(System_OddQ)
{
return OddQ(At(x,0)) ? True : False;
}
CAPI CPROC(System_EvenQ)
{
return EvenQ(At(x,0)) ? True : False;
}
CAPI CPROC(System_Join)
{
size_t n = Size(x);
var c = At(x,0);
if(VecQ(c))
{
size_t m = Size(c);
for(size_t i = 1; i < n; ++i)
m += Size(At(x,i));
var r = Vec(m);
vec_t::rep_t::iterator iter = CVec(r).begin();
std::copy(CVec(c).begin(),CVec(c).end(),iter);
for(size_t i = 1; i < n; ++i)
std::copy(CVec(At(x,i)).begin(),CVec(At(x,i)).end(),iter += Size(At(x,i - 1)));
return r;
}
return 0;
}