@@ -1162,13 +1162,7 @@ def read_to_separator
1162
1162
str . clear
1163
1163
end
1164
1164
1165
- s = IO . read_encode ( @io , s )
1166
-
1167
- s . chomp! ( @separator ) if @chomp
1168
- $. = @io . __send__ ( :increment_lineno )
1169
- @buffer . discard @skip if @skip
1170
-
1171
- yield s
1165
+ yield prepare_read_string ( s )
1172
1166
1173
1167
next
1174
1168
else
@@ -1210,10 +1204,7 @@ def read_to_separator
1210
1204
@buffer . put_back ( str . byteslice ( offset , str . bytesize - offset ) )
1211
1205
end
1212
1206
1213
- res = IO . read_encode ( @io , str . byteslice ( 0 , offset ) )
1214
- res . chomp! ( @separator ) if @chomp
1215
- $. = @io . __send__ ( :increment_lineno )
1216
- @buffer . discard @skip if @skip
1207
+ res = prepare_read_string ( str . byteslice ( 0 , offset ) )
1217
1208
1218
1209
str . clear
1219
1210
last_scan_end = 0
@@ -1227,7 +1218,7 @@ def read_to_separator
1227
1218
1228
1219
str << @buffer . shift
1229
1220
str . chomp! ( @separator ) if @chomp
1230
- yield_string ( str ) { | y | yield y }
1221
+ yield prepare_read_string ( str ) unless str . empty?
1231
1222
end
1232
1223
1233
1224
# method B, E
@@ -1245,27 +1236,16 @@ def read_to_separator_with_limit
1245
1236
bytes = Primitive . min ( count , wanted )
1246
1237
str << @buffer . shift ( bytes )
1247
1238
1248
- str = IO . read_encode ( @io , str )
1249
-
1250
- str . chomp! ( @separator ) if @chomp
1251
- $. = @io . __send__ ( :increment_lineno )
1252
- @buffer . discard @skip if @skip
1253
-
1254
- yield str
1239
+ yield prepare_read_string ( str )
1255
1240
1256
1241
str = +''
1257
1242
wanted = limit
1258
1243
else
1259
1244
if wanted < available
1260
1245
str << @buffer . shift ( wanted )
1261
-
1262
1246
str = @buffer . read_to_char_boundary ( @io , str )
1263
1247
1264
- str . chomp! ( @separator ) if @chomp
1265
- $. = @io . __send__ ( :increment_lineno )
1266
- @buffer . discard @skip if @skip
1267
-
1268
- yield str
1248
+ yield prepare_read_string ( str )
1269
1249
1270
1250
str = +''
1271
1251
wanted = limit
@@ -1276,8 +1256,7 @@ def read_to_separator_with_limit
1276
1256
end
1277
1257
end
1278
1258
1279
- str . chomp! ( @separator ) if @chomp
1280
- yield_string ( str ) { |s | yield s }
1259
+ yield prepare_read_string ( str ) unless str . empty?
1281
1260
end
1282
1261
1283
1262
# Method G
@@ -1293,7 +1272,7 @@ def read_all
1293
1272
end
1294
1273
1295
1274
str . chomp! ( DEFAULT_RECORD_SEPARATOR ) if @chomp
1296
- yield_string ( str ) { | s | yield s }
1275
+ yield prepare_read_string ( str ) unless str . empty?
1297
1276
end
1298
1277
1299
1278
# Method H
@@ -1319,15 +1298,17 @@ def read_to_limit
1319
1298
end
1320
1299
end
1321
1300
1322
- yield_string ( str ) { | s | yield s }
1301
+ yield prepare_read_string ( str ) unless str . empty?
1323
1302
end
1324
1303
1325
- def yield_string ( str )
1326
- unless str . empty?
1327
- str = IO . read_encode ( @io , str )
1328
- $. = @io . __send__ ( :increment_lineno )
1329
- yield str
1330
- end
1304
+ def prepare_read_string ( str )
1305
+ s = IO . read_encode ( @io , str )
1306
+
1307
+ s . chomp! ( @separator ) if @chomp
1308
+ $. = @io . __send__ ( :increment_lineno )
1309
+ @buffer . discard @skip if @skip
1310
+
1311
+ s
1331
1312
end
1332
1313
end
1333
1314
0 commit comments