Class: Wiris::StringTools

Inherits:
Object
  • Object
show all
Defined in:
lib/src-generic/StringTools.rb

Class Method Summary collapse

Class Method Details

.compare(s1, s2) ⇒ Object



40
41
42
# File 'lib/src-generic/StringTools.rb', line 40

def self.compare(s1,s2)
    return s1<=>s2
end

.endsWith(s, ends) ⇒ Object



16
17
18
# File 'lib/src-generic/StringTools.rb', line 16

def self.endsWith(s, ends)
    return s.end_with?(ends)
end

.hex(n, digits) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/src-generic/StringTools.rb', line 32

def self.hex(n, digits)
    hex = n.to_s(16).upcase
    while hex.length() < digits
        hex = "0" + hex
    end
    return hex.upcase
end

.replace(text, target, replacement) ⇒ Object



5
6
7
8
9
10
# File 'lib/src-generic/StringTools.rb', line 5

def self.replace(text, target, replacement)
    # Block syntax is used due to if we put 'replacement' as a
    # normal parameter, Ruby interpretes escape characters.
    text = text.gsub(target) { replacement }
    return text
end

.startsWith(s, start) ⇒ Object



12
13
14
# File 'lib/src-generic/StringTools.rb', line 12

def self.startsWith(s, start)
    return s.start_with?(start)
end

.trim(s) ⇒ Object



28
29
30
# File 'lib/src-generic/StringTools.rb', line 28

def self.trim(s)
    return s.strip
end

.urlDecode(s) ⇒ Object



24
25
26
# File 'lib/src-generic/StringTools.rb', line 24

def self.urlDecode(s)
    return URI.unescape(s)
end

.urlEncode(s) ⇒ Object



20
21
22
# File 'lib/src-generic/StringTools.rb', line 20

def self.urlEncode(s)
    return ERB::Util::url_encode(s);
end