Class: WirisPlugin::StringParser

Inherits:
Object
  • Object
show all
Includes:
Wiris
Defined in:
lib/com/wiris/util/json/StringParser.rb

Direct Known Subclasses

JSon

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStringParser

Returns a new instance of StringParser.



11
12
13
# File 'lib/com/wiris/util/json/StringParser.rb', line 11

def initialize()
    super()
end

Instance Attribute Details

#cObject

Returns the value of attribute c.



9
10
11
# File 'lib/com/wiris/util/json/StringParser.rb', line 9

def c
  @c
end

#iObject

Returns the value of attribute i.



7
8
9
# File 'lib/com/wiris/util/json/StringParser.rb', line 7

def i
  @i
end

#nObject

Returns the value of attribute n.



8
9
10
# File 'lib/com/wiris/util/json/StringParser.rb', line 8

def n
  @n
end

#strObject

Returns the value of attribute str.



10
11
12
# File 'lib/com/wiris/util/json/StringParser.rb', line 10

def str
  @str
end

Class Method Details

.isBlank(c) ⇒ Object



39
40
41
# File 'lib/com/wiris/util/json/StringParser.rb', line 39

def self.isBlank(c)
    return ((((c == 32) || (c == 10)) || (c == 13)) || (c == 9)) || (c == 160)
end

Instance Method Details

#getPositionRepresentationObject



42
43
44
45
46
47
# File 'lib/com/wiris/util/json/StringParser.rb', line 42

def getPositionRepresentation()
    i0 = WInteger::min(@i,@n)
    s0 = WInteger::max(0,@i - 20)
    e0 = WInteger::min(@n,@i + 20)
    return (("..." + Std::substr(@str,s0,i0 - s0).to_s) + " >>> . <<<") + Std::substr(@str,i0,e0).to_s
end

#init(str) ⇒ Object



14
15
16
17
18
19
# File 'lib/com/wiris/util/json/StringParser.rb', line 14

def init(str)
    self.str = str
    @i = 0
    @n = str::length()
    nextToken()
end

#isHexDigit(c) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/com/wiris/util/json/StringParser.rb', line 48

def isHexDigit(c)
    if (c >= 48) && (c <= 58)
        return true
    end
    if (c >= 97) && (c <= 102)
        return true
    end
    if (c >= 65) && (c <= 70)
        return true
    end
    return false
end

#nextSafeTokenObject



31
32
33
34
35
36
37
38
# File 'lib/com/wiris/util/json/StringParser.rb', line 31

def nextSafeToken()
    if @i < @n
        @c = Utf8::charCodeAt(Std::substr(@str,@i),0)
        @i += (Utf8::uchr(@c))::length()
    else 
        @c = -1
    end
end

#nextTokenObject



25
26
27
28
29
30
# File 'lib/com/wiris/util/json/StringParser.rb', line 25

def nextToken()
    if @c == -1
        raise Exception,"End of string"
    end
    nextSafeToken()
end

#skipBlanksObject



20
21
22
23
24
# File 'lib/com/wiris/util/json/StringParser.rb', line 20

def skipBlanks()
    while (@i < @n) && StringParser.isBlank(@c)
        nextToken()
    end
end