Class: WirisPlugin::JSon
- Inherits:
-
StringParser
- Object
- StringParser
- WirisPlugin::JSon
- Includes:
- Wiris
- Defined in:
- lib/com/wiris/util/json/JSon.rb
Instance Attribute Summary collapse
-
#addNewLines ⇒ Object
Returns the value of attribute addNewLines.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#lastDepth ⇒ Object
Returns the value of attribute lastDepth.
Attributes inherited from StringParser
Class Method Summary collapse
- .compare(a, b, eps) ⇒ Object
- .decode(str) ⇒ Object
- .encode(o) ⇒ Object
- .getArray(a) ⇒ Object
- .getBoolean(b) ⇒ Object
- .getDepth(o) ⇒ Object
- .getFloat(n) ⇒ Object
- .getHash(a) ⇒ Object
- .getInt(n) ⇒ Object
- .getString(o) ⇒ Object
- .main(args) ⇒ Object
- .sb ⇒ Object
- .sb=(sb) ⇒ Object
Instance Method Summary collapse
- #decodeArray ⇒ Object
- #decodeBooleanOrNull ⇒ Object
- #decodeHash ⇒ Object
- #decodeNumber ⇒ Object
- #decodeString ⇒ Object
- #encodeArray(sb, v) ⇒ Object
- #encodeBoolean(sb, b) ⇒ Object
- #encodeFloat(sb, d) ⇒ Object
- #encodeHash(sb, h) ⇒ Object
- #encodeImpl(sb, o) ⇒ Object
- #encodeInteger(sb, i) ⇒ Object
- #encodeIntegerFormat(sb, i) ⇒ Object
- #encodeLong(sb, i) ⇒ Object
- #encodeObject(o) ⇒ Object
- #encodeString(sb, s) ⇒ Object
-
#initialize ⇒ JSon
constructor
A new instance of JSon.
- #localDecode ⇒ Object
- #localDecodeString(str) ⇒ Object
- #newLine(depth, sb) ⇒ Object
- #setAddNewLines(addNewLines) ⇒ Object
Methods inherited from StringParser
#getPositionRepresentation, #init, isBlank, #isHexDigit, #nextSafeToken, #nextToken, #skipBlanks
Constructor Details
#initialize ⇒ JSon
20 21 22 |
# File 'lib/com/wiris/util/json/JSon.rb', line 20 def initialize() super() end |
Instance Attribute Details
#addNewLines ⇒ Object
Returns the value of attribute addNewLines.
17 18 19 |
# File 'lib/com/wiris/util/json/JSon.rb', line 17 def addNewLines @addNewLines end |
#depth ⇒ Object
Returns the value of attribute depth.
18 19 20 |
# File 'lib/com/wiris/util/json/JSon.rb', line 18 def depth @depth end |
#lastDepth ⇒ Object
Returns the value of attribute lastDepth.
19 20 21 |
# File 'lib/com/wiris/util/json/JSon.rb', line 19 def lastDepth @lastDepth end |
Class Method Details
.compare(a, b, eps) ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/com/wiris/util/json/JSon.rb', line 433 def self.compare(a,b,eps) if TypeTools::isHash(a) isBHash = TypeTools::isHash(b) if !isBHash return false end ha = (a) hb = (b) it = ha::keys() itb = hb::keys() while it::hasNext() if !itb::hasNext() return false end itb::next() key = it::next() if !hb::exists(key)||!compare(ha::get(key),hb::get(key),eps) return false end end if itb::hasNext() return false end return true else if TypeTools::isArray(a) isBArray = TypeTools::isArray(b) if !isBArray return false end aa = (a) ab = (b) if aa::length()!=ab::length() return false end for i in 0..aa::length()-1 if !compare(aa::_(i),ab::_(i),eps) return false end i+=1 end return true else if a.instance_of?String if !(b.instance_of?String) return false end return (a==b) else if a.instance_of?Integer if !(b.instance_of?Integer) return false end return (a==b) else if a.instance_of?Long isBLong = b.instance_of?Long if !isBLong return false end return (a==b) else if a.instance_of?JSonIntegerFormat if !(b.instance_of?JSonIntegerFormat) return false end ja = (a) jb = (b) return (ja::toString()==jb::toString()) else if a.instance_of?Boolean if !(b.instance_of?Boolean) return false end return (a==b) else if a.instance_of?Double if !(b.instance_of?Double) return false end da = getFloat(a) db = getFloat(b) return (da>=(db-eps))&&(da<=(db+eps)) end end end end end end end end return true end |
.decode(str) ⇒ Object
167 168 169 170 |
# File 'lib/com/wiris/util/json/JSon.rb', line 167 def self.decode(str) json = JSon.new() return json::localDecodeString(str) end |
.encode(o) ⇒ Object
23 24 25 26 |
# File 'lib/com/wiris/util/json/JSon.rb', line 23 def self.encode(o) js = JSon.new() return js::encodeObject(o) end |
.getArray(a) ⇒ Object
427 428 429 |
# File 'lib/com/wiris/util/json/JSon.rb', line 427 def self.getArray(a) return (a) end |
.getBoolean(b) ⇒ Object
424 425 426 |
# File 'lib/com/wiris/util/json/JSon.rb', line 424 def self.getBoolean(b) return ((b))::booleanValue() end |
.getDepth(o) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/com/wiris/util/json/JSon.rb', line 355 def self.getDepth(o) if TypeTools::isHash(o) h = (o) m = 0 if h::exists("_left_")||h::exists("_right_") if h::exists("_left_") m = WInteger::max(getDepth(h::get("_left_")),m) end if h::exists("_right_") m = WInteger::max(getDepth(h::get("_right_")),m) end return m end iter = h::keys() while iter::hasNext() key = iter::next() m = WInteger::max(getDepth(h::get(key)),m) end return m+2 else if TypeTools::isArray(o) a = (o) m = 0 for i in 0..a::length()-1 m = WInteger::max(getDepth(a::_(i)),m) i+=1 end return m+1 else return 1 end end end |
.getFloat(n) ⇒ Object
402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/com/wiris/util/json/JSon.rb', line 402 def self.getFloat(n) if n.instance_of?Double return (n) else if n.instance_of?Integer return (n)+0.0 else return 0.0 end end end |
.getHash(a) ⇒ Object
430 431 432 |
# File 'lib/com/wiris/util/json/JSon.rb', line 430 def self.getHash(a) return (a) end |
.getInt(n) ⇒ Object
413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/com/wiris/util/json/JSon.rb', line 413 def self.getInt(n) if n.instance_of?Double return (Math::round((n))) else if n.instance_of?Integer return (n) else return 0 end end end |
.getString(o) ⇒ Object
399 400 401 |
# File 'lib/com/wiris/util/json/JSon.rb', line 399 def self.getString(o) return (o) end |
.main(args) ⇒ Object
526 527 528 529 530 531 532 533 534 |
# File 'lib/com/wiris/util/json/JSon.rb', line 526 def self.main(args) s1 = "{\"displays\":[{\"horizontal_axis_values_position\":\"below\",\"vertical_axis_label\":\"\",\"window_width\":450.,\"horizontal_axis_label\":\"\",\"styles\":[{\"color\":\"#9a0000\",\"ref\":\"line1\"},{\"color\":\"#105b5c\",\"ref\":\"conic1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point2\"}],\"window_height\":450.,\"height\":21.,\"id\":\"plotter1\",\"grid_y\":true,\"width\":21.,\"grid_x\":true,\"axis_color\":\"#9696ff\",\"vertical_axis_values_position\":\"left\",\"grid_primary_color\":\"#ffc864\",\"background_color\":\"#fffff0\",\"axis_y\":true,\"axis_x\":true,\"center\":[0.,0.]}],\"elements\":[{\"type\":\"line_segment\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><ci>y</ci><ci>x</ci></apply></math>\",\"coordinates\":[[-31.5,-31.5],[31.5,31.5]],\"id\":\"line1\"},{\"type\":\"path\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><apply><plus></plus><apply><times></times><apply><minus></minus><apply><divide></divide><cn>1</cn><cn>4</cn></apply></apply><apply><power></power><ci>x</ci><cn>2</cn></apply></apply><ci>y</ci><cn>4</cn></apply><cn>0</cn></apply></math>\",\"coordinates\":[[9.795918464660645,19.99000358581543],[9.387755393981934,18.032485961914062],[8.979591369628906,16.158267974853516],[8.571428298950195,14.36734676361084],[8.163265228271484,12.659725189208984],[7.755102157592773,11.035402297973633],[7.346938610076904,9.494377136230469],[6.938775539398193,8.036651611328125],[6.530612468719482,6.662224292755127],[6.122448921203613,5.371095180511475],[5.714285850524902,4.163265228271484],[5.306122303009033,3.038733959197998],[4.897959232330322,1.997501015663147],[4.489795684814453,1.0395668745040894],[4.081632614135742,0.1649312824010849],[3.673469305038452,-0.626405656337738],[3.265306234359741,-1.3344439268112183],[2.857142925262451,-1.959183692932129],[2.448979616165161,-2.500624656677246],[2.040816307067871,-2.9587671756744385],[1.6326531171798706,-3.333611011505127],[1.2244898080825806,-3.6251561641693115],[0.8163265585899353,-3.833402633666992],[0.40816327929496765,-3.958350658416748],[0.,-4.],[-0.40816327929496765,-3.958350658416748],[-0.8163265585899353,-3.833402633666992],[-1.2244898080825806,-3.6251561641693115],[-1.6326531171798706,-3.333611011505127],[-2.040816307067871,-2.9587671756744385],[-2.448979616165161,-2.500624656677246],[-2.857142925262451,-1.959183692932129],[-3.265306234359741,-1.3344439268112183],[-3.673469305038452,-0.626405656337738],[-4.081632614135742,0.1649312824010849],[-4.489795684814453,1.0395668745040894],[-4.897959232330322,1.997501015663147],[-5.306122303009033,3.038733959197998],[-5.714285850524902,4.163265228271484],[-6.122448921203613,5.371095180511475],[-6.530612468719482,6.662224292755127],[-6.938775539398193,8.036651611328125],[-7.346938610076904,9.494377136230469],[-7.755102157592773,11.035402297973633],[-8.163265228271484,12.659725189208984],[-8.571428298950195,14.36734676361084],[-8.979591369628906,16.158267974853516],[-9.387755393981934,18.032485961914062],[-9.795918464660645,19.99000358581543],[-10.204081535339355,22.030820846557617]],\"id\":\"conic1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[-2.4721360206604004,-2.4721360206604004],\"id\":\"point1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[6.4721360206604,6.4721360206604],\"id\":\"point2\"}],\"constraints\":[]}" s2 = "{\"displays\":[{\"horizontal-axis-values-position\":\"below\",\"vertical-axis-label\":\"\",\"window-width\":450.,\"styles\":[{\"color\":\"#9a0000\",\"ref\":\"line1\"},{\"color\":\"#105b5c\",\"ref\":\"conic1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point1\"},{\"color\":\"#a3b017\",\"fixed\":false,\"ref\":\"point2\"}],\"background-color\":\"#fffff0\",\"height\":21.,\"id\":\"plotter1\",\"grid-y\":true,\"window-height\":450.,\"grid-x\":true,\"width\":21.,\"horizontal-axis-label\":\"\",\"vertical-axis-values-position\":\"left\",\"grid-primary-color\":\"#ffc864\",\"axis-color\":\"#9696ff\",\"axis-y\":true,\"axis-x\":true,\"center\":[0.,0.]}],\"elements\":[{\"type\":\"line_segment\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><ci>y</ci><ci>x</ci></apply></math>\",\"coordinates\":[[-31.5,-31.5],[31.5,31.5]],\"id\":\"line1\"},{\"type\":\"path\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><apply><eq></eq><apply><plus></plus><apply><times></times><apply><minus></minus><apply><divide></divide><cn>1</cn><cn>4</cn></apply></apply><apply><power></power><ci>x</ci><cn>2</cn></apply></apply><ci>y</ci><cn>4</cn></apply><cn>0</cn></apply></math>\",\"coordinates\":[[9.795918464660645,19.99000358581543],[9.387755393981934,18.032485961914062],[8.979591369628906,16.158267974853516],[8.571428298950195,14.36734676361084],[8.163265228271484,12.659725189208984],[7.755102157592773,11.035402297973633],[7.346938610076904,9.494377136230469],[6.938775539398193,8.036651611328125],[6.530612468719482,6.662224292755127],[6.122448921203613,5.371095180511475],[5.714285850524902,4.163265228271484],[5.306122303009033,3.038733959197998],[4.897959232330322,1.997501015663147],[4.489795684814453,1.0395668745040894],[4.081632614135742,0.1649312824010849],[3.673469305038452,-0.626405656337738],[3.265306234359741,-1.3344439268112183],[2.857142925262451,-1.959183692932129],[2.448979616165161,-2.500624656677246],[2.040816307067871,-2.9587671756744385],[1.6326531171798706,-3.333611011505127],[1.2244898080825806,-3.6251561641693115],[0.8163265585899353,-3.833402633666992],[0.40816327929496765,-3.958350658416748],[0.,-4.],[-0.40816327929496765,-3.958350658416748],[-0.8163265585899353,-3.833402633666992],[-1.2244898080825806,-3.6251561641693115],[-1.6326531171798706,-3.333611011505127],[-2.040816307067871,-2.9587671756744385],[-2.448979616165161,-2.500624656677246],[-2.857142925262451,-1.959183692932129],[-3.265306234359741,-1.3344439268112183],[-3.673469305038452,-0.626405656337738],[-4.081632614135742,0.1649312824010849],[-4.489795684814453,1.0395668745040894],[-4.897959232330322,1.997501015663147],[-5.306122303009033,3.038733959197998],[-5.714285850524902,4.163265228271484],[-6.122448921203613,5.371095180511475],[-6.530612468719482,6.662224292755127],[-6.938775539398193,8.036651611328125],[-7.346938610076904,9.494377136230469],[-7.755102157592773,11.035402297973633],[-8.163265228271484,12.659725189208984],[-8.571428298950195,14.36734676361084],[-8.979591369628906,16.158267974853516],[-9.387755393981934,18.032485961914062],[-9.795918464660645,19.99000358581543],[-10.204081535339355,22.030820846557617]],\"id\":\"conic1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><apply><minus></minus><cn>2</cn></apply><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[-2.4721360206604004,-2.4721360206604004],\"id\":\"point1\"},{\"type\":\"point\",\"value-content\":\"<math xmlns=\\\"http://www.w3.org/1998/Math/MathML\\\"><vector><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply><apply><plus></plus><apply><times></times><cn>2</cn><apply><root></root><cn>5</cn></apply></apply><cn>2</cn></apply></vector></math>\",\"coordinates\":[6.4721360206604,6.4721360206604],\"id\":\"point2\"}],\"constraints\":[]}" if JSon::compare(JSon::decode(s1),JSon::decode(s2),1.0E-8) Std::trace("Equal") else Std::trace("Not equal") end end |
.sb ⇒ Object
11 12 13 |
# File 'lib/com/wiris/util/json/JSon.rb', line 11 def self.sb @@sb end |
.sb=(sb) ⇒ Object
14 15 16 |
# File 'lib/com/wiris/util/json/JSon.rb', line 14 def self.sb=(sb) @@sb = sb end |
Instance Method Details
#decodeArray ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/com/wiris/util/json/JSon.rb', line 331 def decodeArray() v = Array.new() nextToken() skipBlanks() if c==93 nextToken() return v end while c!=93 o = localDecode() v::push(o) skipBlanks() if c==44 nextToken() skipBlanks() else if c!=93 raise Exception,"Expected \',\' or \']\'." end end end nextToken() return v end |
#decodeBooleanOrNull ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/com/wiris/util/json/JSon.rb', line 203 def decodeBooleanOrNull() sb = StringBuf.new() while WCharacterBase::isLetter(c) sb::addChar(c) nextToken() end word = sb::toString() if (word=="true") return Boolean::TRUE else if (word=="false") return Boolean::FALSE else if (word=="null") return nil else raise Exception,("Unrecognized keyword \""+word)+"\"." end end end end |
#decodeHash ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/com/wiris/util/json/JSon.rb', line 300 def decodeHash() h = Hash.new() nextToken() skipBlanks() if c==125 nextToken() return h end while c!=125 key = decodeString() skipBlanks() if c!=58 raise Exception,"Expected \':\'." end nextToken() skipBlanks() o = localDecode() h::set(key,o) skipBlanks() if c==44 nextToken() skipBlanks() else if c!=125 raise Exception,"Expected \',\' or \'}\'. "+getPositionRepresentation() end end end nextToken() return h end |
#decodeNumber ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/com/wiris/util/json/JSon.rb', line 277 def decodeNumber() sb = StringBuf.new() hex = false floating = false loop do sb::add(Std::fromCharCode(c)) nextToken() if c==120 hex = true sb::add(Std::fromCharCode(c)) nextToken() end if ((c==46)||(c==69))||(c==101) floating = true end break if not (((c>=48)&&(c<=58))||(hex&&isHexDigit(c)))||(floating&&((((c==46)||(c==69))||(c==101))||(c==45))) end if floating return Std::parseFloat(sb::toString()) else return Std::parseInt(sb::toString()) end end |
#decodeString ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/com/wiris/util/json/JSon.rb', line 224 def decodeString() sb = StringBuf.new() d = c nextToken() while c!=d if c==92 nextToken() if c==110 sb::add("\n") else if c==114 sb::add("\r") else if c==34 sb::add("\"") else if c==39 sb::add("\'") else if c==116 sb::add("\t") else if c==92 sb::add("\\") else if c==117 nextToken() code = Utf8::uchr(c) nextToken() code+=Utf8::uchr(c) nextToken() code+=Utf8::uchr(c) nextToken() code+=Utf8::uchr(c) dec = Std::parseInt("0x"+code) sb::add(Utf8::uchr(dec)) else raise Exception,("Unknown scape sequence \'\\"+Utf8::uchr(c).to_s)+"\'" end end end end end end end else sb::add(Std::fromCharCode(c)) end nextToken() end nextToken() return sb::toString() end |
#encodeArray(sb, v) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/com/wiris/util/json/JSon.rb', line 98 def encodeArray(sb,v) newLines = @addNewLines&&(self.class.getDepth(v)>2) @depth+=1 myDepth = @lastDepth sb::add("[") if newLines newLine(@depth,sb) end for i in 0..v::length()-1 o = v::_(i) if i>0 sb::add(",") if newLines newLine(@depth,sb) end end encodeImpl(sb,o) i+=1 end if newLines newLine(myDepth,sb) end sb::add("]") @depth-=1 end |
#encodeBoolean(sb, b) ⇒ Object
155 156 157 |
# File 'lib/com/wiris/util/json/JSon.rb', line 155 def encodeBoolean(sb,b) sb::add(b::booleanValue() ? "true" : "false") end |
#encodeFloat(sb, d) ⇒ Object
158 159 160 |
# File 'lib/com/wiris/util/json/JSon.rb', line 158 def encodeFloat(sb,d) sb::add(TypeTools::floatToString(d)) end |
#encodeHash(sb, h) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/com/wiris/util/json/JSon.rb', line 68 def encodeHash(sb,h) newLines = @addNewLines&&(self.class.getDepth(h)>2) @depth+=1 myDepth = @lastDepth sb::add("{") if newLines newLine(@depth,sb) end e = h::keys() first = true while e::hasNext() if first first = false else sb::add(",") if newLines newLine(@depth,sb) end end key = e::next() encodeString(sb,key) sb::add(":") encodeImpl(sb,h::get(key)) end if newLines newLine(myDepth,sb) end sb::add("}") @depth-=1 end |
#encodeImpl(sb, o) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/com/wiris/util/json/JSon.rb', line 33 def encodeImpl(sb,o) if TypeTools::isHash(o) encodeHash(sb,(o)) else if TypeTools::isArray(o) encodeArray(sb,(o)) else if o.instance_of?String encodeString(sb,(o)) else if o.instance_of?Integer encodeInteger(sb,(o)) else if o.instance_of?Long encodeLong(sb,(o)) else if o.instance_of?JSonIntegerFormat encodeIntegerFormat(sb,(o)) else if o.instance_of?Boolean encodeBoolean(sb,(o)) else if o.instance_of?Double encodeFloat(sb,(o)) else raise Exception,"Impossible to convert to json object of type "+Type::getClass(o).to_s end end end end end end end end end |
#encodeInteger(sb, i) ⇒ Object
152 153 154 |
# File 'lib/com/wiris/util/json/JSon.rb', line 152 def encodeInteger(sb,i) sb::add(""+i.to_s) end |
#encodeIntegerFormat(sb, i) ⇒ Object
164 165 166 |
# File 'lib/com/wiris/util/json/JSon.rb', line 164 def encodeIntegerFormat(sb,i) sb::add(i::toString()) end |
#encodeLong(sb, i) ⇒ Object
161 162 163 |
# File 'lib/com/wiris/util/json/JSon.rb', line 161 def encodeLong(sb,i) sb::add(""+i.to_s) end |
#encodeObject(o) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/com/wiris/util/json/JSon.rb', line 27 def encodeObject(o) sb = StringBuf.new() @depth = 0 encodeImpl(sb,o) return sb::toString() end |
#encodeString(sb, s) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/com/wiris/util/json/JSon.rb', line 123 def encodeString(sb,s) sb::add("\"") for i in 0..s::length()-1 c = Std::charCodeAt(s,i) if c==34 sb::add("\\\"") else if c==13 sb::add("\\r") else if c==10 sb::add("\\n") else if c==9 sb::add("\\t") else if c==92 sb::add("\\\\") else sb::add(s::charAt(i)) end end end end end i+=1 end sb::add("\"") end |
#localDecode ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/com/wiris/util/json/JSon.rb', line 175 def localDecode() skipBlanks() if c==123 return decodeHash() else if c==91 return decodeArray() else if c==34 return decodeString() else if c==39 return decodeString() else if (c==45)||((c>=48)&&(c<=58)) return decodeNumber() else if ((c==116)||(c==102))||(c==110) return decodeBooleanOrNull() else raise Exception,"Unrecognized char "+c.to_s end end end end end end end |
#localDecodeString(str) ⇒ Object
171 172 173 174 |
# File 'lib/com/wiris/util/json/JSon.rb', line 171 def localDecodeString(str) init(str) return localDecode() end |
#newLine(depth, sb) ⇒ Object
391 392 393 394 395 396 397 398 |
# File 'lib/com/wiris/util/json/JSon.rb', line 391 def newLine(depth,sb) sb::add("\r\n") for i in 0..depth-1 sb::add(" ") i+=1 end @lastDepth = depth end |
#setAddNewLines(addNewLines) ⇒ Object
388 389 390 |
# File 'lib/com/wiris/util/json/JSon.rb', line 388 def setAddNewLines(addNewLines) @addNewLines = addNewLines end |