mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 02:05:30 +01:00
replace_all! returns if any modification has been performed
This commit is contained in:
parent
95ac3940d7
commit
18ad0a04b6
@ -352,15 +352,17 @@ function replace(W::GWord, index, toreplace::GWord, replacement::GWord)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}})
|
function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}})
|
||||||
|
modified = false
|
||||||
for toreplace in reverse!(sort!(collect(keys(subst_dict)), by=length))
|
for toreplace in reverse!(sort!(collect(keys(subst_dict)), by=length))
|
||||||
replacement = subst_dict[toreplace]
|
replacement = subst_dict[toreplace]
|
||||||
i = findfirst(W, toreplace)
|
i = findfirst(W, toreplace)
|
||||||
while i ≠ 0
|
while i ≠ 0
|
||||||
|
modified = true
|
||||||
replace!(W,i,toreplace, replacement)
|
replace!(W,i,toreplace, replacement)
|
||||||
i = findnext(W, toreplace, i)
|
i = findnext(W, toreplace, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return W
|
return modified
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_all{T<:GSymbol}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}}) = replace_all!(deepcopy(W), subst_dict)
|
replace_all{T<:GSymbol}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}}) = replace_all!(deepcopy(W), subst_dict)
|
||||||
|
Loading…
Reference in New Issue
Block a user