Module: ID3Tag::StringUtil

Defined in:
lib/id3tag/string_util.rb

Constant Summary collapse

NULL_BYTE =
"\x00"
UTF_8_DIRECTIVE =
"U*"

Class Method Summary collapse

Class Method Details

.blank?(string) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/id3tag/string_util.rb', line 6

def self.blank?(string)
  string !~ /[^[:space:]]/
end

.cut_at_null_byte(string) ⇒ Object



22
23
24
# File 'lib/id3tag/string_util.rb', line 22

def self.cut_at_null_byte(string)
  string.split(NULL_BYTE, 2).first
end

.do_unsynchronization(input) ⇒ Object



10
11
12
13
14
# File 'lib/id3tag/string_util.rb', line 10

def self.do_unsynchronization(input)
  unsynch = Unsynchronization.new(input)
  unsynch.apply
  unsynch.output
end

.split_by_null_byte(string) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/id3tag/string_util.rb', line 26

def self.split_by_null_byte(string)
  null_byte_found = false
  has_skipped = false
  before, after = [], []
  string.each_byte do |byte|
    if byte == 0
      null_byte_found = true
      (has_skipped = true) and next unless has_skipped
    end
    if null_byte_found
      after << byte
    else
      before << byte
    end
  end
  [before.pack(UTF_8_DIRECTIVE), after.pack(UTF_8_DIRECTIVE)]
end

.undo_unsynchronization(input) ⇒ Object



16
17
18
19
20
# File 'lib/id3tag/string_util.rb', line 16

def self.undo_unsynchronization(input)
  unsynch = Unsynchronization.new(input)
  unsynch.remove
  unsynch.output
end