From ac5417b5c04a3661ad24ecb3f7003122dba92bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 20 Sep 2017 22:50:12 +0200 Subject: [PATCH] clean up string indexing --- base/interactiveutil.jl | 3 +-- base/loading.jl | 2 +- base/profile.jl | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 6bbc05a494c6a..3bf8a9bd1c160 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -33,8 +33,7 @@ by setting `JULIA_EDITOR`, `VISUAL` or `EDITOR` as an environment variable. function edit(path::AbstractString, line::Integer=0) command = editor() name = basename(first(command)) - issrc = length(path)>2 && path[end-2:end] == ".jl" - if issrc + if endswith(path, ".jl") f = find_source_file(path) f !== nothing && (path = f) end diff --git a/base/loading.jl b/base/loading.jl index bdc38471890fe..4e9f41acfca0f 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -103,7 +103,7 @@ function find_in_path(name::String, wd::Union{Void,String}) isabspath(name) && return name base = name if endswith(name,".jl") - base = name[1:end-3] + base = name[1:prevind(name, end-2)] else name = string(base,".jl") end diff --git a/base/profile.jl b/base/profile.jl index 922ec8414b805..ad89abdb88d2c 100644 --- a/base/profile.jl +++ b/base/profile.jl @@ -640,14 +640,14 @@ function rtruncto(str::String, w::Int) if length(str) <= w return str else - return string("...", str[end-w+4:end]) + return string("...", str[chr2ind(str, length(str)-w+4):end]) end end function ltruncto(str::String, w::Int) if length(str) <= w return str else - return string(str[1:w-4], "...") + return string(str[1:chr2ind(str,w-4)], "...") end end