From af3cd59e13c93fcb3e3788a79b0168127473d18a Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 11 Nov 2020 11:26:54 -0500 Subject: [PATCH] eliminate copy for Unicode.normalize of substring (#38381) eliminate copy for Unicode.normalize of substring --- base/strings/unicode.jl | 2 +- stdlib/Unicode/test/runtests.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/strings/unicode.jl b/base/strings/unicode.jl index 235f85184d43e..9bafad5d347e2 100644 --- a/base/strings/unicode.jl +++ b/base/strings/unicode.jl @@ -145,7 +145,7 @@ const UTF8PROC_STRIPMARK = (1<<13) utf8proc_error(result) = error(unsafe_string(ccall(:utf8proc_errmsg, Cstring, (Cssize_t,), result))) -function utf8proc_map(str::String, options::Integer) +function utf8proc_map(str::Union{String,SubString{String}}, options::Integer) nwords = ccall(:utf8proc_decompose, Int, (Ptr{UInt8}, Int, Ptr{UInt8}, Int, Cint), str, sizeof(str), C_NULL, 0, options) nwords < 0 && utf8proc_error(nwords) diff --git a/stdlib/Unicode/test/runtests.jl b/stdlib/Unicode/test/runtests.jl index aa4fe6e01e575..d84137de11054 100644 --- a/stdlib/Unicode/test/runtests.jl +++ b/stdlib/Unicode/test/runtests.jl @@ -6,7 +6,7 @@ using Unicode: normalize, isassigned @testset "string normalization" begin # normalize (Unicode normalization etc.): - @test normalize("\u006e\u0303", :NFC) == "\u00f1" + @test normalize("\u006e\u0303", :NFC) == "\u00f1" == normalize(SubString("ab\u006e\u0303cd",3,4), :NFC) @test "\u006e\u0303" == normalize("\u00f1", :NFD) @test normalize("\ufb00", :NFC) != "ff" @test normalize("\ufb00", :NFKC) == "ff"