sxp 1.2.0 → 1.2.1

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: 8ac25f66cc3d44ef1ea0ee37141ce092c9740ada5d58e000472043ed0e53dec7
4
- data.tar.gz: 3969e76131d5e12a512a182ba9f03de3f1dcc098b60cd067089f0d75443117ce
3
+ metadata.gz: 85a17ead97e988aff52b01d4c4d3754cacf3d4c62e835b796f22f7a6ef4dbceb
4
+ data.tar.gz: 775622b3f2e834e674b18dc6b85740bde1144e78a3f902c68dc661f50ed1833c
5
5
  SHA512:
6
- metadata.gz: da0445f22b06f2ed5cb31a44dd37bc4c49a078205335f420857b1105b30f1d95296254e4d7f0ce80c5d4779862f0792c45e409758c893eb0131eced633df243c
7
- data.tar.gz: f8018ae5ffb2740cf12e0ca28f67c4f3b92dd466b0a2a2db73ed896f6fdb801a4a3148daf3c575474890db74d278ad2cecd114336fd9f85e021555456ea7393b
6
+ metadata.gz: 5928470e0846c61c2e6b26652890046457005370ae51254fff3e1ebb2de210b1822625985d817e51227246fefd20d4f99542a99ed55768202775321131f94d07
7
+ data.tar.gz: 4633a81cfbf46cd5facfa20415b54b63c6a5d874c6d88fdb18757794414858b8ad7da3eac39c3f11d010139b6aa30d12a7a7e5b1cf3fd1cbc9b9742f385d871f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
@@ -55,11 +55,27 @@ end
55
55
  # Extensions for Ruby's `String` class.
56
56
  class String
57
57
  ##
58
- # Returns the SXP representation of this object.
58
+ # Returns the SXP representation of this object. Uses SPARQL-like escaping.
59
59
  #
60
60
  # @return [String]
61
61
  def to_sxp(**options)
62
- inspect
62
+ buffer = ""
63
+ each_char do |u|
64
+ buffer << case u.ord
65
+ when (0x00..0x07) then sprintf("\\u%04X", u.ord)
66
+ when (0x08) then '\b'
67
+ when (0x09) then '\t'
68
+ when (0x0A) then '\n'
69
+ when (0x0C) then '\f'
70
+ when (0x0D) then '\r'
71
+ when (0x0E..0x1F) then sprintf("\\u%04X", u.ord)
72
+ when (0x22) then '\"'
73
+ when (0x5C) then '\\\\'
74
+ when (0x7F) then sprintf("\\u%04X", u.ord)
75
+ else u.chr
76
+ end
77
+ end
78
+ '"' + buffer + '"'
63
79
  end
64
80
  end
65
81
 
@@ -229,7 +245,7 @@ begin
229
245
 
230
246
  class RDF::URI
231
247
  ##
232
- # Returns the SXP representation of this a URI. Uses Lexical representation, if set, otherwise, any PName match, otherwise, the relativized version of the URI if a base_uri is given, otherwise just the URI.
248
+ # Returns the SXP representation of this URI. Uses Lexical representation, if set, otherwise, any PName match, otherwise, the relativized version of the URI if a base_uri is given, otherwise just the URI.
233
249
  #
234
250
  # @param [Hash{Symbol => RDF::URI}] prefixes(nil)
235
251
  # @param [RDF::URI] base_uri(nil)
@@ -268,7 +284,7 @@ begin
268
284
  # Retain stated lexical form if possible
269
285
  valid? ? to_s : object.to_sxp(**options)
270
286
  else
271
- text = value.dump
287
+ text = value.to_sxp
272
288
  text << "@#{language}" if self.has_language?
273
289
  text << "^^#{datatype.to_sxp(**options)}" if self.has_datatype?
274
290
  text
@@ -35,7 +35,7 @@ module SXP; class Reader
35
35
  ##
36
36
  # @return [String]
37
37
  def read_string
38
- buffer = String.new
38
+ buffer = ""
39
39
  skip_char # '"'
40
40
  until peek_char == ?" #"
41
41
  buffer <<
@@ -57,8 +57,8 @@ module SXP; class Reader
57
57
  when ?n then ?\n
58
58
  when ?r then ?\r
59
59
  when ?t then ?\t
60
- when ?u then read_chars(4).to_i(16).chr
61
- when ?U then read_chars(8).to_i(16).chr
60
+ when ?u then read_chars(4).to_i(16).chr(Encoding::UTF_8)
61
+ when ?U then read_chars(8).to_i(16).chr(Encoding::UTF_8)
62
62
  when ?" then char #"
63
63
  when ?\\ then char
64
64
  else char
@@ -69,7 +69,7 @@ module SXP; class Reader
69
69
  # @return [String]
70
70
  def read_literal
71
71
  grammar = self.class.const_get(:ATOM)
72
- buffer = String.new
72
+ buffer = ""
73
73
  buffer << read_char while !eof? && peek_char.chr =~ grammar
74
74
  buffer
75
75
  end
@@ -72,7 +72,7 @@ module SXP; class Reader
72
72
  ##
73
73
  # @return [Symbol]
74
74
  def read_symbol(delimiter = nil)
75
- buffer = String.new
75
+ buffer = ""
76
76
  skip_char # '|'
77
77
  until delimiter === peek_char
78
78
  buffer <<
@@ -171,7 +171,7 @@ module SXP; class Reader
171
171
  #
172
172
  # @return [RDF::URI]
173
173
  def read_rdf_uri
174
- buffer = String.new
174
+ buffer = ""
175
175
  skip_char # '<'
176
176
  return :< if (char = peek_char).nil? || char.chr !~ ATOM # FIXME: nasty special case for the '< symbol
177
177
  return :<= if peek_char.chr.eql?(?=.chr) && read_char # FIXME: nasty special case for the '<= symbol
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sxp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-12-08 00:00:00.000000000 Z
12
+ date: 2022-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf