multibyte.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # encoding: utf-8
  2. module Mail #:nodoc:
  3. module Multibyte
  4. require 'mail/multibyte/exceptions'
  5. require 'mail/multibyte/chars'
  6. require 'mail/multibyte/unicode'
  7. # The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy
  8. # class so you can support other encodings. See the Mail::Multibyte::Chars implementation for
  9. # an example how to do this.
  10. #
  11. # Example:
  12. # Mail::Multibyte.proxy_class = CharsForUTF32
  13. def self.proxy_class=(klass)
  14. @proxy_class = klass
  15. end
  16. # Returns the current proxy class
  17. def self.proxy_class
  18. @proxy_class ||= Mail::Multibyte::Chars
  19. end
  20. # Regular expressions that describe valid byte sequences for a character
  21. VALID_CHARACTER = {
  22. # Borrowed from the Kconv library by Shinji KONO - (also as seen on the W3C site)
  23. 'UTF-8' => /\A(?:
  24. [\x00-\x7f] |
  25. [\xc2-\xdf] [\x80-\xbf] |
  26. \xe0 [\xa0-\xbf] [\x80-\xbf] |
  27. [\xe1-\xef] [\x80-\xbf] [\x80-\xbf] |
  28. \xf0 [\x90-\xbf] [\x80-\xbf] [\x80-\xbf] |
  29. [\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf] |
  30. \xf4 [\x80-\x8f] [\x80-\xbf] [\x80-\xbf])\z /xn,
  31. # Quick check for valid Shift-JIS characters, disregards the odd-even pairing
  32. 'Shift_JIS' => /\A(?:
  33. [\x00-\x7e\xa1-\xdf] |
  34. [\x81-\x9f\xe0-\xef] [\x40-\x7e\x80-\x9e\x9f-\xfc])\z /xn
  35. }
  36. end
  37. end
  38. require 'mail/multibyte/utils'