Class: SQLite3::Encoding

Inherits:
Object
  • Object
show all
Defined in:
lib/sqlite3/encoding.rb

Class Method Summary collapse

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_asciiObject



26
27
28
# File 'lib/sqlite3/encoding.rb', line 26

def us_ascii
  ::Encoding::US_ASCII
end

.utf_16?(str_or_enc) ⇒ Boolean

Returns:

  • (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_16beObject



38
39
40
# File 'lib/sqlite3/encoding.rb', line 38

def utf_16be
  ::Encoding::UTF_16BE
end

.utf_16leObject



34
35
36
# File 'lib/sqlite3/encoding.rb', line 34

def utf_16le
  ::Encoding::UTF_16LE
end

.utf_16nativeObject



22
23
24
# File 'lib/sqlite3/encoding.rb', line 22

def utf_16native
  "Ruby".unpack("i")[0] == 2036495698 ? utf_16le : utf_16be
end

.utf_8Object



30
31
32
# File 'lib/sqlite3/encoding.rb', line 30

def utf_8
  ::Encoding::UTF_8
end