Skip to content

Commit

Permalink
remove underscores from begins_with, ends_with, parse_int, parse_float
Browse files Browse the repository at this point in the history
remove parse_bin, parse_oct, parse_hex
ref #1539
  • Loading branch information
JeffBezanson committed Apr 3, 2013
1 parent b8e41d1 commit 70a8f39
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 203 deletions.
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function process_options(args::Array{Any,1})
# load juliarc now before processing any more options
try_include(string(ENV["HOME"],"/.juliarc.jl"))
startup = false
elseif begins_with(args[i], "--color")
elseif beginswith(args[i], "--color")
if args[i] == "--color"
color_set = true
global have_color = true
Expand Down Expand Up @@ -332,7 +332,7 @@ function _start()
startup && try_include(joinpath(ENV["HOME"],".juliarc.jl"))

if !color_set
@unix_only global have_color = (begins_with(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`))
@unix_only global have_color = (beginswith(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`))
@windows_only global have_color = true
end

Expand Down
2 changes: 1 addition & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function dlm_readrow(io::IO, dlm, eol::Char)
else
row = split(row_string, dlm, true)
end
if ends_with(row[end], eol)
if endswith(row[end], eol)
row[end] = chop(row[end])
end
row
Expand Down
10 changes: 10 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ export PipeString
@deprecate each_match eachmatch
@deprecate function_loc functionloc
@deprecate compile_hint precompile
@deprecate begins_with beginswith
@deprecate ends_with endswidth
@deprecate parse_float parsefloat
@deprecate parse_int parseint
@deprecate parse_bin(T,s) parseint(T,s,2)
@deprecate parse_bin(s) parseint(s,2)
@deprecate parse_oct(T,s) parseint(T,s,8)
@deprecate parse_oct(s) parseint(s,8)
@deprecate parse_hex(T,s) parseint(T,s,16)
@deprecate parse_hex(s) parseint(s,16)

@deprecate expr(hd, a...) Expr(hd, a...)
@deprecate expr(hd, a::Array{Any,1}) Expr(hd, a...)
Expand Down
4 changes: 2 additions & 2 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ end

## misc environment-related functionality ##

tty_cols() = parse_int(Int32, get(ENV,"COLUMNS","80"), 10)
tty_rows() = parse_int(Int32, get(ENV,"LINES","25"), 10)
tty_cols() = parseint(Int32, get(ENV,"COLUMNS","80"), 10)
tty_rows() = parseint(Int32, get(ENV,"LINES","25"), 10)
11 changes: 4 additions & 7 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -699,15 +699,15 @@ export

# strings and text output
ascii,
begins_with,
beginswith,
char,
charwidth,
chomp,
chop,
chr2ind,
bytestring,
eachmatch,
ends_with,
endswith,
escape_string,
first_utf8_byte,
ind2chr,
Expand Down Expand Up @@ -762,11 +762,8 @@ export
ndigits,
ndigits0z,
oct,
parse_bin,
parse_float,
parse_hex,
parse_int,
parse_oct,
parsefloat,
parseint,
print,
print_escaped,
print_joined,
Expand Down
4 changes: 2 additions & 2 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ num2hex(x::Float64) = hex(box(Uint64,unbox(Float64,x)),16)

function hex2num(s::String)
if length(s) <= 8
return box(Float32,unbox(Int32,parse_hex(Int32,s)))
return box(Float32,unbox(Int32,parseint(Int32,s,16)))
end
return box(Float64,unbox(Int64,parse_hex(Int64,s)))
return box(Float64,unbox(Int64,parseint(Int64,s,16)))
end

@vectorize_1arg Real iround
Expand Down
4 changes: 2 additions & 2 deletions base/git.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ function merge_configs(Bc::Dict, Lc::Dict, Rc::Dict)
# expunge removed submodules from left and right sides
deleted = Set{ByteString}()
for section in Bs - Ls & Rs
filter!((k,v)->!begins_with(k,"$section."),Lc)
filter!((k,v)->!begins_with(k,"$section."),Rc)
filter!((k,v)->!beginswith(k,"$section."),Lc)
filter!((k,v)->!beginswith(k,"$section."),Rc)
add!(deleted, section)
end
# merge the remaining config key-value pairs
Expand Down
6 changes: 3 additions & 3 deletions base/help.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
function decor_help_desc(func::String, mfunc::String, desc::String)
sd = split(desc, '\n')
for i = 1:length(sd)
if begins_with(sd[i], func)
if beginswith(sd[i], func)
sd[i] = mfunc * sd[i][length(func)+1:end]
else
break
Expand Down Expand Up @@ -54,7 +54,7 @@ function init_help()
CATEGORY_DICT[cat] = {}
end
if !isempty(mod)
if begins_with(func, '@')
if beginswith(func, '@')
mfunc = "@" * mod * "." * func[2:]
else
mfunc = mod * "." * func
Expand Down Expand Up @@ -133,7 +133,7 @@ function help_for(fname::String, obj)
found = true
else
macrocall = ""
if begins_with(fname, '@')
if beginswith(fname, '@')
sfname = fname[2:]
macrocall = "@"
else
Expand Down
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function find_in_path(name::String)
name[1] == '/' && return abspath(name)
isfile(name) && return abspath(name)
base = name
if ends_with(name,".jl")
if endswith(name,".jl")
base = match(r"^(.*)\.jl$",name).captures[1]
else
name = string(base,".jl")
Expand Down
2 changes: 1 addition & 1 deletion base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ end
function parse_connection_info(str)
m = match(r"^julia_worker:(\d+)#(.*)", str)
if m != nothing
(m.captures[2], parse_int(Int16, m.captures[1]))
(m.captures[2], parseint(Int16, m.captures[1]))
else
("", int16(-1))
end
Expand Down
2 changes: 1 addition & 1 deletion base/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ pull() = cd_pkgdir() do
end
# remove submodules that were deleted
for section in deleted
if !begins_with(section,"submodule.") continue end
if !beginswith(section,"submodule.") continue end
path = get(Lc,"$section.path",nothing)
if path == nothing continue end
run(`git rm -qrf --cached --ignore-unmatch -- $path`)
Expand Down
2 changes: 1 addition & 1 deletion base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ end

