From 579366bbd07c140b72d5ddb3dc097305ba9a9f90 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Mon, 29 Aug 2016 13:50:24 -0400 Subject: [PATCH 1/2] Revert "Revert #182599 "add faster done for strings" (#18275)" This reverts commit 6d179b33cb6bc793d8f6613b87c61ba287c92113. --- base/strings/string.jl | 2 ++ test/strings/basic.jl | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/base/strings/string.jl b/base/strings/string.jl index 9ff67987338e7..c7b9dd9237bf1 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -80,6 +80,8 @@ end return Char(c), i end +done(s::String, state) = state > endof(s.data) + @inline function next(s::String, i::Int) # function is split into this critical fast-path # for pure ascii data, such as parsing numbers, diff --git a/test/strings/basic.jl b/test/strings/basic.jl index 55398736d9976..e736da9e69890 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -427,7 +427,3 @@ foobaz(ch) = reinterpret(Char, typemax(UInt32)) # issue #17624, missing getindex method for String @test "abc"[:] == "abc" - -# PR #18259 reverted because failing test below -a = [x for x in String([0xcf, 0x83, 0x83, 0x83, 0x83])] -@test a[1] == 'σ' From d89690ec7341f14d35d13fcf0f98a92860767634 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Mon, 29 Aug 2016 14:12:26 -0400 Subject: [PATCH 2/2] Test that next(s, endof(s)) > endof(s.data) --- base/strings/string.jl | 2 ++ test/strings/basic.jl | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/base/strings/string.jl b/base/strings/string.jl index c7b9dd9237bf1..702db77e53ddd 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -80,6 +80,8 @@ end return Char(c), i end +# This implementation relies on `next` returning a value past the end of the +# String's underlying data, which is true for valid Strings done(s::String, state) = state > endof(s.data) @inline function next(s::String, i::Int) diff --git a/test/strings/basic.jl b/test/strings/basic.jl index e736da9e69890..ab2b8cef9ae5d 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -427,3 +427,9 @@ foobaz(ch) = reinterpret(Char, typemax(UInt32)) # issue #17624, missing getindex method for String @test "abc"[:] == "abc" + +# issue #18280: next/nextind must return past String's underlying data +for s in ("Hello", "Σ", "こんにちは", "😊😁") + @test next(s, endof(s))[2] > endof(s.data) + @test nextind(s, endof(s)) > endof(s.data) +end