Skip to content

Commit 70a8f39

Browse files
committed
remove underscores from begins_with, ends_with, parse_int, parse_float
remove parse_bin, parse_oct, parse_hex ref #1539
1 parent b8e41d1 commit 70a8f39

23 files changed

+173
-203
lines changed

base/client.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function process_options(args::Array{Any,1})
225225
# load juliarc now before processing any more options
226226
try_include(string(ENV["HOME"],"/.juliarc.jl"))
227227
startup = false
228-
elseif begins_with(args[i], "--color")
228+
elseif beginswith(args[i], "--color")
229229
if args[i] == "--color"
230230
color_set = true
231231
global have_color = true
@@ -332,7 +332,7 @@ function _start()
332332
startup && try_include(joinpath(ENV["HOME"],".juliarc.jl"))
333333

334334
if !color_set
335-
@unix_only global have_color = (begins_with(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`))
335+
@unix_only global have_color = (beginswith(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`))
336336
@windows_only global have_color = true
337337
end
338338

base/datafmt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function dlm_readrow(io::IO, dlm, eol::Char)
1212
else
1313
row = split(row_string, dlm, true)
1414
end
15-
if ends_with(row[end], eol)
15+
if endswith(row[end], eol)
1616
row[end] = chop(row[end])
1717
end
1818
row

base/deprecated.jl

+10
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ export PipeString
162162
@deprecate each_match eachmatch
163163
@deprecate function_loc functionloc
164164
@deprecate compile_hint precompile
165+
@deprecate begins_with beginswith
166+
@deprecate ends_with endswidth
167+
@deprecate parse_float parsefloat
168+
@deprecate parse_int parseint
169+
@deprecate parse_bin(T,s) parseint(T,s,2)
170+
@deprecate parse_bin(s) parseint(s,2)
171+
@deprecate parse_oct(T,s) parseint(T,s,8)
172+
@deprecate parse_oct(s) parseint(s,8)
173+
@deprecate parse_hex(T,s) parseint(T,s,16)
174+
@deprecate parse_hex(s) parseint(s,16)
165175

166176
@deprecate expr(hd, a...) Expr(hd, a...)
167177
@deprecate expr(hd, a::Array{Any,1}) Expr(hd, a...)

base/env.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ end
133133

134134
## misc environment-related functionality ##
135135

136-
tty_cols() = parse_int(Int32, get(ENV,"COLUMNS","80"), 10)
137-
tty_rows() = parse_int(Int32, get(ENV,"LINES","25"), 10)
136+
tty_cols() = parseint(Int32, get(ENV,"COLUMNS","80"), 10)
137+
tty_rows() = parseint(Int32, get(ENV,"LINES","25"), 10)

base/exports.jl

+4-7
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,15 @@ export
699699

700700
# strings and text output
701701
ascii,
702-
begins_with,
702+
beginswith,
703703
char,
704704
charwidth,
705705
chomp,
706706
chop,
707707
chr2ind,
708708
bytestring,
709709
eachmatch,
710-
ends_with,
710+
endswith,
711711
escape_string,
712712
first_utf8_byte,
713713
ind2chr,
@@ -762,11 +762,8 @@ export
762762
ndigits,
763763
ndigits0z,
764764
oct,
765-
parse_bin,
766-
parse_float,
767-
parse_hex,
768-
parse_int,
769-
parse_oct,
765+
parsefloat,
766+
parseint,
770767
print,
771768
print_escaped,
772769
print_joined,

base/floatfuncs.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ num2hex(x::Float64) = hex(box(Uint64,unbox(Float64,x)),16)
3636

3737
function hex2num(s::String)
3838
if length(s) <= 8
39-
return box(Float32,unbox(Int32,parse_hex(Int32,s)))
39+
return box(Float32,unbox(Int32,parseint(Int32,s,16)))
4040
end
41-
return box(Float64,unbox(Int64,parse_hex(Int64,s)))
41+
return box(Float64,unbox(Int64,parseint(Int64,s,16)))
4242
end
4343

4444
@vectorize_1arg Real iround

