structuredtext 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/lib/structuredtext.rb +15 -16
- metadata +1 -1
data/README
CHANGED
data/lib/structuredtext.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
# Utilities for working with various kinds of structured text.
|
22
22
|
module StructuredText
|
23
|
-
VERSION = "1.0.
|
23
|
+
VERSION = "1.0.1"
|
24
24
|
|
25
25
|
|
26
26
|
# Removes comments from text.
|
@@ -117,22 +117,22 @@ module StructuredText
|
|
117
117
|
# identical to the left-hand field quote
|
118
118
|
def initialize(source, delimiter = ",", lquote = '"', rquote = nil)
|
119
119
|
@source = source
|
120
|
-
# Escape the custom characters the caller provides a regular
|
121
|
-
# control character.
|
120
|
+
# Escape the custom characters in case the caller provides a regular
|
121
|
+
# expression control character.
|
122
122
|
delimiter = Regexp.escape(delimiter)
|
123
123
|
lquote = Regexp.escape(lquote)
|
124
124
|
rquote = rquote.nil? ? lquote : Regexp.escape(rquote)
|
125
125
|
s = <<-EOTEXT
|
126
|
-
(
|
127
|
-
(#{delimiter})
|
128
|
-
|
|
129
|
-
($)
|
126
|
+
( # Match delimiter
|
127
|
+
(?: #{delimiter}) # field delimiter
|
128
|
+
| # ...or...
|
129
|
+
(?: $) # end of line
|
130
130
|
)
|
131
|
-
|
|
132
|
-
(
|
133
|
-
(?: #{lquote}.*?#{rquote})
|
134
|
-
|
|
135
|
-
(?: [^#{delimiter}]*)
|
131
|
+
| # ...or...
|
132
|
+
( # Match text
|
133
|
+
(?: #{lquote}.*?#{rquote}) # quoted string
|
134
|
+
| # ...or...
|
135
|
+
(?: [^#{delimiter}]*) # text without delimiters
|
136
136
|
)
|
137
137
|
EOTEXT
|
138
138
|
@field_regex = Regexp.compile(s, Regexp::EXTENDED)
|
@@ -150,10 +150,9 @@ EOTEXT
|
|
150
150
|
# double-quoted strings.
|
151
151
|
field = ""
|
152
152
|
line.scan(@field_regex) do |match|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
if not (comma_delimiter or eol_delimiter)
|
153
|
+
delimiter = match[0]
|
154
|
+
text = match[1]
|
155
|
+
if delimiter.nil?
|
157
156
|
# Append text in the middle of a field.
|
158
157
|
field += text if not text.nil?
|
159
158
|
else
|