11#=
22Utility functions for Str strings
33
4- Copyright 2018-2020 Gandalf Software, Inc., Scott P. Jones,
4+ Copyright 2018-2021 Gandalf Software, Inc., Scott P. Jones,
55and other contributors to the Julia language
66Licensed under MIT License, see LICENSE.md
77Based initially on julia/test/strings/util.jl
@@ -65,6 +65,7 @@ rpad(ch::Chr, cnt::Integer, pad::AbstractChar=' ') =
6565const SetOfChars =
6666 Union{Tuple{Vararg{<: AbstractChar }},AbstractVector{<: AbstractChar },Set{<: AbstractChar }}
6767
68+ @static if ! isdefined (Base, :eachsplit )
6869function __split (str, splitter, limit:: Integer , keep_empty:: Bool , strs:: Vector )
6970 pos = 1
7071 lst = lastindex (str)
@@ -85,6 +86,7 @@ function __split(str, splitter, limit::Integer, keep_empty::Bool, strs::Vector)
8586 end
8687 (keep_empty || pos <= lst) ? push! (strs, SubString (str, pos)) : strs
8788end
89+ end
8890
8991function __rsplit (str, splitter, limit:: Integer , keep_empty:: Bool , strs:: Vector )
9092 res = find (Last, splitter, str)
@@ -111,10 +113,9 @@ splitarr(::MaybeSub{String}) = SubString{String}[]
111113splitarr (:: MaybeSub{T} ) where {T<: Str } =
112114 SubString{Str{basecse (T),Nothing,Nothing,Nothing}}[]
113115
116+ @static if ! isdefined (Base, :eachsplit )
114117Base. _split (str:: MaybeSub{<:Str} , splitter, limit, keepempty, vec) =
115118 __split (str, splitter, limit, keepempty, vec)
116- Base. _rsplit (str:: MaybeSub{<:Str} , splitter, limit, keepempty, vec) =
117- __rsplit (str, splitter, limit, keepempty, vec)
118119
119120split (str:: MaybeSub{<:Str} , splitter;
120121 limit:: Integer = 0 , keepempty:: Bool = true , keep:: Union{Nothing,Bool} = nothing ) =
@@ -127,6 +128,10 @@ split(str::MaybeSub{<:Str}, splitter::AbstractChar;
127128split (str:: MaybeSub{<:Str} , splitter:: SetOfChars ;
128129 limit:: Integer = 0 , keepempty:: Bool = true , keep:: Union{Nothing,Bool} = nothing ) =
129130 __split (str, in (splitter), limit, checkkeep (keepempty, keep, :split ), splitarr (str))
131+ end
132+
133+ Base. _rsplit (str:: MaybeSub{<:Str} , splitter, limit, keepempty, vec) =
134+ __rsplit (str, splitter, limit, keepempty, vec)
130135
131136rsplit (str:: MaybeSub{<:Str} , splitter;
132137 limit:: Integer = 0 , keepempty:: Bool = true , keep:: Union{Nothing,Bool} = nothing ) =
0 commit comments