| Class | Origami::Filter::ASCIIHex |
| In: |
sources/parser/filters.rb
|
| Parent: | Object |
Decodes given data writen into upcase hexadecimal representation.
| string: | The data to decode. |
# File sources/parser/filters.rb, line 270
270: def decode(string)
271:
272: input = string.include?(?>) ? string[0..string.index(?>) - 1] : string
273:
274: digits = input.delete(" \f\t\r\n\0").split(//)
275:
276: if not digits.all? { |d| d =~ /[a-fA-F0-9>]/ }
277: raise InvalidASCIIHexString, input
278: end
279:
280: digits << "0" unless digits.size % 2 == 0
281:
282: bytes = []
283: for i in 0..digits.size/2-1 do bytes << digits[2*i].to_s + digits[2*i+1].to_s end
284:
285: bytes.pack("H2" * (digits.size / 2))
286: end