Skip to content

Commit a06ef4a

Browse files
committed
Rename utf->unicode, merge cstring into utf32, remove RepStrings & RopeStrings
1 parent 79d4aea commit a06ef4a

26 files changed

+70
-154
lines changed

base/RepStrings.jl

Lines changed: 0 additions & 52 deletions
This file was deleted.

base/RopeStrings.jl

Lines changed: 0 additions & 47 deletions
This file was deleted.

base/string.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ include("strings/basic.jl")
44
include("strings/search.jl")
55
include("strings/parse.jl")
66
include("strings/strutil.jl")
7-
include("strings/cstring.jl")
87
include("strings/strio.jl")
98

base/strings/basic.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ eltype{T<:AbstractString}(::Type{T}) = Char
5151
(*)(s1::AbstractString, ss::AbstractString...) = string(s1, ss...)
5252
(^)(s::AbstractString, r::Integer) = repeat(s,r)
5353

54+
function repeat(s::ByteString, r::Integer)
55+
r < 0 && throw(ArgumentError("can't repeat a string $r times"))
56+
d = s.data; n = length(d)
57+
out = Array(UInt8, n*r)
58+
for i=1:r
59+
copy!(out, 1+(i-1)*n, d, 1, n)
60+
end
61+
convert(typeof(s), out)
62+
end
63+
5464
length(s::DirectIndexString) = endof(s)
5565
function length(s::AbstractString)
5666
i = start(s)

base/sysimg.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,9 @@ include("osutils.jl")
9090
# strings & printing
9191
include("SubStrings.jl")
9292
include("RevStrings.jl")
93-
include("RepStrings.jl")
94-
include("RopeStrings.jl")
9593
include("char.jl")
9694
include("ascii.jl")
97-
include("utf.jl")
95+
include("unicode.jl")
9896
include("iobuffer.jl")
9997
include("string.jl")
10098
include("shell.jl")

base/unicode.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file is a part of Julia. License is MIT: http://julialang.org/license
2+
3+
include("unicode/UnicodeError.jl")
4+
include("unicode/types.jl")
5+
include("unicode/checkstring.jl")
6+
include("unicode/utf8.jl")
7+
include("unicode/utf16.jl")
8+
include("unicode/utf32.jl")
9+
include("unicode/utf8proc.jl")
10+
importall .UTF8proc
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

base/utf/utf32.jl renamed to base/unicode/utf32.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,37 @@ function map(f, s::UTF32String)
100100
end
101101
UTF32String(out)
102102
end
103+
104+
# Definitions for C compatible strings, that don't allow embedded
105+
# '\0', and which are terminated by a '\0'
106+
107+
containsnul(s::AbstractString) = '\0' in s
108+
containsnul(s::ByteString) = containsnul(unsafe_convert(Ptr{Cchar}, s), sizeof(s))
109+
containsnul(s::Union{UTF16String,UTF32String}) = findfirst(s.data, 0) != length(s.data)
110+
111+
if sizeof(Cwchar_t) == 2
112+
const WString = UTF16String
113+
const wstring = utf16
114+
elseif sizeof(Cwchar_t) == 4
115+
const WString = UTF32String
116+
const wstring = utf32
117+
end
118+
wstring(s::Cwstring) = wstring(box(Ptr{Cwchar_t}, unbox(Cwstring,s)))
119+
120+
# Cwstring is defined in c.jl, but conversion needs to be defined here
121+
# to have WString
122+
function unsafe_convert(::Type{Cwstring}, s::WString)
123+
if containsnul(s)
124+
throw(ArgumentError("embedded NUL chars are not allowed in C strings: $(repr(s))"))
125+
end
126+
return Cwstring(unsafe_convert(Ptr{Cwchar_t}, s))
127+
end
128+
129+
# pointer conversions of ASCII/UTF8/UTF16/UTF32 strings:
130+
pointer(x::Union{ByteString,UTF16String,UTF32String}) = pointer(x.data)
131+
pointer{T<:ByteString}(x::SubString{T}) = pointer(x.string.data) + x.offset
132+
pointer(x::ByteString, i::Integer) = pointer(x.data)+(i-1)
133+
pointer{T<:ByteString}(x::SubString{T}, i::Integer) = pointer(x.string.data) + x.offset + (i-1)
134+
pointer(x::Union{UTF16String,UTF32String}, i::Integer) = pointer(x)+(i-1)*sizeof(eltype(x.data))
135+
pointer{T<:Union{UTF16String,UTF32String}}(x::SubString{T}) = pointer(x.string.data) + x.offset*sizeof(eltype(x.data))
136+
pointer{T<:Union{UTF16String,UTF32String}}(x::SubString{T}, i::Integer) = pointer(x.string.data) + (x.offset + (i-1))*sizeof(eltype(x.data))
File renamed without changes.
File renamed without changes.

