Module: Net::IMAP::StringFormatter
- Defined in:
- lib/net/imap/command_data.rb
Constant Summary collapse
- LITERAL_REGEX =
/[\x80-\xff\r\n]/n
Class Method Summary collapse
- .literal_or_literal8(input, name: "argument") ⇒ Object
-
.nstring(str) ⇒ Object
coerces non-nil using
to_s. -
.string(str) ⇒ Object
coerces using
to_s. -
.valid_nstring?(str) ⇒ Boolean
Allows nil, symbols, and strings.
-
.valid_string?(str) ⇒ Boolean
Allows symbols in addition to strings.
Class Method Details
.literal_or_literal8(input, name: "argument") ⇒ Object
441 442 443 444 445 446 447 |
# File 'lib/net/imap/command_data.rb', line 441 def literal_or_literal8(input, name: "argument") return input if input in Literal | Literal8 data = String.try_convert(input) \ or raise TypeError, "expected #{name} to be String, got #{input.class}" type = data.include?("\0") ? Literal8 : Literal type.new(data:) end |
.nstring(str) ⇒ Object
coerces non-nil using to_s
470 471 472 |
# File 'lib/net/imap/command_data.rb', line 470 def nstring(str) str.nil? ? nil : string(str) end |
.string(str) ⇒ Object
coerces using to_s
460 461 462 463 464 465 466 467 |
# File 'lib/net/imap/command_data.rb', line 460 def string(str) str = str.to_s if str =~ LITERAL_REGEX Literal.new(str) else QuotedString.new(str) end end |
.valid_nstring?(str) ⇒ Boolean
Allows nil, symbols, and strings
455 456 457 |
# File 'lib/net/imap/command_data.rb', line 455 def valid_nstring?(str) str.nil? || valid_string?(str) end |
.valid_string?(str) ⇒ Boolean
Allows symbols in addition to strings
450 451 452 |
# File 'lib/net/imap/command_data.rb', line 450 def valid_string?(str) str.is_a?(Symbol) || str.respond_to?(:to_str) end |