rsinger-rdfobjects 0.1.9 → 0.1.11
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.
- data/lib/rdf_objects/parsers.rb +15 -5
- metadata +1 -1
data/lib/rdf_objects/parsers.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
require 'rubygems'
|
3
3
|
require 'strscan'
|
4
4
|
require 'iconv'
|
5
|
-
require 'jcode'
|
6
5
|
require 'uri'
|
7
6
|
require 'json'
|
8
7
|
require 'nokogiri'
|
9
8
|
require 'cgi'
|
9
|
+
if RUBY_VERSION < '1.9.0'
|
10
|
+
$KCODE = 'u'
|
11
|
+
require 'jcode'
|
12
|
+
end
|
10
13
|
|
11
14
|
class UTF8Parser < StringScanner
|
12
15
|
STRING = /(([\x0-\x1f]|[\\\/bfnrt]|\\u[0-9a-fA-F]{4}|[\x20-\xff])*)/nx
|
@@ -52,7 +55,7 @@ class UTF8Parser < StringScanner
|
|
52
55
|
UNPARSED
|
53
56
|
end
|
54
57
|
rescue Iconv::Failure => e
|
55
|
-
raise
|
58
|
+
raise StandardError, "Caught #{e.class}: #{e}"
|
56
59
|
end
|
57
60
|
end
|
58
61
|
module RDFObject
|
@@ -61,6 +64,9 @@ class NTriplesParser
|
|
61
64
|
attr_accessor :object
|
62
65
|
def initialize(line)
|
63
66
|
@ntriple = line
|
67
|
+
if @ntriple.respond_to?(:force_encoding)
|
68
|
+
@ntriple.force_encoding("ASCII-8BIT")
|
69
|
+
end
|
64
70
|
parse_ntriple
|
65
71
|
end
|
66
72
|
|
@@ -83,8 +89,12 @@ class NTriplesParser
|
|
83
89
|
object = scanner.scan_until(/("\s?\.\n?$)|("@[A-z])|("\^\^)/)
|
84
90
|
scanner.pos=(scanner.pos-2)
|
85
91
|
object.sub!(/"..$/,'')
|
86
|
-
|
87
|
-
|
92
|
+
if object.respond_to?(:force_encoding)
|
93
|
+
object.force_encoding('utf-8')
|
94
|
+
else
|
95
|
+
uscan = UTF8Parser.new(object)
|
96
|
+
object = uscan.parse_string
|
97
|
+
end
|
88
98
|
if scanner.match?(/@/)
|
89
99
|
scanner.getch
|
90
100
|
@language = scanner.scan_until(/\s?\.\n?$/)
|