cddlc 0.3.4 → 0.3.5

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: c3ebce64393cf5518aaaf97d1257771e4b0a7e0f3318f0c1ba7a2c0a3342de9f
4
- data.tar.gz: 6dd472b20440724ce78aa6bc87a858b29d8b81b8137b7f583afed016285e0e2b
3
+ metadata.gz: 6d01061fd86124e6e68aae0a7ef043d23c9a2211992f9421e9333c50d8a870ee
4
+ data.tar.gz: 7efe567eeca90c756dac4354791583cae6da812b05eaf4074dfb953f71d09adb
5
5
  SHA512:
6
- metadata.gz: 31b74e7d6fc4fce123d2289c7323d8dcbc91704f16851c509938bc89d786a4850c8abd373247c931c1a5a078e310ab0b539900b514626d8dcaa24e5c33fb3067
7
- data.tar.gz: a3c9e1683b8bf909cd4c946b2396794172fd1c6f8d66814af36bb209ab65524da4c5f61b920d0836b91d39d53bd7c784156b22989e99946c166b34c6b3dca0f3
6
+ metadata.gz: c051e4c6c4e319e223dc8126512ffe8c7368b985735c8b15b34ac3ae5dad183f7f80f74e3a4b90f1679877472c8c5a0968f38d73994fc4e3dbb8669a39938c09
7
+ data.tar.gz: 29fce82dbdfd0bf5e14184b8445d3281a648fdd3f1fb982e37020317c23b94100449d21fed9a609a2f041fdc4a035c7842e23f861b5730480f9a828963122fef
data/cddlc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cddlc"
3
- s.version = "0.3.4"
3
+ s.version = "0.3.5"
4
4
  s.summary = "CDDL (Concise Data Definition Language) converters and miscellaneous tools"
5
5
  s.description = %q{cddlc implements converters and miscellaneous tools for CDDL, RFC 8610}
6
6
  s.author = "Carsten Bormann"
@@ -2,6 +2,32 @@ require_relative "../cddlc.rb"
2
2
 
3
3
  class CDDL
4
4
 
5
+ # In each specific case, use the appropriate subset
6
+ ESCAPED_STRING_MAPPINGS = Hash[[
7
+ ["\x08", "b"],
8
+ ["\x09", "t"],
9
+ ["\x0A", "n"],
10
+ ["\x0C", "f"],
11
+ ["\x0D", "r"],
12
+ ["\x22", "\""],
13
+ ["\x27", "'"],
14
+ ["\x2F", "/"],
15
+ ["\x5C", "\\"],
16
+ ]]
17
+
18
+ # TODO: Enable selecting Unicode-friendly variants
19
+ def escape_string(s)
20
+ s.gsub(/[^\n !#-\[\]-~]/) {|ch|
21
+ if m = ESCAPED_STRING_MAPPINGS[ch]
22
+ "\\#{m}"
23
+ elsif (o = ch.ord) < 0x10000
24
+ "\\u#{"%04x" % o}"
25
+ else
26
+ "\\u{#{"%x" % o}}"
27
+ end
28
+ }
29
+ end
30
+
5
31
  def write_lhs(k, parmnames)
6
32
  if parmnames
7
33
  "#{k}<#{parmnames.join(", ")}>"
@@ -104,7 +130,7 @@ class CDDL
104
130
  in ["bytes", t]
105
131
  [4, t] # XXX not very clean
106
132
  in ["text", t]
107
- [4, "\"#{t}\""] # XXX escape
133
+ [4, "\"#{escape_string(t)}\""]
108
134
  in ["number", t]
109
135
  [4, t.to_s]
110
136
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cddlc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-12 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler