Class: SQLite3::Encoding
- Inherits:
-
Object
- Object
- SQLite3::Encoding
- Defined in:
- lib/sqlite3/encoding.rb
Class Method Summary collapse
- .find(encoding) ⇒ Object
- .us_ascii ⇒ Object
- .utf_16?(str_or_enc) ⇒ Boolean
- .utf_16be ⇒ Object
- .utf_16le ⇒ Object
- .utf_16native ⇒ Object
- .utf_8 ⇒ Object
Class Method Details
.find(encoding) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/sqlite3/encoding.rb', line 4 def find(encoding) enc = encoding.to_s if enc.downcase == "utf-16" utf_16native else ::Encoding.find(enc).tap do |e| if utf_16?(e) && e != utf_16native raise ArgumentError, "requested to use byte order different than native" end end end end |
.us_ascii ⇒ Object
26 27 28 |
# File 'lib/sqlite3/encoding.rb', line 26 def us_ascii ::Encoding::US_ASCII end |
.utf_16?(str_or_enc) ⇒ Boolean
17 18 19 20 |
# File 'lib/sqlite3/encoding.rb', line 17 def utf_16?(str_or_enc) enc = str_or_enc.kind_of?(::Encoding) ? str_or_enc : str_or_enc.encoding [utf_16le, utf_16be].include?(enc) end |
.utf_16be ⇒ Object
38 39 40 |
# File 'lib/sqlite3/encoding.rb', line 38 def utf_16be ::Encoding::UTF_16BE end |
.utf_16le ⇒ Object
34 35 36 |
# File 'lib/sqlite3/encoding.rb', line 34 def utf_16le ::Encoding::UTF_16LE end |
.utf_16native ⇒ Object
22 23 24 |
# File 'lib/sqlite3/encoding.rb', line 22 def utf_16native "Ruby".unpack("i")[0] == 2036495698 ? utf_16le : utf_16be end |
.utf_8 ⇒ Object
30 31 32 |
# File 'lib/sqlite3/encoding.rb', line 30 def utf_8 ::Encoding::UTF_8 end |