Class: WirisPlugin::UrlUtils

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

Constant Summary collapse

@@charCodeA =
Std::charCodeAt("A",0)
@@charCodeZ =
Std::charCodeAt("Z",0)
@@charCodea =
Std::charCodeAt("a",0)
@@charCodez =
Std::charCodeAt("z",0)
@@charCode0 =
Std::charCodeAt("0",0)
@@charCode9 =
Std::charCodeAt("9",0)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUrlUtils

Returns a new instance of UrlUtils.



6
7
8
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 6

def initialize()
    super()
end

Class Method Details

.charCode0Object



38
39
40
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 38

def self.charCode0
    @@charCode0
end

.charCode0=(charCode0) ⇒ Object



41
42
43
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 41

def self.charCode0=(charCode0)
    @@charCode0 = charCode0
end

.charCode9Object



45
46
47
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 45

def self.charCode9
    @@charCode9
end

.charCode9=(charCode9) ⇒ Object



48
49
50
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 48

def self.charCode9=(charCode9)
    @@charCode9 = charCode9
end

.charCodeAObject



10
11
12
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 10

def self.charCodeA
    @@charCodeA
end

.charCodeaObject



24
25
26
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 24

def self.charCodea
    @@charCodea
end

.charCodeA=(charCodeA) ⇒ Object



13
14
15
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 13

def self.charCodeA=(charCodeA)
    @@charCodeA = charCodeA
end

.charCodea=(charCodea) ⇒ Object



27
28
29
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 27

def self.charCodea=(charCodea)
    @@charCodea = charCodea
end

.charCodezObject



31
32
33
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 31

def self.charCodez
    @@charCodez
end

.charCodeZObject



17
18
19
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 17

def self.charCodeZ
    @@charCodeZ
end

.charCodeZ=(charCodeZ) ⇒ Object



20
21
22
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 20

def self.charCodeZ=(charCodeZ)
    @@charCodeZ = charCodeZ
end

.charCodez=(charCodez) ⇒ Object



34
35
36
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 34

def self.charCodez=(charCodez)
    @@charCodez = charCodez
end

.isAllowed(c) ⇒ Object



51
52
53
54
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 51

def self.isAllowed(c)
    allowedChars = "-_.!~*\'()"::indexOf(Std::fromCharCode(c)) != -1
    return ((((c >= @@charCodeA) && (c <= @@charCodeZ)) || ((c >= @@charCodea) && (c <= @@charCodez))) || ((c >= @@charCode0) && (c <= @@charCode9))) || allowedChars
end

.urlComponentEncode(uriComponent) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/com/wiris/util/type/UrlUtils.rb', line 55

def self.urlComponentEncode(uriComponent)
    sb = StringBuf.new()
    buf = Bytes::ofData(Utf8::toBytes(uriComponent))
    for i in 0..buf::length() - 1
        b = buf::get(i)&255
        if UrlUtils.isAllowed(b)
            sb::add(Std::fromCharCode(b))
        else 
            sb::add("%")
            sb::add(StringTools::hex(b,2))
        end
        i+=1
    end
    return sb::toString()
end