Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_extensions/string.rb

Overview

Taken from the mail gem.

Constant Summary collapse

CRLF =

:nodoc:

"\r\n"
LF =
"\n"
CRLF_REGEX =

This 1.9 only regex can save a reasonable amount of time (~20%) by not matching “rn” so the string is returned unchanged in the common case.

/\n|\r\n|\r/

Instance Method Summary collapse

Instance Method Details

#to_crlfObject



15
16
17
# File 'lib/core_extensions/string.rb', line 15

def to_crlf
  to_str.gsub(CRLF_REGEX, CRLF)
end

#to_lfObject



19
20
21
# File 'lib/core_extensions/string.rb', line 19

def to_lf
  to_str.gsub(/\r\n|\r/, LF)
end

#to_quoted_printableObject



23
24
25
# File 'lib/core_extensions/string.rb', line 23

def to_quoted_printable
  [to_lf].pack("M").to_crlf
end