_is_str_expr(ex) =
isa(ex,Expr) && ex.head==:macrocall && isa(ex.args[1],Symbol) &&
(ex.args[1] == :str || ends_with(string(ex.args[1]),"_str"))
(ex.args[1] == :str || endswith(string(ex.args[1]),"_str"))

macro printf(args...)
if length(args) == 0
Expand Down
2 changes: 1 addition & 1 deletion base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function librandom_init()
seed = reinterpret(Uint64, time())
seed = bitmix(seed, uint64(getpid()))
try
seed = bitmix(seed, parse_int(Uint64, readall(`ifconfig`|`sha1sum`)[1:40], 16))
seed = bitmix(seed, parseint(Uint64, readall(`ifconfig`|`sha1sum`)[1:40], 16))
catch
# ignore
end
Expand Down
60 changes: 26 additions & 34 deletions base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ hash(s::String) = hash(bytestring(s))

# begins with and ends with predicates

function begins_with(a::String, b::String)
function beginswith(a::String, b::String)
i = start(a)
j = start(b)
while !done(a,i) && !done(b,i)
Expand All @@ -240,9 +240,9 @@ function begins_with(a::String, b::String)
end
done(b,i)
end
begins_with(a::String, c::Char) = !isempty(a) && a[start(a)] == c
beginswith(a::String, c::Char) = !isempty(a) && a[start(a)] == c

function ends_with(a::String, b::String)
function endswith(a::String, b::String)
i = endof(a)
j = endof(b)
a1 = start(a)
Expand All @@ -256,17 +256,17 @@ function ends_with(a::String, b::String)
end
j < b1
end
ends_with(a::String, c::Char) = !isempty(a) && a[end] == c
endswith(a::String, c::Char) = !isempty(a) && a[end] == c

# faster comparisons for byte strings

cmp(a::ByteString, b::ByteString) = cmp(a.data, b.data)
isequal(a::ByteString, b::ByteString) = endof(a)==endof(b) && cmp(a,b)==0
begins_with(a::ByteString, b::ByteString) = begins_with(a.data, b.data)
beginswith(a::ByteString, b::ByteString) = beginswith(a.data, b.data)

begins_with(a::Array{Uint8,1}, b::Array{Uint8,1}) = (length(a) >= length(b) && ccall(:strncmp, Int32, (Ptr{Uint8}, Ptr{Uint8}, Uint), a, b, length(b)) == 0)
beginswith(a::Array{Uint8,1}, b::Array{Uint8,1}) = (length(a) >= length(b) && ccall(:strncmp, Int32, (Ptr{Uint8}, Ptr{Uint8}, Uint), a, b, length(b)) == 0)

# TODO: fast ends_with
# TODO: fast endswith

## character column width function ##

Expand Down Expand Up @@ -1052,7 +1052,7 @@ strip(s::String, chars::String) = lstrip(rstrip(s, chars), chars)

## string to integer functions ##

function parse_int{T<:Integer}(::Type{T}, s::String, base::Integer)
function parseint{T<:Integer}(::Type{T}, s::String, base::Integer)
if !(2 <= base <= 36); error("invalid base: ",base); end
i = start(s)
while true
Expand Down Expand Up @@ -1118,32 +1118,24 @@ function parse_int{T<:Integer}(::Type{T}, s::String, base::Integer)
return n
end

parse_int(s::String, base::Integer) = parse_int(Int,s,base)
parse_int(T::Type, s::String) = parse_int(T,s,10)
parse_int(s::String) = parse_int(Int,s,10)

parse_bin(T::Type, s::String) = parse_int(T,s,2)
parse_oct(T::Type, s::String) = parse_int(T,s,8)
parse_hex(T::Type, s::String) = parse_int(T,s,16)

parse_bin(s::String) = parse_int(Int,s,2)
parse_oct(s::String) = parse_int(Int,s,8)
parse_hex(s::String) = parse_int(Int,s,16)
parseint(s::String, base::Integer) = parseint(Int,s,base)
parseint(T::Type, s::String) = parseint(T,s,10)
parseint(s::String) = parseint(Int,s,10)

