5
5
# Export Symbols API
6
6
export Symbols,
7
7
getindex, length, iterate, lastindex, eltype,
8
+ findall, findfirst,
8
9
handle, header
9
-
10
+
10
11
# Export SymtabEntry API
11
12
export SymtabEntry,
12
13
deref, symbol_name, symbol_value, isundef, isglobal, islocal, isweak
@@ -15,8 +16,8 @@ export SymtabEntry,
15
16
export SymbolRef,
16
17
symbol_number
17
18
18
- # Import iteration protocol
19
- import Base: length, iterate, lastindex
19
+ # Import Base methods for extension
20
+ import Base: length, iterate, lastindex, findall, findfirst
20
21
21
22
"""
22
23
Symbols
@@ -38,6 +39,10 @@ in emphasis:
38
39
- iterate()
39
40
- eltype()
40
41
42
+ ### Search
43
+ - findall()
44
+ - findfirst()
45
+
41
46
### Misc.
42
47
- *handle()*
43
48
"""
@@ -62,6 +67,46 @@ function getindex(syms::Symbols{H}, idx) where {H <: ObjectHandle}
62
67
)
63
68
end
64
69
70
+ """
71
+ findall(symbols::Symbols, name::String)
72
+
73
+ Return a list of symbols that match the given `name`.
74
+ """
75
+ function findall (symbols:: Symbols , name:: AbstractString )
76
+ return findall (symbols, [name])
77
+ end
78
+
79
+ """
80
+ findall(symbols::Symbols, name::String)
81
+
82
+ Return a list of symbols that match one of the given `names`.
83
+ """
84
+ function findall (symbols:: Symbols , names:: Vector{S} ) where {S <: AbstractString }
85
+ return [s for s in symbols if symbol_name (s) in names]
86
+ end
87
+
88
+ """
89
+ findfirst(symbols::Symbols, name::String)
90
+
91
+ Return the first section that matches the given `name`.
92
+ """
93
+ function findfirst (symbols:: Symbols , name:: AbstractString )
94
+ return findfirst (symbols, [name])
95
+ end
96
+
97
+ """
98
+ findfirst(symbols::Symbols, names::Vector{String})
99
+
100
+ Return the first section that matches on of the given `names`.
101
+ """
102
+ function findfirst (symbols:: Symbols , names:: Vector{String} )
103
+ results = findall (symbols, names)
104
+ if isempty (results)
105
+ error (" Could not find any symbols that match $(names) " )
106
+ end
107
+ return first (results)
108
+ end
109
+
65
110
66
111
67
112
0 commit comments