modl 0.3.22 → 0.3.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15424e85da367ff2ab9aaf7719c781891382d0b06e8f043b4c53a92da037aa7a
4
- data.tar.gz: 68d4ccbd3516afd9b628aacdace4689f46706d2db151ef70b2725c3724a7cee0
3
+ metadata.gz: b6e08595e87f2b8fccd3ab9abfde857bd268bf2ca1c8fa1b00069d81c5644701
4
+ data.tar.gz: c725b89c8d561e3c84404f55d74c94d1fdf605474aa58c2fb5bc255255d7a816
5
5
  SHA512:
6
- metadata.gz: 2026dcc8197b0ac9beb78555aaa2ed13817b7005a781a85fa7255b29042be14c92aa4aa455522ca67658aa92a86bd49f4e98f0b723359272b13a541dd53be496
7
- data.tar.gz: 3df4f4c19bdc33b7453146c81802396c15fc90c3e9ebf073f4e8920bb128cf5e1cb7a10c50eaebf8be4631643c3ba73bcb34d031d87643e6806160b37ac2fcba
6
+ metadata.gz: 17d4f8fc520fb5cc16737ab869a52b1ee532b5050dc404153da7dd6c6f71f79befd6aaaddaf1857b41e317be763ca404851d8419d254041397f2cd6290ee1957
7
+ data.tar.gz: 6ba10d6e62a742b0c7ec38c2a82ab8f9231168a7d9ed8102ea45fe3a0f45209e2f753f980551de919eba18d7762c4dfc0ca1b3ee0530de40cfb7a90fed15c26b
@@ -1,3 +1,7 @@
1
+ 0.3.23
2
+ ===
3
+ - Add support for 5- and 6-digit unicode escape sequences.
4
+
1
5
  0.3.22
2
6
  ===
3
7
  - Two bug fixes - quoted strings, and incomplete strings for certain output situations.
@@ -3160,5 +3160,15 @@
3160
3160
  "object_ref"
3161
3161
  ],
3162
3162
  "minimised_modl": "_C=gb;_L=en;*load=\"http://modules.num.uk/1/rcf.txt!\";o(c[fb=abc;tw=abc])"
3163
+ },
3164
+ {
3165
+ "id": "332",
3166
+ "input": "test=~u1f60000",
3167
+ "expected_output": "{\n \"test\": \"\uD83D\uDE0000\"\n}",
3168
+ "tested_features": [
3169
+ "unicode",
3170
+ "escapes"
3171
+ ],
3172
+ "minimised_modl": "test=\\~u1f60000"
3163
3173
  }
3164
3174
  ]
@@ -55,15 +55,58 @@ module MODL
55
55
  next if uni_str_idx > 0 && result[uni_str_idx - 1] == '~'
56
56
  next if uni_str_idx > 0 && result[uni_str_idx - 1] == '\\'
57
57
 
58
- value = result.slice(uni_str_idx + 2, 4).to_i(16)
58
+ (value, len) = try_parse(result, uni_str_idx + 2)
59
59
  uni_val = value.chr(Encoding::UTF_8)
60
60
  left = result.slice(0, uni_str_idx)
61
- right = result.slice(uni_str_idx + 6, result.length)
61
+ right = result.slice(uni_str_idx + (2 + len), result.length)
62
62
  result = left + uni_val + right unless right.nil?
63
63
  result = left + uni_val if right.nil?
64
64
  end
65
65
  result
66
66
  end
67
+
68
+ def self.enough_digits?(str, idx, n)
69
+ i = 0
70
+ chars = str.chars
71
+ while i < n && (idx + i) < str.length
72
+ c = chars[idx + i]
73
+ unless (('0'..'9').include? c) || (('a'..'f').include? c) || (('A'..'F').include? c)
74
+ return false
75
+ end
76
+ i += 1
77
+ end
78
+ (i == n) ? true : false
79
+ end
80
+
81
+ # unicode can be 4 to 6 characters
82
+ def self.try_parse(str, idx)
83
+ if enough_digits?(str, idx, 6)
84
+ value = str.slice(idx, 6).to_i(16)
85
+ if valid_range? value
86
+ return [value, 6]
87
+ end
88
+ end
89
+ if enough_digits?(str, idx, 5)
90
+ value = str.slice(idx, 5).to_i(16)
91
+ if valid_range? value
92
+ return [value, 5]
93
+ end
94
+ end
95
+ if enough_digits?(str, idx, 4)
96
+ value = str.slice(idx, 4).to_i(16)
97
+ if valid_range? value
98
+ return [value, 4]
99
+ end
100
+ if valid_range? value
101
+ return [value, 4]
102
+ end
103
+ end
104
+ [0, 4]
105
+ end
106
+
107
+ def self.valid_range?(value)
108
+ return ((0x100000..0x10ffff).include? value) || ((0x10000..0xfffff).include? value) || ((0..0xd7ff).include? value) || ((0xe000..0xffff).include? value) ? true : false
109
+ end
67
110
  end
68
111
  end
69
112
  end
@@ -24,6 +24,6 @@
24
24
 
25
25
  module MODL
26
26
  module Parser
27
- VERSION = "0.3.22"
27
+ VERSION = "0.3.23"
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.22
4
+ version: 0.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Walmsley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-29 00:00:00.000000000 Z
11
+ date: 2019-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake