linefeed 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e42d833b1d76721fb8906bdc579c93f0b5ab46071d2f0168adb3ffdef69f39b
4
- data.tar.gz: 5e63818116b3d40432460f2cb90b516f0617a6dbaa67556ce0b8b4637da80161
3
+ metadata.gz: acb4d8a8b79c2913d1a9b3118f11c5fc61b1bd956cecfb3c921a8a34282f369c
4
+ data.tar.gz: 7d3174f86ebe7c3af2960b425b8c656427eb181158c87c347db16c896fda4cef
5
5
  SHA512:
6
- metadata.gz: 6767fa2a9741565af3dc7e92fe96f474a58d4aa250f8db67ab1b619c886fce099f0565b9c87a29d9cb9bbffd78ac5a2ec569b6749be88b30d5f391ddaca751a3
7
- data.tar.gz: a58bba06bd570e0225f130c757ea7993809791b8cedd51ccb4f9ab59b77c68d6c941cd0e1e00e3bafc9ea61f94207e7bfdbf266bc3295470e675a08c4ad0e4a3
6
+ metadata.gz: d702bc5d2e3b49141abefd70dd72b4d84d5fbac82892cf88f97ad1da11e4fbf65af0db7dc996a198f9b8674bfdba2be456cdcfaba76058a3db45e31e8bf4cc2d
7
+ data.tar.gz: e94154e6ae96d1b8abe5dfff8f39653ded9b7dbd10bbe1e771f4baeb1805789b773e1a9b6506a2081bf0195704b68971604e86723d2d2654c2e259723c642c48
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Linefeed
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/linefeed.rb CHANGED
@@ -6,14 +6,11 @@ module Linefeed
6
6
  class Error < StandardError; end
7
7
 
8
8
  def linefeed(&default_proc)
9
+ raise ArgumentError, "linefeed already called" if @__linefeed_called
9
10
  @__linefeed_default = default_proc
10
- __linefeed_reset
11
- self
12
- end
13
-
14
- def __linefeed_reset
15
11
  @__linefeed_buffer = +"".b
16
12
  @__linefeed_closed = false
13
+ @__linefeed_called = true
17
14
  self
18
15
  end
19
16
 
@@ -23,11 +20,18 @@ module Linefeed
23
20
  raise Error, "already closed" if @__linefeed_closed
24
21
  raise ArgumentError, "no line handler" unless per_line
25
22
 
23
+ @__linefeed_called = true
26
24
  @__linefeed_buffer ||= +"".b
27
25
  @__linefeed_buffer << chunk
28
26
 
29
- while (eol = @__linefeed_buffer.index("\n"))
30
- per_line.call(@__linefeed_buffer.slice!(0..eol)) # includes the "\n"
27
+ start = 0
28
+ while (eol = @__linefeed_buffer.index("\n", start))
29
+ per_line.call(@__linefeed_buffer.slice(start..eol)) # includes the "\n"
30
+ start = eol + 1
31
+ end
32
+
33
+ if start > 0
34
+ @__linefeed_buffer = @__linefeed_buffer.byteslice(start, @__linefeed_buffer.bytesize - start) || +"".b
31
35
  end
32
36
 
33
37
  self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linefeed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Goodall