Class: LX::String
- Inherits:
-
Object
- Object
- LX::String
- Defined in:
- lib/lx.rb
Overview
Utilities for strings.
Defined Under Namespace
Modules: Dangerous
Instance Method Summary collapse
-
#collapse ⇒ Object
Returns a new string in which leading and trailing whitespace have been removed, and multiple internal whitespaces are collapsed into into single spaces.
-
#collapse! ⇒ Object
Performs a collapse on the string itself.
-
#has_content? ⇒ Boolean
Same as hascontent?.
-
#hascontent? ⇒ Boolean
Returns true if the string contains a non-whitespace character.
-
#initialize(p_str) ⇒ String
constructor
Initializes a LX::String object, The single param is the string with which the object will be associated.
-
#inner_collapse ⇒ Object
————————————————————————— inner_collapse.
-
#no_content? ⇒ Boolean
Same as no_content?.
-
#nocontent? ⇒ Boolean
Return true if the string does not have any non-whitespace characters.
-
#tmp_untaint(rx) {|tmp| ... } ⇒ Object
————————————————————————— tmp_untaint.
Constructor Details
#initialize(p_str) ⇒ String
Initializes a LX::String object, The single param is the string with which the object will be associated.
312 313 314 |
# File 'lib/lx.rb', line 312 def initialize(p_str) @str = p_str end |
Instance Method Details
#collapse ⇒ Object
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"
329 330 331 332 333 |
# File 'lib/lx.rb', line 329 def collapse() rv = @str.dup rv.lx.collapse! return rv end |
#collapse! ⇒ Object
Performs a collapse on the string itself.
336 337 338 339 340 |
# 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? ⇒ Boolean
Same as hascontent?
369 370 371 |
# File 'lib/lx.rb', line 369 def has_content? return hascontent? end |
#hascontent? ⇒ Boolean
Returns true if the string contains a non-whitespace character.
364 365 366 |
# File 'lib/lx.rb', line 364 def hascontent? return @str.match(/\S/mu) ? true : false end |
#inner_collapse ⇒ Object
inner_collapse
349 350 351 352 353 |
# File 'lib/lx.rb', line 349 def inner_collapse rv = @str.clone rv.gsub!(/[\u00A0\s]+/imu, ' ') return rv end |
#no_content? ⇒ Boolean
Same as no_content?
379 380 381 |
# File 'lib/lx.rb', line 379 def no_content? return nocontent? end |
#nocontent? ⇒ Boolean
Return true if the string does not have any non-whitespace characters.
374 375 376 |
# File 'lib/lx.rb', line 374 def nocontent? return !hascontent? end |
#tmp_untaint(rx) {|tmp| ... } ⇒ Object
tmp_untaint
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# 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 |