Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/staticstring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ function Base.String(x::StaticString{N, T}) where {N, T}
b = Base.StringVector(N)
return String(b .= x.codeunits)
end

@inline Base.ncodeunits(::StaticString{N}) where N = N

function StaticString(cu::Base.CodeUnits{T}) where T
N = length(cu)
return StaticString{N, T}(NTuple{N, T}(cu))
end
StaticString(s::AbstractString) = StaticString(codeunits(s))
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include("epochs_test.jl")
include("comprehensive_test.jl")
include("cdf2_test.jl")
include("CommonDataModelExt_test.jl")
include("staticstring.jl")

@testset "Aqua" begin
using Aqua
Expand Down
11 changes: 11 additions & 0 deletions test/staticstring.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CommonDataFormat: StaticString

@testset "StaticString" begin
s = "Hello, World!"
ss = StaticString(s)

StaticString(codeunits(s))
@test ss == s
@test String(ss) == s
@test !isempty(ss)
end
Loading