base/utf.jl

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/RepStrings.jl

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/RopeStrings.jl

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/choosetests.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ Upon return, `tests` is a vector of fully-expanded test names, and
1515
""" ->
1616
function choosetests(choices = [])
1717
testnames = [
18-
"linalg", "core", "keywordargs", "numbers",
19-
"string", "utf", "triplequote", "printf",
20-
"RepStrings", "RopeStrings", "SubStrings", "RevStrings",
18+
"linalg", "core", "keywordargs", "numbers", "string", "unicode", "char",
19+
"SubStrings", "RevStrings", "triplequote", "printf",
2120
"dates", "dict", "hashing", "remote", "iobuffer", "staged",
2221
"arrayops", "tuple", "subarray", "reduce", "reducedim", "random",
2322
"abstractarray", "intfuncs", "simdloop", "blas", "sparse",
@@ -31,7 +30,7 @@ function choosetests(choices = [])
3130
"euler", "show", "lineedit", "replcompletions", "repl",
3231
"replutil", "sets", "test", "goto", "llvmcall", "grisu",
3332
"nullable", "meta", "profile", "libgit2", "docs", "markdown",
34-
"base64", "parser", "serialize", "functors", "char", "misc",
33+
"base64", "parser", "serialize", "functors", "misc",
3534
"enums", "cmdlineargs", "i18n"
3635
]
3736

test/hashing.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ for a in vals, b in vals
7979
@test isequal(a,b) == (hash(a)==hash(b))
8080
end
8181

82-
@test hash(RopeString("1","2")) == hash("12")
8382
@test hash(SubString("--hello--",3,7)) == hash("hello")
8483
@test hash(:(X.x)) == hash(:(X.x))
8584
@test hash(:(X.x)) != hash(:(X.y))

test/string.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ include("strings/basic.jl")
44
include("strings/search.jl")
55
include("strings/parse.jl")
66
include("strings/strutil.jl")
7-
include("strings/cstring.jl")
87
include("strings/strio.jl")

test/strings/cstring.jl

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/unicode.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file is a part of Julia. License is MIT: http://julialang.org/license
2+
3+
include("unicode/checkstring.jl")
4+
include("unicode/utf16.jl")
5+
include("unicode/utf32.jl")
6+
include("unicode/utf8proc.jl")
File renamed without changes.
File renamed without changes.

test/utf/utf32.jl renamed to test/unicode/utf32.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ u32 = utf32(u8)
1111
@test u8 == utf32(u32.data[1:end-1]) == utf32(copy!(Array(UInt8, 20), 1, reinterpret(UInt8, u32.data), 1, 20))
1212
@test u8 == utf32(pointer(u32)) == utf32(convert(Ptr{Int32}, pointer(u32)))
1313
@test_throws UnicodeError utf32(UInt8[1,2,3])
14+
15+
# Wstring
16+
u8 = "\U10ffff\U1d565\U1d7f6\U00066\U2008a"
17+
w = wstring(u8)
18+
@test length(w) == 5 && utf8(w) == u8 && collect(u8) == collect(w)
19+
@test u8 == WString(w.data)
File renamed without changes.

test/utf.jl

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)