base/git.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ function merge_configs(Bc::Dict, Lc::Dict, Rc::Dict)
147147
# expunge removed submodules from left and right sides
148148
deleted = Set{ByteString}()
149149
for section in Bs - Ls & Rs
150-
filter!((k,v)->!begins_with(k,"$section."),Lc)
151-
filter!((k,v)->!begins_with(k,"$section."),Rc)
150+
filter!((k,v)->!beginswith(k,"$section."),Lc)
151+
filter!((k,v)->!beginswith(k,"$section."),Rc)
152152
add!(deleted, section)
153153
end
154154
# merge the remaining config key-value pairs

base/help.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717
function decor_help_desc(func::String, mfunc::String, desc::String)
1818
sd = split(desc, '\n')
1919
for i = 1:length(sd)
20-
if begins_with(sd[i], func)
20+
if beginswith(sd[i], func)
2121
sd[i] = mfunc * sd[i][length(func)+1:end]
2222
else
2323
break
@@ -54,7 +54,7 @@ function init_help()
5454
CATEGORY_DICT[cat] = {}
5555
end
5656
if !isempty(mod)
57-
if begins_with(func, '@')
57+
if beginswith(func, '@')
5858
mfunc = "@" * mod * "." * func[2:]
5959
else
6060
mfunc = mod * "." * func
@@ -133,7 +133,7 @@ function help_for(fname::String, obj)
133133
found = true
134134
else
135135
macrocall = ""
136-
if begins_with(fname, '@')
136+
if beginswith(fname, '@')
137137
sfname = fname[2:]
138138
macrocall = "@"
139139
else

base/loading.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function find_in_path(name::String)
99
name[1] == '/' && return abspath(name)
1010
isfile(name) && return abspath(name)
1111
base = name
12-
if ends_with(name,".jl")
12+
if endswith(name,".jl")
1313
base = match(r"^(.*)\.jl$",name).captures[1]
1414
else
1515
name = string(base,".jl")

base/multi.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ end
947947
function parse_connection_info(str)
948948
m = match(r"^julia_worker:(\d+)#(.*)", str)
949949
if m != nothing
950-
(m.captures[2], parse_int(Int16, m.captures[1]))
950+
(m.captures[2], parseint(Int16, m.captures[1]))
951951
else
952952
("", int16(-1))
953953
end

base/pkg.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ pull() = cd_pkgdir() do
512512
end
513513
# remove submodules that were deleted
514514
for section in deleted
515-
if !begins_with(section,"submodule.") continue end
515+
if !beginswith(section,"submodule.") continue end
516516
path = get(Lc,"$section.path",nothing)
517517
if path == nothing continue end
518518
run(`git rm -qrf --cached --ignore-unmatch -- $path`)

base/printf.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ end
754754

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

759759
macro printf(args...)
760760
if length(args) == 0

base/random.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function librandom_init()
5555
seed = reinterpret(Uint64, time())
5656
seed = bitmix(seed, uint64(getpid()))
5757
try
58-
seed = bitmix(seed, parse_int(Uint64, readall(`ifconfig`|`sha1sum`)[1:40], 16))
58+
seed = bitmix(seed, parseint(Uint64, readall(`ifconfig`|`sha1sum`)[1:40], 16))
5959
catch
6060
# ignore
6161
end

base/string.jl

+26-34
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ hash(s::String) = hash(bytestring(s))
230230

231231
# begins with and ends with predicates
232232

233-
function begins_with(a::String, b::String)
233+
function beginswith(a::String, b::String)
234234
i = start(a)
235235
j = start(b)
236236
while !done(a,i) && !done(b,i)
@@ -240,9 +240,9 @@ function begins_with(a::String, b::String)
240240
end
241241
done(b,i)
242242
end
243-
begins_with(a::String, c::Char) = !isempty(a) && a[start(a)] == c
243+
beginswith(a::String, c::Char) = !isempty(a) && a[start(a)] == c
244244

245-
function ends_with(a::String, b::String)
245+
function endswith(a::String, b::String)
246246
i = endof(a)
247247
j = endof(b)
248248
a1 = start(a)
@@ -256,17 +256,17 @@ function ends_with(a::String, b::String)
256256
end
257257
j < b1
258258
end
259-
ends_with(a::String, c::Char) = !isempty(a) && a[end] == c
259+
endswith(a::String, c::Char) = !isempty(a) && a[end] == c
260260

