class LX::String

Utilities for strings.

Public Class Methods

new(p_str) click to toggle source

Initializes a LX::String object, The single param is the string with which the object will be associated.

# File lib/lx.rb, line 312
def initialize(p_str)
        @str = p_str
end

Public Instance Methods

collapse() click to toggle source

Returns a new string in which leading and trailing whitespace have been removed, and multiple internal whitespaces are collapsed into into single spaces.

str = ' Whatever  Dude  '
str.lx.collapse # => "Whatever Dude"
# File lib/lx.rb, line 329
def collapse()
        rv = @str.dup
        rv.lx.collapse!
        return rv
end
collapse!() click to toggle source

Performs a collapse on the string itself.

# File lib/lx.rb, line 336
def collapse!()
        @str.sub!(/\A[^[:graph:]]+/mu, '')
        @str.sub!(/[^[:graph:]]+\z/mu, '')
        @str.gsub!(/[^[:graph:]]+/mu, ' ')
end
has_content?() click to toggle source

Same as hascontent?

# File lib/lx.rb, line 369
def has_content?
        return hascontent?
end
hascontent?() click to toggle source

Returns true if the string contains a non-whitespace character.

# File lib/lx.rb, line 364
def hascontent?
        return @str.match(/\S/mu) ? true : false
end
inner_collapse() click to toggle source
# File lib/lx.rb, line 349
def inner_collapse
        rv = @str.clone
        rv.gsub!(/[\u00A0\s]+/imu, ' ')
        return rv
end
no_content?() click to toggle source

Same as no_content?

# File lib/lx.rb, line 379
def no_content?
        return nocontent?
end
nocontent?() click to toggle source

Return true if the string does not have any non-whitespace characters.

# File lib/lx.rb, line 374
def nocontent?
        return !hascontent?
end
tmp_untaint(rx) { |tmp| ... } click to toggle source
# File lib/lx.rb, line 391
def tmp_untaint(rx)
        # dangerous
        if rx == LX::String::Dangerous
                tmp = @str.dup.untaint
        else
                if @str.match(rx)
                        tmp = @str.dup.untaint
                else
                        raise 'string-does-not-match-untaint-pattern: ' + rx.to_s
                end
        end
        
        # yield
        yield tmp
end