From 057650bcfb6dab7a0b10f9c5873d450ffabcf6f7 Mon Sep 17 00:00:00 2001 From: tan Date: Mon, 10 Nov 2014 11:40:36 +0530 Subject: [PATCH] add compat for rsplit, updated readme --- README.md | 4 ++++ src/Compat.jl | 18 +++++++++--------- test/runtests.jl | 5 +++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4a41c1b950937..c92ed779fa587 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,14 @@ Currently, the `@compat` macro supports the following syntaxes: * `@compat split(str, splitter; keywords...)` - the Julia 0.4-style keyword-based `split` function +* `@compat rsplit(str, splitter; keywords...)` - the Julia 0.4-style keyword-based `rsplit` function + ## Type Aliases * `typealias AbstractString String` - `String` has been renamed to `AbstractString` [#8872](https://github.com/JuliaLang/julia/pull/8872) +* For all unsigned integer types to their equivalents with uppercase `I`. [#8907](https://github.com/JuliaLang/julia/pull/8907) + ## Renamed functions * `itrunc`, `iround`, `iceil`, `ifloor` are now accessed via `trunc(T, x)`, etc. [#9133](https://github.com/JuliaLang/julia/pull/9133) diff --git a/src/Compat.jl b/src/Compat.jl index 31f08259d1aad..fe863e740f3e3 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -67,9 +67,9 @@ function rewrite_dict(ex) newex end -# rewrite Julia 0.4-style split(str, splitter; kws...) into 0.2/0.3-style -# positional arguments -function rewrite_split(ex) +# rewrite Julia 0.4-style split or rsplit (str, splitter; kws...) +# into 0.2/0.3-style positional arguments +function rewrite_split(ex, f) limit = nothing keep = nothing for i in 4:length(ex.args) @@ -84,15 +84,15 @@ function rewrite_split(ex) end if limit == nothing if keep == nothing - return Expr(:call, :split, ex.args[2], ex.args[3]) + return Expr(:call, f, ex.args[2], ex.args[3]) else - return Expr(:call, :split, ex.args[2], ex.args[3], keep) + return Expr(:call, f, ex.args[2], ex.args[3], keep) end else if keep == nothing - return Expr(:call, :split, ex.args[2], ex.args[3], limit) + return Expr(:call, f, ex.args[2], ex.args[3], limit) else - return Expr(:call, :split, ex.args[2], ex.args[3], limit, keep) + return Expr(:call, f, ex.args[2], ex.args[3], limit, keep) end end end @@ -102,8 +102,8 @@ function _compat(ex::Expr) f = ex.args[1] if VERSION < v"0.4.0-dev+980" && (f == :Dict || (isexpr(f, :curly) && length(f.args) == 3 && f.args[1] == :Dict)) ex = rewrite_dict(ex) - elseif VERSION < v"0.4.0-dev+129" && f == :split && length(ex.args) >= 4 && isexpr(ex.args[4], :kw) - ex = rewrite_split(ex) + elseif VERSION < v"0.4.0-dev+129" && (f == :split || f == :rsplit) && length(ex.args) >= 4 && isexpr(ex.args[4], :kw) + ex = rewrite_split(ex, f) end end return Expr(ex.head, map(_compat, ex.args)...) diff --git a/test/runtests.jl b/test/runtests.jl index f7df52da03d03..3e036ad0b4d3d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -51,6 +51,11 @@ end @test @compat split("a,b,,c", ',', keep=false) == ["a", "b", "c"] @test @compat split("a,b,,c", ',', keep=true) == ["a", "b", "", "c"] +@test @compat rsplit("a,b,,c", ',', limit=2) == ["a,b,", "c"] +@test @compat rsplit("a,b,,c", ',', limit=2,keep=true) == ["a,b,", "c"] +@test @compat rsplit("a,b,,c", ',', keep=false) == ["a", "b", "c"] +@test @compat rsplit("a,b,,c", ',', keep=true) == ["a", "b", "", "c"] + if VERSION < v"0.4.0-dev+1387" @test isdefined(Main, :AbstractString) end