From d12bf251cab7dc073e06bc062a1a04abea700b85 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Tue, 22 Aug 2017 18:55:55 +0200 Subject: [PATCH] titlecase: all non-letters are considered word-separators This is to be consistent with `istitle`. --- base/deprecated.jl | 2 +- base/strings/basic.jl | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index 78e456452a08c..f0dc590ffb6f9 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1709,7 +1709,7 @@ export hex2num @deprecate diagm(A::SparseMatrixCSC) spdiagm(sparsevec(A)) # PR #23393 -@deprecate titlecase(s::AbstractString) titlecase(s, false) +@deprecate titlecase(s::AbstractString) titlecase(s, false, true) # END 0.7 deprecations diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 86bece8d09d75..2be1fbd0486b0 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -423,17 +423,23 @@ julia> titlecase("ISS - international space station", false) "ISS - International Space Station" ``` """ -function titlecase(s::AbstractString, strict::Bool) +function titlecase(s::AbstractString, strict::Bool, compat=false) startword = true b = IOBuffer() for c in s - if isspace(c) + if compat + if isspace(c) + print(b, c) + startword = true + continue + end + elseif !iscased(c) print(b, c) startword = true - else - print(b, startword ? titlecase(c) : strict ? lowercase(c) : c) - startword = false + continue end + print(b, startword ? titlecase(c) : strict ? lowercase(c) : c) + startword = false end return String(take!(b)) end