ctx_parser 0.2.1 → 0.2.2

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: 34175c1684f6dc5b5a7ef9a12649f16d393965f87c506d1f672f63a8301a7ebd
4
- data.tar.gz: 55f14e3f497e6a3fa5484f6e5465effc39acadcfff0e908932abe41b43696b94
3
+ metadata.gz: ebe907b20b136d10009fd616c196276d2e8f252dc80ccca829f0470037870cae
4
+ data.tar.gz: ec22c079545cde64af1c90ea3ae6914738ad52df680451229f71f157bcac5137
5
5
  SHA512:
6
- metadata.gz: fc1d527a3d2a6a0c2001bfc270d6afb7f8b21e3f779d5f61b31de69757ea598f2b255a5a5eb15db41ebde8de6274c99e3ade55f89cb1b577041cdab8d4563bbf
7
- data.tar.gz: 4708ac383d49d5f2ade14747800d6d5d52db0e1cdc78ac2acbd87e828fb41695e41ebf2a98a72b1c81c13d4612c2419e40ba189d429c39be7bb4afebd074100c
6
+ metadata.gz: 41da2cef0eade558dc4e0abbc4ad2929d0a6f3fa43e9571070cc5974e2d84e13bee4cf1e404fe6ab556eabd9f314e3401a1ca1b480be4c2d408beac4a7c74d36
7
+ data.tar.gz: 71c40107cb0a24d0521984594dd0680214fb066f3985e536105b16f7bb1ff0e2a4cdaf2a2e7c5aa9a6834e339652b73d471e4565153355496728d095d57a5aa6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Changes to the public contract are recorded here. Versions follow Semantic Versioning.
4
4
 
5
+ ## 0.2.2 (2026-10-18)
6
+
7
+ - Preserve exact block, capture and unresolved source text independently of Ruby's global output separator.
8
+ - Normalize source lines independently of Ruby's global input separator, without an intermediate chomp allocation.
9
+ - Build cursor lines directly during scanning instead of retaining an intermediate source-line array.
10
+ - Return false from IP address validation for incompatible string encodings.
11
+
5
12
  ## 0.2.1 (2026-10-17)
6
13
 
7
14
  - Update the configuration benchmark to use the Baseline 0.2 vendor parser namespace.
data/README-zh.md CHANGED
@@ -99,6 +99,8 @@ bundle exec rake build
99
99
 
100
100
  使用声明的最低 Ruby 版本检查兼容性。方法用途统一使用简明中文注释;复杂实现还需说明业务规则、实现思路及关键分支。保持公开返回值与错误契约。真实回显和凭据不可进入示例、fixture、日志或发布包。
101
101
 
102
+ 执行 `bundle exec ruby -Ilib benchmark/source.rb`,可使用合成输入和语义断言测量游标及文档构建的耗时与对象分配量,无需领域 gem。此类本地测量不代表设备性能。
103
+
102
104
  ## 发布
103
105
 
104
106
  本目录可独立维护为 [ctx_parser](https://github.com/gatework/ctx_parser) 仓库。更新 `VERSION` 和 `CHANGELOG.md`,运行上述验证与构建命令,检查包内文件,再创建 `vVERSION` 标签。
data/README.md CHANGED
@@ -99,6 +99,8 @@ bundle exec rake build
99
99
 
100
100
  Use the declared minimum Ruby version for compatibility checks. Document source methods and non-obvious business logic in concise Chinese, preserve public return/error contracts, and never add raw device captures or credentials to examples, fixtures, logs, or release archives.
101
101
 
102
+ Run `bundle exec ruby -Ilib benchmark/source.rb` to measure cursor and document construction with synthetic input and semantic checks. It needs no domain gems and reports elapsed time and allocated objects; these local measurements do not establish device performance.
103
+
102
104
  ## Release
103
105
 
104
106
  This directory can be maintained as the independent [ctx_parser](https://github.com/gatework/ctx_parser) repository. Update `VERSION` and `CHANGELOG.md`, run the validation and build commands above, and inspect the packaged file list before tagging `vVERSION`.
@@ -97,7 +97,7 @@ module CtxParser
97
97
  # 返回属于当前配置块的原始来源行。
98
98
  def lines = cursor.lines[index..last_index].freeze
99
99
  # 返回配置块或捕获事实对应的精确来源文本。
100
- def content = lines.map(&:raw).join.freeze
100
+ def content = lines.map(&:raw).join("").freeze
101
101
  # 返回当前配置块各来源行的处理状态。
102
102
  def states = lines.map { |source| cursor.state(source.index) }.freeze
103
103
  # 要求块内所有来源行均已解析或明确忽略。
@@ -19,9 +19,12 @@ module CtxParser
19
19
 
20
20
  @content = Input.text(content, encoding: :transcode).freeze
21
21
 
22
- @lines = @content.scan(/[^\r\n]*(?:\r\n|\r|\n)|[^\r\n]+\z/).each_with_index.map do |raw, index|
23
- Line.new(index: index, raw: raw)
24
- end.freeze
22
+ # scan 直接交付每行,避免同时保留原始行数组与 Line 数组。
23
+ @lines = []
24
+ @content.scan(/[^\r\n]*(?:\r\n|\r|\n)|[^\r\n]+\z/) do |raw|
25
+ @lines << Line.new(index: @lines.size, raw: raw)
26
+ end
27
+ @lines.freeze
25
28
  @checksum = Digest::SHA256.hexdigest(@content).freeze
26
29
  reset!
27
30
  end
@@ -123,7 +126,7 @@ module CtxParser
123
126
  end
124
127
 
125
128
  # 拼接未解决来源行,并保留原有格式。
126
- def unparsed_content = unparsed_lines.map(&:raw).join.freeze
129
+ def unparsed_content = unparsed_lines.map(&:raw).join("").freeze
127
130
 
128
131
  # 将事实快照关联到来源块,不将整个块标记为解析成功。
129
132
  def capture(block, data:, path:)
@@ -8,7 +8,8 @@ module CtxParser
8
8
  raise ArgumentError, "Line index must be nonnegative" unless index.is_a?(Integer) && index >= 0
9
9
  raise ArgumentError, "Line content must be text" unless raw.is_a?(String)
10
10
 
11
- @text = raw.chomp.strip.freeze
11
+ # strip 已移除行结束空白,避免 chomp 依赖宿主进程的 $/。
12
+ @text = raw.strip.freeze
12
13
  @indent = raw[/\A[ \t]*/].size
13
14
  super(index: index, raw: raw.dup.freeze)
14
15
  end
@@ -48,7 +48,7 @@ module CtxParser
48
48
  # 校验主机地址有效性,不让格式错误值继续传播。
49
49
  def ip_address?(raw, allow_zone: false)
50
50
  !ip_address(raw, allow_zone: allow_zone).nil?
51
- rescue ArgumentError, IPAddr::Error
51
+ rescue ArgumentError, IPAddr::Error, EncodingError
52
52
  false
53
53
  end
54
54
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CtxParser
4
4
  # 公开包版本,供 RubyGems 元数据和运行时调用方共用。
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ctx_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gatework contributors