Module: UnicodeTools
- Defined in:
- lib/unicode-tools/bidi.rb,
lib/unicode-tools/whitespace.rb,
lib/unicode-tools/string_ext/base.rb,
lib/unicode-tools/string_ext/trim.rb,
lib/unicode-tools/string_ext/squish.rb
Defined Under Namespace
Modules: StringExt
Constant Summary collapse
- BIDI_OVERRIDE_CHARS_REGEX =
/\u00E2\u0080[\u008E\u008F\u00AA-\u00AE]/.freeze
- WHITESPACE_CHARS =
%w( \u0009-\u000D \u0085 \u2028 \u2029 \u0020 \u3000 \u1680 \u2000-\u200A \u205F \u00A0 \u202F \u180E ).freeze
- WHITESPACE_REGEX =
/[#{WHITESPACE_CHARS.join('')}]+/.freeze
- LEADING_WHITESPACE_REGEX =
/\A#{WHITESPACE_REGEX.source}+/.freeze
- TRAILING_WHITESPACE_REGEX =
/#{WHITESPACE_REGEX.source}+\z/.freeze
- SURROUNDING_WHITESPACE_REGEX =
/(\A#{WHITESPACE_REGEX.source})|(#{WHITESPACE_REGEX.source}\z)/.freeze
Class Method Summary collapse
- .has_bidi_override?(string) ⇒ Boolean
- .has_whitespace?(string) ⇒ Boolean
- .replace_whitespace(string, replacement = nil, &block) ⇒ Object
- .replace_whitespace!(string, replacement = nil, &block) ⇒ Object
- .squish(string) ⇒ Object
- .squish!(string) ⇒ Object
- .strip_bidi_override_chars(string) ⇒ Object
- .strip_bidi_override_chars!(string) ⇒ Object
- .trim(string) ⇒ Object
- .trim!(string) ⇒ Object
Class Method Details
.has_bidi_override?(string) ⇒ Boolean
8 9 10 |
# File 'lib/unicode-tools/bidi.rb', line 8 def has_bidi_override?(string) !!(string =~ BIDI_OVERRIDE_CHARS_REGEX) end |
.has_whitespace?(string) ⇒ Boolean
16 17 18 |
# File 'lib/unicode-tools/whitespace.rb', line 16 def has_whitespace?(string) string.has_whitespace? end |
.replace_whitespace(string, replacement = nil, &block) ⇒ Object
36 37 38 |
# File 'lib/unicode-tools/whitespace.rb', line 36 def replace_whitespace(string, replacement = nil, &block) string.replace_whitespace(replacement, &block) end |
.replace_whitespace!(string, replacement = nil, &block) ⇒ Object
40 41 42 |
# File 'lib/unicode-tools/whitespace.rb', line 40 def replace_whitespace!(string, replacement = nil, &block) string.replace_whitespace!(replacement, &block) end |
.squish(string) ⇒ Object
28 29 30 |
# File 'lib/unicode-tools/whitespace.rb', line 28 def squish(string) string.squish end |
.squish!(string) ⇒ Object
32 33 34 |
# File 'lib/unicode-tools/whitespace.rb', line 32 def squish!(string) string.squish! end |
.strip_bidi_override_chars(string) ⇒ Object
12 13 14 |
# File 'lib/unicode-tools/bidi.rb', line 12 def strip_bidi_override_chars(string) string.gsub(BIDI_OVERRIDE_CHARS_REGEX, '') end |
.strip_bidi_override_chars!(string) ⇒ Object
16 17 18 |
# File 'lib/unicode-tools/bidi.rb', line 16 def strip_bidi_override_chars!(string) string.gsub!(BIDI_OVERRIDE_CHARS_REGEX, '') end |
.trim(string) ⇒ Object
20 21 22 |
# File 'lib/unicode-tools/whitespace.rb', line 20 def trim(string) string.trim end |
.trim!(string) ⇒ Object
24 25 26 |
# File 'lib/unicode-tools/whitespace.rb', line 24 def trim!(string) string.trim! end |