diff --git a/Project.toml b/Project.toml index cd8c7fa..7d61339 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "OMRuntimeExternalC" uuid = "ada38df0-e20e-11ed-02f3-2b4b19c1ec8a" authors = ["Adrian Pop ", "John Tinnerholm "] -version = "0.3.5" +version = "0.3.6" [deps] CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" diff --git a/src/api.jl b/src/api.jl index 732f73e..68a01a1 100644 --- a/src/api.jl +++ b/src/api.jl @@ -964,6 +964,16 @@ function ModelicaStrings_scanIdentifier(string::String, startIndex::Int64) return (Int64(nextIndex[]), idStr) end +#= Output-by-reference, as the Modelica external "C" declaration calls it (Modelica.Utilities.Strings + .scanToken, which MSL's readRealParameter calls). =# +function ModelicaStrings_scanIdentifier(string::AbstractString, startIndex::Integer, nextIndex::Ref{Cint}, + identifier::Ref{Cstring}) + ccall((:ModelicaStrings_scanIdentifier, installedLibPathlibModelicaExternalC), + Cvoid, + (Cstring, Cint, Ref{Cint}, Ref{Cstring}), + String(string), Cint(startIndex), nextIndex, identifier) +end + """ MODELICA_EXPORT void ModelicaStrings_scanInteger(_In_z_ const char* string, int startIndex, int unsignedNumber, int* nextIndex, int* integerNumber); @@ -1051,6 +1061,16 @@ function ModelicaStrings_scanString(string::String, startIndex::Int64) return (Int64(nextIndex[]), resStr) end +#= Output-by-reference, as the Modelica external "C" declaration calls it (Modelica.Utilities.Strings + .scanToken, which MSL's readRealParameter calls). =# +function ModelicaStrings_scanString(string::AbstractString, startIndex::Integer, nextIndex::Ref{Cint}, + result::Ref{Cstring}) + ccall((:ModelicaStrings_scanString, installedLibPathlibModelicaExternalC), + Cvoid, + (Cstring, Cint, Ref{Cint}, Ref{Cstring}), + String(string), Cint(startIndex), nextIndex, result) +end + """ MODELICA_EXPORT int ModelicaStrings_hashString(_In_z_ const char* str); """ diff --git a/test/runtests.jl b/test/runtests.jl index 5cdb73c..cd7ec0b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -583,6 +583,17 @@ const ORC = OMRuntimeExternalC @test nextIdx == 6 end + @testset "ModelicaStrings_scanIdentifier and scanString Ref-accepting overloads" begin + #= as the Modelica external "C" declarations call them (Strings.scanToken in MSL's readRealParameter) =# + local nextIdx = Ref{Cint}(0) + local ident = Ref{Cstring}(C_NULL) + ORC.ModelicaStrings_scanIdentifier("myVar = 42", 1, nextIdx, ident) + @test nextIdx[] == 6 && unsafe_string(ident[]) == "myVar" + local result = Ref{Cstring}(C_NULL) + ORC.ModelicaStrings_scanString(" \"abc\" rest", 1, nextIdx, result) + @test nextIdx[] == 8 && unsafe_string(result[]) == "abc" + end + @testset "ModelicaStrings_hashString" begin #= Same string should produce the same hash =# @test ORC.ModelicaStrings_hashString("test") == ORC.ModelicaStrings_hashString("test")