integer (s::String) = int(s)
unsigned(s::String) = uint(s)
int (s::String) = parse_int(Int,s)
uint (s::String) = parse_int(Uint,s)
int8 (s::String) = parse_int(Int8,s)
uint8 (s::String) = parse_int(Uint8,s)
int16 (s::String) = parse_int(Int16,s)
uint16 (s::String) = parse_int(Uint16,s)
int32 (s::String) = parse_int(Int32,s)
uint32 (s::String) = parse_int(Uint32,s)
int64 (s::String) = parse_int(Int64,s)
uint64 (s::String) = parse_int(Uint64,s)
int128 (s::String) = parse_int(Int128,s)
uint128 (s::String) = parse_int(Uint128,s)
int (s::String) = parseint(Int,s)
uint (s::String) = parseint(Uint,s)
int8 (s::String) = parseint(Int8,s)
uint8 (s::String) = parseint(Uint8,s)
int16 (s::String) = parseint(Int16,s)
uint16 (s::String) = parseint(Uint16,s)
int32 (s::String) = parseint(Int32,s)
uint32 (s::String) = parseint(Uint32,s)
int64 (s::String) = parseint(Int64,s)
uint64 (s::String) = parseint(Uint64,s)
int128 (s::String) = parseint(Int128,s)
uint128 (s::String) = parseint(Uint128,s)

## stringifying integers more efficiently ##

Expand Down Expand Up @@ -1176,9 +1168,9 @@ begin
end

float(x::String) = float64(x)
parse_float(x::String) = float64(x)
parse_float(::Type{Float64}, x::String) = float64(x)
parse_float(::Type{Float32}, x::String) = float32(x)
parsefloat(x::String) = float64(x)
parsefloat(::Type{Float64}, x::String) = float64(x)
parsefloat(::Type{Float32}, x::String) = float32(x)

for conv in (:float, :float32, :float64,
:int, :int8, :int16, :int32, :int64,
Expand Down
4 changes: 2 additions & 2 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ precompile(unshift!, (Array{WorkItem,1}, WorkItem))
precompile(enq_work, (WorkItem,))
precompile(pop!, (Array{WorkItem,1},))
precompile(string, (Int,))
precompile(parse_int, (Type{Int}, ASCIIString, Int))
precompile(parseint, (Type{Int}, ASCIIString, Int))
precompile(repeat, (ASCIIString, Int))
precompile(KeyError, (Int,))
precompile(show, (Float64,))
Expand Down Expand Up @@ -286,7 +286,7 @@ precompile(split, (ASCIIString,))
precompile(split, (ASCIIString, ASCIIString, Int, Bool))
precompile(split, (ASCIIString, Regex, Int, Bool))
precompile(print_joined, (IOStream, Array{String,1}, ASCIIString))
precompile(begins_with, (ASCIIString, ASCIIString))
precompile(beginswith, (ASCIIString, ASCIIString))
precompile(resolve_globals, (Symbol, Module, Module, Vector{Any}, Vector{Any}))
precompile(resolve_globals, (SymbolNode, Module, Module, Vector{Any}, Vector{Any}))
precompile(BitArray, (Int,))
Expand Down
2 changes: 1 addition & 1 deletion base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function split_idents(s::String)
idents = split(s, '.')
ntuple(length(idents)) do i
ident = idents[i]
ismatch(r"^\d+$", ident) ? parse_int(ident) : ident
ismatch(r"^\d+$", ident) ? parseint(ident) : ident
end
end

Expand Down
31 changes: 5 additions & 26 deletions doc/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1007,13 +1007,13 @@
"),

("Strings","Base","begins_with","begins_with(string, prefix)
("Strings","Base","beginswith","beginswith(string, prefix)
Returns \"true\" if \"string\" starts with \"prefix\".
"),

("Strings","Base","ends_with","ends_with(string, suffix)
("Strings","Base","endswith","endswith(string, suffix)
Returns \"true\" if \"string\" ends with \"suffix\".
Expand Down Expand Up @@ -2605,35 +2605,14 @@
"),

("Data Formats","Base","parse_int","parse_int(type, str[, base])
("Data Formats","Base","parseint","parseint([type], str[, base])
Parse a string as an integer in the given base (default 10),
yielding a number of the specified type.
yielding a number of the specified type (default \"Int\").
"),

("Data Formats","Base","parse_bin","parse_bin(type, str)
Parse a string as an integer in base 2, yielding a number of the
specified type.
"),

("Data Formats","Base","parse_oct","parse_oct(type, str)
Parse a string as an integer in base 8, yielding a number of the
specified type.
"),

("Data Formats","Base","parse_hex","parse_hex(type, str)
Parse a string as an integer in base 16, yielding a number of the
specified type.
"),

("Data Formats","Base","parse_float","parse_float(type, str)
("Data Formats","Base","parsefloat","parsefloat([type], str)
Parse a string as a decimal floating point number, yielding a
number of the specified type.
Expand Down
Loading

1 comment on commit 70a8f39

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Great Underscore Purge of 2013.

Please sign in to comment.