Skip to content

Commit

Permalink
Merge pull request #20 from JuliaString/spj/splituni
Browse files Browse the repository at this point in the history
Fix split on UniStr union (due to change in Base)
  • Loading branch information
ScottPJones authored Feb 26, 2022
2 parents 41c5598 + 09d8bef commit 85bce68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["ScottPJones <[email protected]>"]
keywords = ["Strings"]
license = "MIT"
uuid = "e79e7a6a-7bb1-5a4d-9d64-da657b06f53a"
version = "1.1.2"
version = "1.1.3"

[deps]
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
Expand Down
15 changes: 8 additions & 7 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ rpad(ch::Chr, cnt::Integer, pad::AbstractChar=' ') =
const SetOfChars =
Union{Tuple{Vararg{<:AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}

@static if !isdefined(Base, :eachsplit)
function __split(str, splitter, limit::Integer, keep_empty::Bool, strs::Vector)
pos = 1
lst = lastindex(str)
Expand All @@ -86,7 +85,6 @@ function __split(str, splitter, limit::Integer, keep_empty::Bool, strs::Vector)
end
(keep_empty || pos <= lst) ? push!(strs, SubString(str, pos)) : strs
end
end

function __rsplit(str, splitter, limit::Integer, keep_empty::Bool, strs::Vector)
res = find(Last, splitter, str)
Expand All @@ -113,22 +111,25 @@ splitarr(::MaybeSub{String}) = SubString{String}[]
splitarr(::MaybeSub{T}) where {T<:Str} =
SubString{Str{basecse(T),Nothing,Nothing,Nothing}}[]

@static if !isdefined(Base, :eachsplit)
@static if isdefined(Base, :eachsplit)
const _SplitTypes = MaybeSub{<:Str{<:Union{_LatinCSE,_UCS2CSE,_UTF32CSE}}}
else
const _SplitTypes = MaybeSub{<:Str}
Base._split(str::MaybeSub{<:Str}, splitter, limit, keepempty, vec) =
__split(str, splitter, limit, keepempty, vec)
end

split(str::MaybeSub{<:Str}, splitter;
split(str::_SplitTypes, splitter;
limit::Integer=0, keepempty::Bool=true, keep::Union{Nothing,Bool}=nothing) =
__split(str, splitter, limit, checkkeep(keepempty, keep, :split), splitarr(str))

split(str::MaybeSub{<:Str}, splitter::AbstractChar;
split(str::_SplitTypes, splitter::AbstractChar;
limit::Integer=0, keepempty::Bool=true, keep::Union{Nothing,Bool}=nothing) =
__split(str, isequal(splitter), limit, checkkeep(keepempty, keep, :split), splitarr(str))

split(str::MaybeSub{<:Str}, splitter::SetOfChars;
split(str::_SplitTypes, splitter::SetOfChars;
limit::Integer=0, keepempty::Bool=true, keep::Union{Nothing,Bool}=nothing) =
__split(str, in(splitter), limit, checkkeep(keepempty, keep, :split), splitarr(str))
end

Base._rsplit(str::MaybeSub{<:Str}, splitter, limit, keepempty, vec) =
__rsplit(str, splitter, limit, keepempty, vec)
Expand Down

2 comments on commit 85bce68

@ScottPJones
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator() register

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/55500

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.3 -m "<description of version>" 85bce685d73ccc477d1d7c03a3193837523caed8
git push origin v1.1.3

Please sign in to comment.