-
Notifications
You must be signed in to change notification settings - Fork 13
/
uuList.r
66 lines (62 loc) · 1.24 KB
/
uuList.r
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
# \file uuList.r
# \brief List functions.
# \author Chris Smeele
# \author Paul Frederiks
# \copyright Copyright (c) 2015, Utrecht University. All rights reserved.
# \license GPLv3, see LICENSE.
# \brief Check if a list contains a certain string value.
#
# \param list
# \param value
# \param inList
#
uuListContains(*list, *value, *inList) {
*inList = false;
foreach (*item in *list) {
if (*item == *value) {
*inList = true;
break;
}
}
}
# \brief Check if an item in list matches a certain regex.
#
# \param list
# \param pattern
# \param inList
#
uuListMatches(*list, *pattern, *inList) {
*inList = false;
foreach (*item in *list) {
if (*item like regex *pattern) {
*inList = true;
break;
}
}
}
# \brief Join a list.
#
# \param[in] delimiter
# \param[in] list
# \param[out] str contains all elements in `list`, separated by `delimiter`
#
uuJoin(*delimiter, *list, *str) {
*str = "";
foreach (*item in *list) {
if (strlen(*str) > 0) {
*str = *str ++ *delimiter ++ *item;
} else {
*str = *item;
}
}
}
# \brief Return a reversed list
# \param[in] list to reverse
# \returnvalue reversed list
uuListReverse(*lst) {
*newlst = list();
foreach(*el in *lst){
*newlst = cons(*el, *newlst);
}
*newlst;
}