-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,715 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
name = "StyledStrings" | ||
uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b" | ||
authors = ["TEC <[email protected]>"] | ||
version = "1.11.0" | ||
version = "1.0.0" | ||
|
||
[deps] | ||
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" | ||
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" | ||
|
||
[compat] | ||
julia = "1.11" | ||
TOML = "1" | ||
julia = "1" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
@static if VERSION < v"1.1" | ||
isnothing(x) = x === nothing | ||
end | ||
|
||
@static if VERSION < v"1.2" | ||
ncodeunits(s::AbstractString) = Base.ncodeunits(s) | ||
ncodeunits(c::AbstractChar) = Base.ncodeunits(string(c)) | ||
elseif AnnotatedStrings != @__MODULE__ | ||
const ncodeunits = Base.ncodeunits | ||
end | ||
|
||
@static if VERSION < v"1.3" | ||
function _str_sizehint(x) | ||
if x isa Float64 | ||
return 20 | ||
elseif x isa Float32 | ||
return 12 | ||
elseif x isa String || x isa SubString{String} | ||
return sizeof(x) | ||
elseif x isa Char | ||
return ncodeunits(x) | ||
else | ||
return 8 | ||
end | ||
end | ||
else | ||
import Base._str_sizehint | ||
end | ||
|
||
@static if VERSION < v"1.3" | ||
function unescape_string(io::IO, s::AbstractString, keep = ()) | ||
a = Iterators.Stateful(s) | ||
for c in a | ||
if !isempty(a) && c == '\\' | ||
c = popfirst!(a) | ||
if c in keep | ||
print(io, '\\', c) | ||
elseif c == 'x' || c == 'u' || c == 'U' | ||
n = k = 0 | ||
m = c == 'x' ? 2 : | ||
c == 'u' ? 4 : 8 | ||
while (k += 1) <= m && !isempty(a) | ||
nc = peek(a) | ||
n = '0' <= nc <= '9' ? n<<4 + (nc-'0') : | ||
'a' <= nc <= 'f' ? n<<4 + (nc-'a'+10) : | ||
'A' <= nc <= 'F' ? n<<4 + (nc-'A'+10) : break | ||
popfirst!(a) | ||
end | ||
if k == 1 || n > 0x10ffff | ||
u = m == 4 ? 'u' : 'U' | ||
throw(ArgumentError("invalid $(m == 2 ? "hex (\\x)" : | ||
"unicode (\\$u)") escape sequence")) | ||
end | ||
if m == 2 # \x escape sequence | ||
write(io, UInt8(n)) | ||
else | ||
print(io, Char(n)) | ||
end | ||
elseif '0' <= c <= '7' | ||
k = 1 | ||
n = c-'0' | ||
while (k += 1) <= 3 && !isempty(a) | ||
c = peek(a) | ||
n = ('0' <= c <= '7') ? n<<3 + c-'0' : break | ||
popfirst!(a) | ||
end | ||
if n > 255 | ||
throw(ArgumentError("octal escape sequence out of range")) | ||
end | ||
write(io, UInt8(n)) | ||
else | ||
print(io, c == 'a' ? '\a' : | ||
c == 'b' ? '\b' : | ||
c == 't' ? '\t' : | ||
c == 'n' ? '\n' : | ||
c == 'v' ? '\v' : | ||
c == 'f' ? '\f' : | ||
c == 'r' ? '\r' : | ||
c == 'e' ? '\e' : | ||
(c == '\\' || c == '"') ? c : | ||
throw(ArgumentError("invalid escape sequence \\$c"))) | ||
end | ||
else | ||
print(io, c) | ||
end | ||
end | ||
end | ||
unescape_string(s::AbstractString, keep = ()) = | ||
sprint(unescape_string, s, keep; sizehint=lastindex(s)) | ||
end | ||
|
||
@static if VERSION < v"1.4" | ||
function takewhile(f::Function, itr) | ||
taken = Vector{eltype(itr)}() | ||
next = iterate(itr) | ||
while !isnothing(next) && ((item, state) = next) |> first |> f | ||
push!(taken, item) | ||
next = iterate(itr, state) | ||
end | ||
taken | ||
end | ||
else | ||
const takewhile = Iterators.takewhile | ||
end | ||
|
||
@static if VERSION < v"1.5" | ||
function peek(s::Iterators.Stateful, sentinel=nothing) | ||
ns = s.nextvalstate | ||
return ns !== nothing ? ns[1] : sentinel | ||
end | ||
end | ||
|
||
@static if VERSION < v"1.6" | ||
function parseatom(text::AbstractString, pos::Integer) | ||
Meta.parse(text, pos, greedy = false) | ||
end | ||
else | ||
const parseatom = Meta.parseatom | ||
end | ||
|
||
@static if VERSION < v"1.11" | ||
function generating_output(incremental::Union{Bool,Nothing}=nothing) | ||
ccall(:jl_generating_output, Cint, ()) == 0 && return false | ||
if incremental !== nothing | ||
Base.JLOptions().incremental == incremental || return false | ||
end | ||
return true | ||
end | ||
else | ||
const generating_output = Base.generating_output | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.