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