diff --git a/src/StdLib.jl b/src/StdLib.jl index 5eb4199..451b3f5 100644 --- a/src/StdLib.jl +++ b/src/StdLib.jl @@ -112,9 +112,10 @@ Base.cmp(a::String, b::CppBasicString) = cmp(a,String(b)) # Make sure functions taking a C++ string as argument can also take a Julia string CxxWrapCore.map_julia_arg_type(x::Type{<:StdString}) = AbstractString -StdLib.StdStringAllocated(x::String) = StdString(x,length(x)) -Base.cconvert(::Type{CxxWrapCore.ConstCxxRef{StdString}}, x::String) = StdString(x,length(x)) -Base.cconvert(::Type{StdLib.StdStringDereferenced}, x::String) = StdString(x,length(x)) +StdString(x::String) = StdString(x,ncodeunits(x)) +StdLib.StdStringAllocated(x::String) = StdString(x,ncodeunits(x)) +Base.cconvert(::Type{CxxWrapCore.ConstCxxRef{StdString}}, x::String) = StdString(x,ncodeunits(x)) +Base.cconvert(::Type{StdLib.StdStringDereferenced}, x::String) = StdString(x,ncodeunits(x)) Base.unsafe_convert(::Type{CxxWrapCore.ConstCxxRef{StdString}}, x::StdString) = ConstCxxRef(x) function StdValArray(v::Vector{T}) where {T} diff --git a/test/stdlib.jl b/test/stdlib.jl index 90876aa..c1a465b 100644 --- a/test/stdlib.jl +++ b/test/stdlib.jl @@ -39,10 +39,10 @@ let s = StdString("foo") end let s = "\x01\x00\x02" - @test length(StdString(s)) == 1 + @test length(StdString(s)) == 3 @test length(StdString(s, length(s))) == 3 - @test String(StdString(s)) != s + @test String(StdString(s)) == s @test String(StdString(s, length(s))) == s end