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

public static byte[] string2Bytes(String str) {

    try {
        return str.getBytes("iso-8859-1");
    } catch (UnsupportedEncodingException ex) {
        throw new Error(ex);
    }
}


42
43
44
# File 'lib/src-generic/StringTools.rb', line 42

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

.endsWith(s, ends) ⇒ Object



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

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

.hex(n, digits) ⇒ Object



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

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

.replace(text, target, replacement) ⇒ Object



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

def self.replace(text, target, replacement)
    text = text.gsub(target, replacement)
    return text
end

.startsWith(s, start) ⇒ Object



9
10
11
# File 'lib/src-generic/StringTools.rb', line 9

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

.trim(s) ⇒ Object



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

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

.urlEncode(s) ⇒ Object

TODO Implement unsupoortedEncodingException?



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

def self.urlEncode(s) #TODO Implement unsupoortedEncodingException? 

    return CGI::escape(s)
end