261261
# faster comparisons for byte strings
262262

263263
cmp(a::ByteString, b::ByteString) = cmp(a.data, b.data)
264264
isequal(a::ByteString, b::ByteString) = endof(a)==endof(b) && cmp(a,b)==0
265-
begins_with(a::ByteString, b::ByteString) = begins_with(a.data, b.data)
265+
beginswith(a::ByteString, b::ByteString) = beginswith(a.data, b.data)
266266

267-
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)
267+
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)
268268

269-
# TODO: fast ends_with
269+
# TODO: fast endswith
270270

271271
## character column width function ##
272272

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

10531053
## string to integer functions ##
10541054

1055-
function parse_int{T<:Integer}(::Type{T}, s::String, base::Integer)
1055+
function parseint{T<:Integer}(::Type{T}, s::String, base::Integer)
10561056
if !(2 <= base <= 36); error("invalid base: ",base); end
10571057
i = start(s)
10581058
while true
@@ -1118,32 +1118,24 @@ function parse_int{T<:Integer}(::Type{T}, s::String, base::Integer)
11181118
return n
11191119
end
11201120

1121-
parse_int(s::String, base::Integer) = parse_int(Int,s,base)
1122-
parse_int(T::Type, s::String) = parse_int(T,s,10)
1123-
parse_int(s::String) = parse_int(Int,s,10)
1124-
1125-
parse_bin(T::Type, s::String) = parse_int(T,s,2)
1126-
parse_oct(T::Type, s::String) = parse_int(T,s,8)
1127-
parse_hex(T::Type, s::String) = parse_int(T,s,16)
1128-
1129-
parse_bin(s::String) = parse_int(Int,s,2)
1130-
parse_oct(s::String) = parse_int(Int,s,8)
1131-
parse_hex(s::String) = parse_int(Int,s,16)
1121+
parseint(s::String, base::Integer) = parseint(Int,s,base)
1122+
parseint(T::Type, s::String) = parseint(T,s,10)
1123+
parseint(s::String) = parseint(Int,s,10)
11321124

11331125
integer (s::String) = int(s)
11341126
unsigned(s::String) = uint(s)
1135-
int (s::String) = parse_int(Int,s)
1136-
uint (s::String) = parse_int(Uint,s)
1137-
int8 (s::String) = parse_int(Int8,s)
1138-
uint8 (s::String) = parse_int(Uint8,s)
1139-
int16 (s::String) = parse_int(Int16,s)
1140-
uint16 (s::String) = parse_int(Uint16,s)
1141-
int32 (s::String) = parse_int(Int32,s)
1142-
uint32 (s::String) = parse_int(Uint32,s)
1143-
int64 (s::String) = parse_int(Int64,s)
1144-
uint64 (s::String) = parse_int(Uint64,s)
1145-
int128 (s::String) = parse_int(Int128,s)
1146-
uint128 (s::String) = parse_int(Uint128,s)
1127+
int (s::String) = parseint(Int,s)
1128+
uint (s::String) = parseint(Uint,s)
1129+
int8 (s::String) = parseint(Int8,s)
1130+
uint8 (s::String) = parseint(Uint8,s)
1131+
int16 (s::String) = parseint(Int16,s)
1132+
uint16 (s::String) = parseint(Uint16,s)
1133+
int32 (s::String) = parseint(Int32,s)
1134+
uint32 (s::String) = parseint(Uint32,s)
1135+
int64 (s::String) = parseint(Int64,s)
1136+
uint64 (s::String) = parseint(Uint64,s)
1137+
int128 (s::String) = parseint(Int128,s)
1138+
uint128 (s::String) = parseint(Uint128,s)
11471139

11481140
## stringifying integers more efficiently ##
11491141

@@ -1176,9 +1168,9 @@ begin
11761168
end
11771169

