@@ -84,7 +84,6 @@ defmodule StringIO do
84
84
85
85
def init ( { string , options } ) do
86
86
capture_prompt = options [ :capture_prompt ] || false
87
-
88
87
{ :ok , state ( input: string , capture_prompt: capture_prompt ) }
89
88
end
90
89
@@ -161,11 +160,11 @@ defmodule StringIO do
161
160
end
162
161
163
162
defp io_request ( { :setopts , _opts } , s ) do
164
- { :ok , s }
163
+ { { :error , :enotsup } , s }
165
164
end
166
165
167
166
defp io_request ( :getopts , s ) do
168
- { { :error , :enotsup } , s }
167
+ { [ binary: true , encoding: :unicode ] , s }
169
168
end
170
169
171
170
defp io_request ( { :get_geometry , :columns } , s ) do
@@ -200,20 +199,17 @@ defmodule StringIO do
200
199
end
201
200
end
202
201
203
- defp do_get_chars ( "" , _ , _encoding ) do
202
+ defp do_get_chars ( "" , _encoding , _n ) do
204
203
{ :eof , "" }
205
204
end
206
205
207
- defp do_get_chars ( input , n , :latin1 ) when byte_size ( input ) < n do
206
+ defp do_get_chars ( input , :latin1 , n ) when byte_size ( input ) < n do
208
207
{ input , "" }
209
208
end
210
209
211
210
defp do_get_chars ( input , :latin1 , n ) do
212
- if byte_size ( input ) < n do
213
- { input , "" }
214
- else
215
- :erlang . split_binary ( input , n )
216
- end
211
+ << chars :: [ binary , size ( n ) ] , rest :: binary >> = input
212
+ { chars , rest }
217
213
end
218
214
219
215
defp do_get_chars ( input , encoding , n ) do
@@ -222,7 +218,8 @@ defmodule StringIO do
222
218
{ buf_count , split_pos } when buf_count < n or split_pos == :none ->
223
219
{ input , "" }
224
220
{ _buf_count , split_pos } ->
225
- :erlang . split_binary ( input , split_pos )
221
+ << chars :: [ binary , size ( split_pos ) ] , rest :: binary >> = input
222
+ { chars , rest }
226
223
end
227
224
catch
228
225
:exit , :invalid_unicode ->
@@ -266,9 +263,9 @@ defmodule StringIO do
266
263
state ( input: input , output: output , capture_prompt: capture_prompt ) = s ) do
267
264
case :unicode . characters_to_list ( input , encoding ) do
268
265
{ :error , _ , _ } ->
269
- { :error , fun }
266
+ { :error , s }
270
267
{ :incomplete , _ , _ } ->
271
- { :error , fun }
268
+ { :error , s }
272
269
chars ->
273
270
{ result , input , count } = do_get_until ( chars , encoding , mod , fun , args )
274
271
0 commit comments