@@ -14,17 +14,6 @@ bytestring() = ""
14
14
bytestring (s:: Vector{UInt8} ) =
15
15
ccall (:jl_pchar_to_string , Ref{ByteString}, (Ptr{UInt8},Int), s, length (s))
16
16
17
- function bytestring (p:: Union{Ptr{UInt8},Ptr{Int8}} )
18
- p == C_NULL && throw (ArgumentError (" cannot convert NULL to string" ))
19
- ccall (:jl_cstr_to_string , Ref{String}, (Cstring,), p)
20
- end
21
- bytestring (s:: Cstring ) = bytestring (convert (Ptr{UInt8}, s))
22
-
23
- function bytestring (p:: Union{Ptr{UInt8},Ptr{Int8}} ,len:: Integer )
24
- p == C_NULL && throw (ArgumentError (" cannot convert NULL to string" ))
25
- ccall (:jl_pchar_to_string , Ref{String}, (Ptr{UInt8},Int), p, len)
26
- end
27
-
28
17
convert (:: Type{Vector{UInt8}} , s:: AbstractString ) = bytestring (s). data
29
18
convert (:: Type{Array{UInt8}} , s:: AbstractString ) = bytestring (s). data
30
19
convert (:: Type{String} , s:: AbstractString ) = bytestring (s)
@@ -53,6 +42,7 @@ eltype{T<:AbstractString}(::Type{T}) = Char
53
42
(.* ){T<: AbstractString }(s:: AbstractString ,v:: Vector{T} ) = [s* i for i in v]
54
43
55
44
length (s:: DirectIndexString ) = endof (s)
45
+
56
46
function length (s:: AbstractString )
57
47
i = start (s)
58
48
if done (s,i)
91
81
== (a:: AbstractString , b:: AbstractString ) = cmp (a,b) == 0
92
82
isless (a:: AbstractString , b:: AbstractString ) = cmp (a,b) < 0
93
83
94
- # faster comparisons for byte strings and symbols
95
-
96
- cmp (a:: String , b:: String ) = lexcmp (a. data, b. data)
97
- cmp (a:: Symbol , b:: Symbol ) = Int (sign (ccall (:strcmp , Int32, (Cstring, Cstring), a, b)))
98
-
99
- == (a:: String , b:: String ) = endof (a) == endof (b) && cmp (a,b) == 0
100
- isless (a:: Symbol , b:: Symbol ) = cmp (a,b) < 0
101
-
102
84
# # Generic validation functions ##
103
85
104
86
isvalid (s:: DirectIndexString , i:: Integer ) = (start (s) <= i <= endof (s))
116
98
# # Generic indexing functions ##
117
99
118
100
prevind (s:: DirectIndexString , i:: Integer ) = i- 1
119
- prevind (s:: AbstractArray , i:: Integer ) = i- 1
101
+ prevind (s:: AbstractArray , i:: Integer ) = i- 1
120
102
nextind (s:: DirectIndexString , i:: Integer ) = i+ 1
121
- nextind (s:: AbstractArray , i:: Integer ) = i+ 1
103
+ nextind (s:: AbstractArray , i:: Integer ) = i+ 1
122
104
123
105
function prevind (s:: AbstractString , i:: Integer )
124
106
e = endof (s)
@@ -207,28 +189,15 @@ typealias ByteArray Union{Vector{UInt8},Vector{Int8}}
207
189
208
190
strwidth (s:: AbstractString ) = (w= 0 ; for c in s; w += charwidth (c); end ; w)
209
191
210
- isascii (c:: Char ) = c < Char (0x80 )
211
192
isascii (s:: AbstractString ) = all (isascii, s)
212
193
213
194
# # string promotion rules ##
214
195
215
196
promote_rule {S<:AbstractString,T<:AbstractString} (:: Type{S} , :: Type{T} ) = String
216
197
217
- isxdigit (c:: Char ) = ' 0' <= c<= ' 9' || ' a' <= c<= ' f' || ' A' <= c<= ' F'
218
198
isxdigit (s:: AbstractString ) = all (isxdigit, s)
219
199
need_full_hex (s:: AbstractString , i:: Int ) = ! done (s,i) && isxdigit (next (s,i)[1 ])
220
200
221
- # # checking UTF-8 & ACSII validity ##
222
-
223
- byte_string_classify (data:: Vector{UInt8} ) =
224
- ccall (:u8_isvalid , Int32, (Ptr{UInt8}, Int), data, length (data))
225
- byte_string_classify (s:: String ) = byte_string_classify (s. data)
226
- # 0: neither valid ASCII nor UTF-8
227
- # 1: valid ASCII
228
- # 2: valid UTF-8
229
-
230
- isvalid (:: Type{String} , s:: Union{Vector{UInt8},String} ) = byte_string_classify (s) != 0
231
-
232
201
# # uppercase and lowercase transformations ##
233
202
uppercase (s:: AbstractString ) = map (uppercase, s)
234
203
lowercase (s:: AbstractString ) = map (lowercase, s)
0 commit comments