11781170
float(x::String) = float64(x)
1179-
parse_float(x::String) = float64(x)
1180-
parse_float(::Type{Float64}, x::String) = float64(x)
1181-
parse_float(::Type{Float32}, x::String) = float32(x)
1171+
parsefloat(x::String) = float64(x)
1172+
parsefloat(::Type{Float64}, x::String) = float64(x)
1173+
parsefloat(::Type{Float32}, x::String) = float32(x)
11821174

11831175
for conv in (:float, :float32, :float64,
11841176
:int, :int8, :int16, :int32, :int64,

base/sysimg.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ precompile(unshift!, (Array{WorkItem,1}, WorkItem))
219219
precompile(enq_work, (WorkItem,))
220220
precompile(pop!, (Array{WorkItem,1},))
221221
precompile(string, (Int,))
222-
precompile(parse_int, (Type{Int}, ASCIIString, Int))
222+
precompile(parseint, (Type{Int}, ASCIIString, Int))
223223
precompile(repeat, (ASCIIString, Int))
224224
precompile(KeyError, (Int,))
225225
precompile(show, (Float64,))
@@ -286,7 +286,7 @@ precompile(split, (ASCIIString,))
286286
precompile(split, (ASCIIString, ASCIIString, Int, Bool))
287287
precompile(split, (ASCIIString, Regex, Int, Bool))
288288
precompile(print_joined, (IOStream, Array{String,1}, ASCIIString))
289-
precompile(begins_with, (ASCIIString, ASCIIString))
289+
precompile(beginswith, (ASCIIString, ASCIIString))
290290
precompile(resolve_globals, (Symbol, Module, Module, Vector{Any}, Vector{Any}))
291291
precompile(resolve_globals, (SymbolNode, Module, Module, Vector{Any}, Vector{Any}))
292292
precompile(BitArray, (Int,))

base/version.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function split_idents(s::String)
7575
idents = split(s, '.')
7676
ntuple(length(idents)) do i
7777
ident = idents[i]
78-
ismatch(r"^\d+$", ident) ? parse_int(ident) : ident
78+
ismatch(r"^\d+$", ident) ? parseint(ident) : ident
7979
end
8080
end
8181

doc/helpdb.jl

+5-26
Original file line numberDiff line numberDiff line change
@@ -1007,13 +1007,13 @@
10071007
10081008
"),
10091009

1010-
("Strings","Base","begins_with","begins_with(string, prefix)
1010+
("Strings","Base","beginswith","beginswith(string, prefix)
10111011
10121012
Returns \"true\" if \"string\" starts with \"prefix\".
10131013
10141014
"),
10151015

1016-
("Strings","Base","ends_with","ends_with(string, suffix)
1016+
("Strings","Base","endswith","endswith(string, suffix)
10171017
10181018
Returns \"true\" if \"string\" ends with \"suffix\".
10191019
@@ -2605,35 +2605,14 @@
26052605
26062606
"),
26072607

2608-
("Data Formats","Base","parse_int","parse_int(type, str[, base])
2608+
("Data Formats","Base","parseint","parseint([type], str[, base])
26092609
26102610
Parse a string as an integer in the given base (default 10),
2611-
yielding a number of the specified type.
2611+
yielding a number of the specified type (default \"Int\").
26122612
26132613
"),
26142614

2615-
("Data Formats","Base","parse_bin","parse_bin(type, str)
2616-
2617-
Parse a string as an integer in base 2, yielding a number of the
2618-
specified type.
2619-
2620-
"),
2621-
2622-
("Data Formats","Base","parse_oct","parse_oct(type, str)
2623-
2624-
Parse a string as an integer in base 8, yielding a number of the
2625-
specified type.
2626-
2627-
"),
2628-
2629-
("Data Formats","Base","parse_hex","parse_hex(type, str)
2630-
2631-
Parse a string as an integer in base 16, yielding a number of the
2632-
specified type.
2633-
2634-
"),
2635-
2636-
("Data Formats","Base","parse_float","parse_float(type, str)
2615+
("Data Formats","Base","parsefloat","parsefloat([type], str)
26372616
26382617
Parse a string as a decimal floating point number, yielding a
26392618
number of the specified type.

0 commit comments

Comments
 (0)