sdl4r 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -0,0 +1,13 @@
1
+ == v0.9.4 (6-aug-2010)
2
+
3
+ === Major changes:
4
+
5
+ * The use of BigDecimal (standard) has been preferred to Flt::DecNum.
6
+ * "sdl4r/sdl.rb" has been renamed to "sdl4r/sdl4r.rb"
7
+ * A sdl4r.rb has been added so that users can actually write (as the documentation pretended):
8
+
9
+ require 'sdl4r'
10
+
11
+ * SDL4R#coerce_or_fail has been implemented, which means that random objects can't be added to a
12
+ Tag as before. Rational instances are coerced using Rational#to_f.
13
+ * Added usual time methods to SdlTimeSpan: day(), hour(), min(), sec(), usec()
data/README CHANGED
@@ -328,10 +328,10 @@ integer (32 bits signed):: Integer (Fixnum or Bignum)
328
328
  long integer (64 bits signed):: Integer (Fixnum or Bignum)
329
329
  float (32 bits signed):: Float
330
330
  double float (64 bits signed):: Float
331
- decimal (128+ bits signed):: Flt::DecNum (if installed; see http://flt.rubyforge.org/), core numeric classes otherwise
331
+ decimal (128+ bits signed):: BigDecimal
332
332
  boolean:: true (TrueClass) and false (FalseClass)
333
333
  date (day):: Date
334
- date time:: DateTime
334
+ date time:: DateTime (see SDL4R#new_date_time if you want to get Time instances from the parsers)
335
335
  time span:: SdlTimeSpan
336
336
  binary:: SdlBinary (to avoid confusion with simple strings)
337
337
  null:: nil (NilClass)
data/Rakefile CHANGED
@@ -10,14 +10,14 @@ spec = Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.summary = "Simple Declarative Language for Ruby library"
12
12
  s.name = 'sdl4r'
13
- s.version = '0.9.3'
13
+ s.version = '0.9.4'
14
14
  s.requirements << 'none'
15
15
  s.require_path = 'lib'
16
16
  s.authors = ['Philippe Vosges', 'Daniel Leuck']
17
17
  s.email = 'sdl-users@ikayzo.org'
18
18
  s.rubyforge_project = 'sdl4r'
19
19
  s.homepage = 'http://www.ikayzo.org/confluence/display/SDL/Home'
20
- s.files = FileList['lib/sdl4r/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*', 'doc/*'].to_a
20
+ s.files = FileList['lib/sdl4r.rb', 'lib/sdl4r/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*', 'doc/**/*'].to_a
21
21
  s.test_files = FileList[ 'test/**/*test.rb' ].to_a
22
22
  s.description = <<EOF
23
23
  The Simple Declarative Language provides an easy way to describe lists, maps,
@@ -47,7 +47,7 @@ end
47
47
 
48
48
  Rake::RDocTask.new do |rd|
49
49
  files = ['README', 'LICENSE', 'CHANGELOG',
50
- 'lib/sdl4r/**/*.rb', 'doc/**/*.rdoc', 'test/*.rb']
50
+ 'lib/sdl4r.rb', 'lib/sdl4r/**/*.rb', 'doc/**/*.rdoc', 'test/*.rb']
51
51
  rd.main = 'README'
52
52
  rd.rdoc_files.include(files)
53
53
  rd.rdoc_dir = "doc"
data/TODO.txt CHANGED
@@ -11,7 +11,8 @@
11
11
  with or without given block. Same goes for each_value(), etc.
12
12
  [x] Is Base64 really compatible with the format defined in the Java version ?
13
13
  ==> Seems so after having implemented more of the standard tests.
14
- [ ] Support both DateTime and Time in parsing (see Parser#combine())
14
+ [x] Support both DateTime and Time in parsing (see Parser#combine())
15
+ ==> SDL4R::new_date_time can be overriden
15
16
  [x] Use Date instead of DateTime if only day was specified in SDL (parser.rb)
16
17
  [x] Add a remove_all_children() to Tag
17
18
  [x] Rethink the interfaces to access sub-tags, values, attributes, etc
@@ -38,8 +39,8 @@
38
39
  [A] Use YARD in order to generate documentation ?
39
40
  ==> alternatively, I tried to generate some RDoc templates but none worked in Rake...
40
41
  [x] In the documentation, present a table giving the returned Ruby type for each SDL type.
41
- [A] Change the interface of SdlTimeSpan to look like the interfaces of Date, DateTime or Time
42
- ==> Really? This is a timespan, not a date.
42
+ [x] Change the interface of SdlTimeSpan to look like the interfaces of Date, DateTime or Time
43
+ ==> Add alias methods.
43
44
  [x] Have SdlTimeSpan implement Comparable
44
45
  [ ] BUG: the line number is too high by 1 (the column is correct).
45
46
  [x] PB: binary fields shouldn't be kept as Strings because they would not be saved as binaries but
@@ -93,12 +94,17 @@
93
94
  ==> Moved to the Parser namespace.
94
95
  [x] Factorize "each_child..." methods in Tag and refactor "children(recursive, name)" consequently
95
96
  + invert "name" and "recursive" in "children()"
96
- [ ] Return copies or original arrays in Tag?
97
+ [x] Return copies or original arrays in Tag?
98
+ ==> we return the implementation Arrays or Hashes (or whatever) for efficiency.
99
+ However, we ask the users not to assume anything as we might protect the returned objects in
100
+ the future.
97
101
  [A] BUG: test_tag_write_parse() does not work from the command line (ruby v1.8.7).
98
102
  ==> This is normal provided that flt was not installed.
99
- [ ] Tag.to_string(): break up long lines using the backslash
103
+ [A] Tag.to_string(): break up long lines using the backslash
104
+ ==> unless, some day, someone asks for it...
100
105
  [ ] Tag.hash: the implementation is not very efficient.
101
- ==> Difficult to make better and simple
106
+ ==> Difficult to make better and still simple
107
+ ==> Maybe possible when it's frozen.
102
108
  [x] Implement reading from a URL(?) Other sources idiomatic in Ruby?
103
109
  ==> Strings, URIs, Pathnames, IOs
104
110
  [x] See the XML and YAML APIs to find enhancements.
@@ -128,15 +134,17 @@
128
134
  [x] State in the README that without Flt, all the tests can't run.
129
135
  ==> it's stated explicitely in the test
130
136
  [w] Make it so that each test appears separately in test.rb (if possible)
131
- [ ] Have the use of Flt be optional.
132
- [ ] Be sure that there is a way to change the precision of Flt outside of SDL4R
133
- [ ] Turn Rationals to Floats in coerc_or_fail()?
137
+ [A] Have the use of Flt be optional.
138
+ ==> We use BigDecimal instead.
139
+ [x] Be sure that there is a way to change the precision of Flt outside of SDL4
140
+ ==> just change the precision in your thread before parsing
141
+ [x] Turn Rationals to Floats in coerce_or_fail()?
134
142
  [ ] BUG: "rake package" tries to archive the contents twice: once with the command that I configure
135
- in Rakefime, once with a zip command that can't work on my machine (zip is not installed). Why?
143
+ in Rakefile, once with a zip command that can't work on my machine (zip is not installed). Why?
136
144
  At least, the first archive is created and seems correct.
137
145
  [x] Add a "Getting Started" chapter to the README
138
146
  [ ] FUTURE: Would we need a "write" method in SDL4R?
139
- [ ] Implement coerce_or_fail: it is right now allowed to add any garbage to the SDL tags
147
+ [x] Implement coerce_or_fail: it is right now allowed to add any garbage to the SDL tags
140
148
  [x] Fix the doc of Tag.add_value
141
149
  [ ] Add tests and release a RC or beta version
142
150
  [x] Make the parser components disappear from the RDoc
@@ -158,3 +166,12 @@
158
166
  [x] Add tests for to_xml_string
159
167
  [x] Be stricter and more explicit with Tag and attributes name/namespace
160
168
  [x] Fix set_attributes: it was correct before.
169
+ [ ] Input relevant URLs on http://rubygems.org
170
+ [x] What prevents from doing the following?
171
+ tag.values << IO.new("toto.txt")
172
+ ==> It doesn't break the behavior as long as the value type is OK. Even if it is not allowed,
173
+ it still is not too bad.
174
+ [x] Somehow, I didn't choose BigDecimal when I started to use Flt::DecNum. Can't remember why but
175
+ seems overly complicated.
176
+ ==> Remove Flt.
177
+ [x] Rename sdl.rb to sdl4r.rb
@@ -0,0 +1,681 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: SDL4R</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">SDL4R</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/sdl4r/sdl_time_span_rb.html">
59
+ lib/sdl4r/sdl_time_span.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/sdl4r/sdl_parse_error_rb.html">
63
+ lib/sdl4r/sdl_parse_error.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/sdl4r/tag_rb.html">
67
+ lib/sdl4r/tag.rb
68
+ </a>
69
+ <br />
70
+ <a href="../files/lib/sdl4r/parser_rb.html">
71
+ lib/sdl4r/parser.rb
72
+ </a>
73
+ <br />
74
+ <a href="../files/lib/sdl4r/sdl_binary_rb.html">
75
+ lib/sdl4r/sdl_binary.rb
76
+ </a>
77
+ <br />
78
+ <a href="../files/lib/sdl4r/parser/reader_rb.html">
79
+ lib/sdl4r/parser/reader.rb
80
+ </a>
81
+ <br />
82
+ <a href="../files/lib/sdl4r/parser/tokenizer_rb.html">
83
+ lib/sdl4r/parser/tokenizer.rb
84
+ </a>
85
+ <br />
86
+ <a href="../files/lib/sdl4r/parser/token_rb.html">
87
+ lib/sdl4r/parser/token.rb
88
+ </a>
89
+ <br />
90
+ <a href="../files/lib/sdl4r/parser/time_span_with_zone_rb.html">
91
+ lib/sdl4r/parser/time_span_with_zone.rb
92
+ </a>
93
+ <br />
94
+ <a href="../files/lib/sdl4r/sdl4r_rb.html">
95
+ lib/sdl4r/sdl4r.rb
96
+ </a>
97
+ <br />
98
+ </td>
99
+ </tr>
100
+
101
+ </table>
102
+ </div>
103
+ <!-- banner header -->
104
+
105
+ <div id="bodyContent">
106
+
107
+
108
+
109
+ <div id="contextContent">
110
+
111
+ <div id="description">
112
+ <p>
113
+ Gathers utility methods.
114
+ </p>
115
+
116
+ </div>
117
+
118
+
119
+ </div>
120
+
121
+ <div id="method-list">
122
+ <h3 class="section-bar">Methods</h3>
123
+
124
+ <div class="name-list">
125
+ <a href="#M000001">SdlBinary</a>&nbsp;&nbsp;
126
+ <a href="#M000004">coerce_or_fail</a>&nbsp;&nbsp;
127
+ <a href="#M000002">format</a>&nbsp;&nbsp;
128
+ <a href="#M000003">new_date_time</a>&nbsp;&nbsp;
129
+ <a href="#M000006">read</a>&nbsp;&nbsp;
130
+ <a href="#M000009">to_attribute_map</a>&nbsp;&nbsp;
131
+ <a href="#M000007">to_value</a>&nbsp;&nbsp;
132
+ <a href="#M000008">to_value_array</a>&nbsp;&nbsp;
133
+ <a href="#M000005">validate_identifier</a>&nbsp;&nbsp;
134
+ </div>
135
+ </div>
136
+
137
+ </div>
138
+
139
+
140
+ <!-- if includes -->
141
+
142
+ <div id="section">
143
+
144
+ <div id="class-list">
145
+ <h3 class="section-bar">Classes and Modules</h3>
146
+
147
+ Class <a href="SDL4R/Parser.html" class="link">SDL4R::Parser</a><br />
148
+ Class <a href="SDL4R/SdlBinary.html" class="link">SDL4R::SdlBinary</a><br />
149
+ Class <a href="SDL4R/SdlParseError.html" class="link">SDL4R::SdlParseError</a><br />
150
+ Class <a href="SDL4R/SdlTimeSpan.html" class="link">SDL4R::SdlTimeSpan</a><br />
151
+ Class <a href="SDL4R/Tag.html" class="link">SDL4R::Tag</a><br />
152
+
153
+ </div>
154
+
155
+ <div id="constants-list">
156
+ <h3 class="section-bar">Constants</h3>
157
+
158
+ <div class="name-list">
159
+ <table summary="Constants">
160
+ <tr class="top-aligned-row context-row">
161
+ <td class="context-item-name">MAX_INTEGER_32</td>
162
+ <td>=</td>
163
+ <td class="context-item-value">2**31 - 1</td>
164
+ </tr>
165
+ <tr class="top-aligned-row context-row">
166
+ <td class="context-item-name">MIN_INTEGER_32</td>
167
+ <td>=</td>
168
+ <td class="context-item-value">-(2**31)</td>
169
+ </tr>
170
+ <tr class="top-aligned-row context-row">
171
+ <td class="context-item-name">MAX_INTEGER_64</td>
172
+ <td>=</td>
173
+ <td class="context-item-value">2**63 - 1</td>
174
+ </tr>
175
+ <tr class="top-aligned-row context-row">
176
+ <td class="context-item-name">MIN_INTEGER_64</td>
177
+ <td>=</td>
178
+ <td class="context-item-value">-(2**63)</td>
179
+ </tr>
180
+ <tr class="top-aligned-row context-row">
181
+ <td class="context-item-name">BASE64_WRAP_LINE_LENGTH</td>
182
+ <td>=</td>
183
+ <td class="context-item-value">72</td>
184
+ </tr>
185
+ <tr class="top-aligned-row context-row">
186
+ <td class="context-item-name">ESCAPED_QUOTES</td>
187
+ <td>=</td>
188
+ <td class="context-item-value">{ &quot;\&quot;&quot; =&gt; &quot;\\\&quot;&quot;, &quot;'&quot; =&gt; &quot;\\'&quot;, &quot;`&quot; =&gt; &quot;\\`&quot;, }</td>
189
+ </tr>
190
+ <tr class="top-aligned-row context-row">
191
+ <td class="context-item-name">ESCAPED_CHARS</td>
192
+ <td>=</td>
193
+ <td class="context-item-value">{ &quot;\\&quot; =&gt; &quot;\\\\&quot;, &quot;\t&quot; =&gt; &quot;\\t&quot;, &quot;\r&quot; =&gt; &quot;\\r&quot;, &quot;\n&quot; =&gt; &quot;\\n&quot;, }</td>
194
+ </tr>
195
+ </table>
196
+ </div>
197
+ </div>
198
+
199
+
200
+
201
+
202
+
203
+
204
+ <!-- if method_list -->
205
+ <div id="methods">
206
+ <h3 class="section-bar">Public Class methods</h3>
207
+
208
+ <div id="method-M000001" class="method-detail">
209
+ <a name="M000001"></a>
210
+
211
+ <div class="method-heading">
212
+ <a href="#M000001" class="method-signature">
213
+ <span class="method-name">SdlBinary</span><span class="method-args">(o)</span>
214
+ </a>
215
+ </div>
216
+
217
+ <div class="method-description">
218
+ <p>
219
+ Try to coerce &#8216;o&#8217; into a <a
220
+ href="SDL4R.html#M000001">SdlBinary</a>. Raise an ArgumentError if it
221
+ fails.
222
+ </p>
223
+ <p><a class="source-toggle" href="#"
224
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
225
+ <div class="method-source-code" id="M000001-source">
226
+ <pre>
227
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl_binary.rb, line 69</span>
228
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">SdlBinary</span>(<span class="ruby-identifier">o</span>)
229
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">SdlBinary</span>
230
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>
231
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">String</span>
232
+ <span class="ruby-keyword kw">return</span> <span class="ruby-constant">SdlBinary</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">o</span>)
233
+ <span class="ruby-keyword kw">else</span>
234
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;can't coerce argument&quot;</span>
235
+ <span class="ruby-keyword kw">end</span>
236
+ <span class="ruby-keyword kw">end</span>
237
+ </pre>
238
+ </div>
239
+ </div>
240
+ </div>
241
+
242
+ <div id="method-M000004" class="method-detail">
243
+ <a name="M000004"></a>
244
+
245
+ <div class="method-heading">
246
+ <a href="#M000004" class="method-signature">
247
+ <span class="method-name">coerce_or_fail</span><span class="method-args">(o)</span>
248
+ </a>
249
+ </div>
250
+
251
+ <div class="method-description">
252
+ <p>
253
+ Coerce the type to a standard SDL type or raises an ArgumentError.
254
+ </p>
255
+ <p>
256
+ Returns <tt>o</tt> if of the following classes: NilClass, String, Numeric,
257
+ Float, TrueClass, FalseClass, Date, DateTime, Time, <a
258
+ href="SDL4R/SdlTimeSpan.html">SdlTimeSpan</a>, <a
259
+ href="SDL4R.html#M000001">SdlBinary</a>,
260
+ </p>
261
+ <p>
262
+ Rationals are turned into Floats using Rational#to_f.
263
+ </p>
264
+ <p><a class="source-toggle" href="#"
265
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
266
+ <div class="method-source-code" id="M000004-source">
267
+ <pre>
268
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 149</span>
269
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">coerce_or_fail</span>(<span class="ruby-identifier">o</span>)
270
+ <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">o</span>
271
+
272
+ <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Rational</span>
273
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_f</span>
274
+
275
+ <span class="ruby-keyword kw">when</span> <span class="ruby-constant">NilClass</span>,
276
+ <span class="ruby-constant">String</span>,
277
+ <span class="ruby-constant">Numeric</span>,
278
+ <span class="ruby-constant">Float</span>,
279
+ <span class="ruby-constant">TrueClass</span>,
280
+ <span class="ruby-constant">FalseClass</span>,
281
+ <span class="ruby-constant">Date</span>,
282
+ <span class="ruby-constant">DateTime</span>,
283
+ <span class="ruby-constant">Time</span>,
284
+ <span class="ruby-constant">SdlTimeSpan</span>,
285
+ <span class="ruby-constant">SdlBinary</span>
286
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>
287
+
288
+ <span class="ruby-keyword kw">end</span>
289
+
290
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;#{o.class.name} is not coercible to an SDL type&quot;</span>
291
+ <span class="ruby-keyword kw">end</span>
292
+ </pre>
293
+ </div>
294
+ </div>
295
+ </div>
296
+
297
+ <div id="method-M000002" class="method-detail">
298
+ <a name="M000002"></a>
299
+
300
+ <div class="method-heading">
301
+ <a href="#M000002" class="method-signature">
302
+ <span class="method-name">format</span><span class="method-args">(o, add_quotes = true, line_prefix = &quot;&quot;, indent = &quot;\t&quot;)</span>
303
+ </a>
304
+ </div>
305
+
306
+ <div class="method-description">
307
+ <p>
308
+ Creates an SDL string representation for a given object and returns it.
309
+ </p>
310
+ <table>
311
+ <tr><td valign="top"><tt>o</tt>:</td><td>the object to <a href="SDL4R.html#M000002">format</a>
312
+
313
+ </td></tr>
314
+ <tr><td valign="top"><tt>add_quotes</tt>:</td><td>indicates whether quotes will be added to Strings and characters (true by
315
+ default)
316
+
317
+ </td></tr>
318
+ <tr><td valign="top"><tt>line_prefix</tt>:</td><td>the line prefix to use (&quot;&quot; by default)
319
+
320
+ </td></tr>
321
+ <tr><td valign="top"><tt>indent</tt>:</td><td>the indent string to use (&quot;\t&quot; by default)
322
+
323
+ </td></tr>
324
+ </table>
325
+ <p><a class="source-toggle" href="#"
326
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
327
+ <div class="method-source-code" id="M000002-source">
328
+ <pre>
329
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 42</span>
330
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">format</span>(<span class="ruby-identifier">o</span>, <span class="ruby-identifier">add_quotes</span> = <span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">line_prefix</span> = <span class="ruby-value str">&quot;&quot;</span>, <span class="ruby-identifier">indent</span> = <span class="ruby-value str">&quot;\t&quot;</span>)
331
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
332
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">add_quotes</span>
333
+ <span class="ruby-identifier">o_length</span> = <span class="ruby-value">0</span>
334
+ <span class="ruby-identifier">o</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/./</span><span class="ruby-identifier">m</span>) { <span class="ruby-identifier">o_length</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> } <span class="ruby-comment cmt"># counts the number of chars (as opposed of bytes)</span>
335
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o_length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
336
+ <span class="ruby-keyword kw">return</span> <span class="ruby-value str">&quot;'&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>, <span class="ruby-value str">&quot;'&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;'&quot;</span>
337
+ <span class="ruby-keyword kw">else</span>
338
+ <span class="ruby-keyword kw">return</span> <span class="ruby-value str">'&quot;'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>, <span class="ruby-value str">'&quot;'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">'&quot;'</span>
339
+ <span class="ruby-keyword kw">end</span>
340
+ <span class="ruby-keyword kw">else</span>
341
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>)
342
+ <span class="ruby-keyword kw">end</span>
343
+
344
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Bignum</span>)
345
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;BD&quot;</span>
346
+
347
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>)
348
+ <span class="ruby-keyword kw">if</span> <span class="ruby-constant">MIN_INTEGER_32</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">o</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">o</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-constant">MAX_INTEGER_32</span>
349
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>
350
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">MIN_INTEGER_64</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">o</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">o</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-constant">MAX_INTEGER_64</span>
351
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;L&quot;</span>
352
+ <span class="ruby-keyword kw">else</span>
353
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;BD&quot;</span>
354
+ <span class="ruby-keyword kw">end</span>
355
+
356
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Float</span>)
357
+ <span class="ruby-keyword kw">return</span> (<span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;F&quot;</span>)
358
+
359
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Rational</span>)
360
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_f</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;F&quot;</span>
361
+
362
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">BigDecimal</span>)
363
+ <span class="ruby-identifier">s</span> = <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>(<span class="ruby-value str">'F'</span>)
364
+ <span class="ruby-identifier">s</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp re">/\.0$/</span>, <span class="ruby-value str">&quot;&quot;</span>)
365
+ <span class="ruby-keyword kw">return</span> <span class="ruby-node">&quot;#{s}BD&quot;</span>
366
+
367
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">nil?</span>
368
+ <span class="ruby-keyword kw">return</span> <span class="ruby-value str">&quot;null&quot;</span>
369
+
370
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">SdlBinary</span>)
371
+ <span class="ruby-identifier">encoded_o</span> = <span class="ruby-constant">Base64</span>.<span class="ruby-identifier">encode64</span>(<span class="ruby-identifier">o</span>.<span class="ruby-identifier">bytes</span>)
372
+ <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/[\r\n]/</span><span class="ruby-identifier">m</span>, <span class="ruby-value str">&quot;&quot;</span>) <span class="ruby-comment cmt"># Remove the EOL inserted every 60 chars</span>
373
+
374
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">add_quotes</span>
375
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-constant">BASE64_WRAP_LINE_LENGTH</span>
376
+ <span class="ruby-comment cmt"># FIXME: we should a constant or some parameter instead of hardcoded spaces</span>
377
+ <span class="ruby-identifier">wrap_lines_in_ascii</span>(<span class="ruby-identifier">encoded_o</span>, <span class="ruby-constant">BASE64_WRAP_LINE_LENGTH</span>, <span class="ruby-node">&quot;#{line_prefix}#{indent}&quot;</span>)
378
+ <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-node">&quot;[#{$/}&quot;</span>)
379
+ <span class="ruby-identifier">encoded_o</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{$/}#{line_prefix}]&quot;</span>
380
+ <span class="ruby-keyword kw">else</span>
381
+ <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-value str">&quot;[&quot;</span>)
382
+ <span class="ruby-identifier">encoded_o</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;]&quot;</span>
383
+ <span class="ruby-keyword kw">end</span>
384
+ <span class="ruby-keyword kw">end</span>
385
+
386
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">encoded_o</span>
387
+
388
+ <span class="ruby-comment cmt"># Below, we use &quot;#{o.year}&quot; instead of &quot;%Y&quot; because &quot;%Y&quot; always emit 4 chars at least even if</span>
389
+ <span class="ruby-comment cmt"># the date is before 1000.</span>
390
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">DateTime</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Time</span>)
391
+ <span class="ruby-identifier">milliseconds</span> = <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">DateTime</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">get_date_milliseconds</span>(<span class="ruby-identifier">o</span>) <span class="ruby-operator">:</span> (<span class="ruby-identifier">o</span>.<span class="ruby-identifier">usec</span> <span class="ruby-operator">/</span> <span class="ruby-value">10</span>).<span class="ruby-identifier">to_i</span>
392
+
393
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">milliseconds</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
394
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">zone</span>
395
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S%Z&quot;</span>)
396
+ <span class="ruby-keyword kw">else</span>
397
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S&quot;</span>)
398
+ <span class="ruby-keyword kw">end</span>
399
+ <span class="ruby-keyword kw">else</span>
400
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">zone</span>
401
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S.&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">milliseconds</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">ljust</span>(<span class="ruby-value">3</span>, <span class="ruby-value str">'0'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;%Z&quot;</span>)
402
+ <span class="ruby-keyword kw">else</span>
403
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S.&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">milliseconds</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">ljust</span>(<span class="ruby-value">3</span>, <span class="ruby-value str">'0'</span>))
404
+ <span class="ruby-keyword kw">end</span>
405
+ <span class="ruby-keyword kw">end</span>
406
+
407
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Date</span>)
408
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d&quot;</span>)
409
+
410
+ <span class="ruby-keyword kw">else</span>
411
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>
412
+ <span class="ruby-keyword kw">end</span>
413
+ <span class="ruby-keyword kw">end</span>
414
+ </pre>
415
+ </div>
416
+ </div>
417
+ </div>
418
+
419
+ <div id="method-M000003" class="method-detail">
420
+ <a name="M000003"></a>
421
+
422
+ <div class="method-heading">
423
+ <a href="#M000003" class="method-signature">
424
+ <span class="method-name">new_date_time</span><span class="method-args">(year, month, day, hour, min, sec, time_zone_offset)</span>
425
+ </a>
426
+ </div>
427
+
428
+ <div class="method-description">
429
+ <p>
430
+ Creates and returns the object representing a datetime (DateTime in the
431
+ default implementation). This method is, by default, called by the <a
432
+ href="SDL4R/Parser.html">Parser</a> class. It could be overriden as follows
433
+ in order to get Time instances from all the <a href="SDL4R.html">SDL4R</a>
434
+ parsers.
435
+ </p>
436
+ <pre>
437
+ module SDL4R
438
+ def self.new_date_time(year, month, day, hour, min, sec, time_zone_offset)
439
+ Time.utc(year, month, day, hour, min, sec)
440
+ end
441
+ end
442
+ </pre>
443
+ <p><a class="source-toggle" href="#"
444
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
445
+ <div class="method-source-code" id="M000003-source">
446
+ <pre>
447
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 137</span>
448
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new_date_time</span>(<span class="ruby-identifier">year</span>, <span class="ruby-identifier">month</span>, <span class="ruby-identifier">day</span>, <span class="ruby-identifier">hour</span>, <span class="ruby-identifier">min</span>, <span class="ruby-identifier">sec</span>, <span class="ruby-identifier">time_zone_offset</span>)
449
+ <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">civil</span>(<span class="ruby-identifier">year</span>, <span class="ruby-identifier">month</span>, <span class="ruby-identifier">day</span>, <span class="ruby-identifier">hour</span>, <span class="ruby-identifier">min</span>, <span class="ruby-identifier">sec</span>, <span class="ruby-identifier">time_zone_offset</span>)
450
+ <span class="ruby-keyword kw">end</span>
451
+ </pre>
452
+ </div>
453
+ </div>
454
+ </div>
455
+
456
+ <div id="method-M000006" class="method-detail">
457
+ <a name="M000006"></a>
458
+
459
+ <div class="method-heading">
460
+ <a href="#M000006" class="method-signature">
461
+ <span class="method-name">read</span><span class="method-args">(input)</span>
462
+ </a>
463
+ </div>
464
+
465
+ <div class="method-description">
466
+ <p>
467
+ Creates and returns a tag named &quot;root&quot; and add all the tags
468
+ specified in the given <tt>input</tt>.
469
+ </p>
470
+ <table>
471
+ <tr><td valign="top"><tt>input</tt>:</td><td>String, IO, Pathname or URI.
472
+
473
+ </td></tr>
474
+ </table>
475
+ <pre>
476
+ root = SDL4R::read(&lt;&lt;EOF
477
+ planets {
478
+ earth area_km2=510900000
479
+ mars
480
+ }
481
+ EOF
482
+ )
483
+
484
+ root = SDL4R::read(Pathname.new(&quot;my_dir/my_file.sdl&quot;))
485
+
486
+ IO.open(&quot;my_dir/my_file.sdl&quot;, &quot;r&quot;) { |io|
487
+ root = SDL4R::read(io)
488
+ }
489
+
490
+ root = SDL4R::read(URI.new(&quot;http://my_site/my_file.sdl&quot;))
491
+ </pre>
492
+ <p><a class="source-toggle" href="#"
493
+ onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
494
+ <div class="method-source-code" id="M000006-source">
495
+ <pre>
496
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 230</span>
497
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">input</span>)
498
+ <span class="ruby-constant">Tag</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;root&quot;</span>).<span class="ruby-identifier">read</span>(<span class="ruby-identifier">input</span>)
499
+ <span class="ruby-keyword kw">end</span>
500
+ </pre>
501
+ </div>
502
+ </div>
503
+ </div>
504
+
505
+ <div id="method-M000009" class="method-detail">
506
+ <a name="M000009"></a>
507
+
508
+ <div class="method-heading">
509
+ <a href="#M000009" class="method-signature">
510
+ <span class="method-name">to_attribute_map</span><span class="method-args">(s)</span>
511
+ </a>
512
+ </div>
513
+
514
+ <div class="method-description">
515
+ <p>
516
+ Parse a string representing the attributes portion of an SDL tag and return
517
+ the results as a map.
518
+ </p>
519
+ <p>
520
+ Example
521
+ </p>
522
+ <pre>
523
+ hash = SDL4R.to_attribute_hash(&quot;value=1 debugging=on time=12:24:01&quot;);
524
+
525
+ # { &quot;value&quot; =&gt; 1, &quot;debugging&quot; =&gt; true, &quot;time&quot; =&gt; SdlTimeSpan.new(12, 24, 01) }
526
+ </pre>
527
+ <p><a class="source-toggle" href="#"
528
+ onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
529
+ <div class="method-source-code" id="M000009-source">
530
+ <pre>
531
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 268</span>
532
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_attribute_map</span>(<span class="ruby-identifier">s</span>)
533
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;'s' cannot be null&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>
534
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read</span>(<span class="ruby-value str">&quot;atts &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">s</span>).<span class="ruby-identifier">child</span>.<span class="ruby-identifier">attributes</span>
535
+ <span class="ruby-keyword kw">end</span>
536
+ </pre>
537
+ </div>
538
+ </div>
539
+ </div>
540
+
541
+ <div id="method-M000007" class="method-detail">
542
+ <a name="M000007"></a>
543
+
544
+ <div class="method-heading">
545
+ <a href="#M000007" class="method-signature">
546
+ <span class="method-name">to_value</span><span class="method-args">(s)</span>
547
+ </a>
548
+ </div>
549
+
550
+ <div class="method-description">
551
+ <p>
552
+ Parses and returns the value corresponding with the specified SDL literal.
553
+ </p>
554
+ <pre>
555
+ SDL4R.to_value(&quot;\&quot;abcd\&quot;&quot;) # =&gt; &quot;abcd&quot;
556
+ SDL4R.to_value(&quot;1&quot;) # =&gt; 1
557
+ SDL4R.to_value(&quot;null&quot;) # =&gt; nil
558
+ </pre>
559
+ <p><a class="source-toggle" href="#"
560
+ onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
561
+ <div class="method-source-code" id="M000007-source">
562
+ <pre>
563
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 240</span>
564
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_value</span>(<span class="ruby-identifier">s</span>)
565
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;'s' cannot be null&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>
566
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">s</span>).<span class="ruby-identifier">child</span>.<span class="ruby-identifier">value</span>
567
+ <span class="ruby-keyword kw">end</span>
568
+ </pre>
569
+ </div>
570
+ </div>
571
+ </div>
572
+
573
+ <div id="method-M000008" class="method-detail">
574
+ <a name="M000008"></a>
575
+
576
+ <div class="method-heading">
577
+ <a href="#M000008" class="method-signature">
578
+ <span class="method-name">to_value_array</span><span class="method-args">(s)</span>
579
+ </a>
580
+ </div>
581
+
582
+ <div class="method-description">
583
+ <p>
584
+ Parse the string of values and return a list. The string is handled as if
585
+ it is the values portion of an SDL tag.
586
+ </p>
587
+ <p>
588
+ Example
589
+ </p>
590
+ <pre>
591
+ array = SDL4R.to_value_array(&quot;1 true 12:24:01&quot;)
592
+ </pre>
593
+ <p>
594
+ Will return an int, a boolean, and a time span.
595
+ </p>
596
+ <p><a class="source-toggle" href="#"
597
+ onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
598
+ <div class="method-source-code" id="M000008-source">
599
+ <pre>
600
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 254</span>
601
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_value_array</span>(<span class="ruby-identifier">s</span>)
602
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;'s' cannot be null&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>
603
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">s</span>).<span class="ruby-identifier">child</span>.<span class="ruby-identifier">values</span>
604
+ <span class="ruby-keyword kw">end</span>
605
+ </pre>
606
+ </div>
607
+ </div>
608
+ </div>
609
+
610
+ <div id="method-M000005" class="method-detail">
611
+ <a name="M000005"></a>
612
+
613
+ <div class="method-heading">
614
+ <a href="#M000005" class="method-signature">
615
+ <span class="method-name">validate_identifier</span><span class="method-args">(identifier)</span>
616
+ </a>
617
+ </div>
618
+
619
+ <div class="method-description">
620
+ <p>
621
+ Validates an SDL identifier String. SDL Identifiers must start with a
622
+ Unicode letter or underscore (_) and contain only unicode letters, digits,
623
+ underscores (_), dashes(-) and periods (.).
624
+ </p>
625
+ <h2>Raises</h2>
626
+ <p>
627
+ ArgumentError if the identifier is not legal
628
+ </p>
629
+ <p>
630
+ TODO: support UTF-8 identifiers
631
+ </p>
632
+ <p><a class="source-toggle" href="#"
633
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
634
+ <div class="method-source-code" id="M000005-source">
635
+ <pre>
636
+ <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 182</span>
637
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">validate_identifier</span>(<span class="ruby-identifier">identifier</span>)
638
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">empty?</span>
639
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;SDL identifiers cannot be null or empty.&quot;</span>
640
+ <span class="ruby-keyword kw">end</span>
641
+
642
+ <span class="ruby-comment cmt"># in Java, was if(!Character.isJavaIdentifierStart(identifier.charAt(0)))</span>
643
+ <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">identifier</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[a-zA-Z_]/</span>
644
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,
645
+ <span class="ruby-value str">&quot;'&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">identifier</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">0</span>] <span class="ruby-operator">+</span>
646
+ <span class="ruby-value str">&quot;' is not a legal first character for an SDL identifier. &quot;</span> <span class="ruby-operator">+</span>
647
+ <span class="ruby-value str">&quot;SDL Identifiers must start with a unicode letter or &quot;</span> <span class="ruby-operator">+</span>
648
+ <span class="ruby-value str">&quot;an underscore (_).&quot;</span>
649
+ <span class="ruby-keyword kw">end</span>
650
+
651
+ <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">identifier</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[a-zA-Z_][a-zA-Z_0-9\-\.]*$/</span>
652
+ <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">length</span>
653
+ <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">identifier</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">..</span><span class="ruby-identifier">i</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[a-zA-Z_0-9\-]$/</span>
654
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,
655
+ <span class="ruby-value str">&quot;'&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">identifier</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">..</span><span class="ruby-identifier">i</span>] <span class="ruby-operator">+</span>
656
+ <span class="ruby-value str">&quot;' is not a legal character for an SDL identifier. &quot;</span> <span class="ruby-operator">+</span>
657
+ <span class="ruby-value str">&quot;SDL Identifiers must start with a unicode letter or &quot;</span> <span class="ruby-operator">+</span>
658
+ <span class="ruby-value str">&quot;underscore (_) followed by 0 or more unicode &quot;</span> <span class="ruby-operator">+</span>
659
+ <span class="ruby-value str">&quot;letters, digits, underscores (_), or dashes (-)&quot;</span>
660
+ <span class="ruby-keyword kw">end</span>
661
+ <span class="ruby-keyword kw">end</span>
662
+ <span class="ruby-keyword kw">end</span>
663
+ <span class="ruby-keyword kw">end</span>
664
+ </pre>
665
+ </div>
666
+ </div>
667
+ </div>
668
+
669
+
670
+ </div>
671
+
672
+
673
+ </div>
674
+
675
+
676
+ <div id="validator-badges">
677
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
678
+ </div>
679
+
680
+ </body>
681
+ </html>