class WirisPlugin::StringUtils

Public Class Methods

compareIgnoringAccents(a, b) click to toggle source
# File lib/com/wiris/util/type/StringUtils.rb, line 32
def self.compareIgnoringAccents(a, b)
    return (StringUtils::stripAccents(a) == StringUtils::stripAccents(b))
end
compareVersions(a, b) click to toggle source
# File lib/com/wiris/util/type/StringUtils.rb, line 54
def self.compareVersions(a, b)
    va = Std::split(a,".")
    vb = Std::split(b,".")
    i = 0
    while i < va::length()
        na = Std::parseInt(va::_(i))
        nb = 0
        if i < vb::length()
            nb = Std::parseInt(vb::_(i))
        end
        n = na - nb
        if n != 0
            return n
        end
        i+=1
    end
    while i < vb::length()
        nb = Std::parseInt(vb::_(i))
        if nb != 0
            return -nb
        end
        i+=1
    end
    return 0
end
new() click to toggle source
Calls superclass method
# File lib/com/wiris/util/type/StringUtils.rb, line 8
def initialize()
    super()
end
padLeftZeros(s, length) click to toggle source
# File lib/com/wiris/util/type/StringUtils.rb, line 19
        def self.padLeftZeros(s, length)
            if (s == nil) || (s::length() >= length)
                return s
            end
            stringBuf = StringBuf.new()
            for  = s::length()
length - 1
                stringBuf::add("0")
                i+=1
            end
            stringBuf::add(s)
            return stringBuf::toString()
        end
slice(s, beginIndex, endIndex) click to toggle source
# File lib/com/wiris/util/type/StringUtils.rb, line 35
def self.slice(s, beginIndex, endIndex)
    stringLength = s::length()
    if beginIndex < 0
        beginIndex = IntegerTools::max(0,stringLength + beginIndex)
    else 
        if beginIndex > stringLength
            beginIndex = stringLength
        end
    end
    if endIndex < 0
        endIndex = IntegerTools::max(0,s::length() + endIndex)
    else 
        if endIndex > stringLength
            endIndex = stringLength
        end
    end
    span = IntegerTools::max(0,endIndex - beginIndex)
    return Std::substr(s,beginIndex,span)
end
stripAccents(s) click to toggle source
# File lib/com/wiris/util/type/StringUtils.rb, line 11
def self.stripAccents(s)
    sb = StringBuf.new()
    i = Utf8::getIterator(s)
    while i::hasNext()
        sb::add(WCharacterBase::stripAccent(i::next()))
    end
    return sb::toString()
end