Top Level Namespace
Defined Under Namespace
Classes: Calldata
Instance Method Summary collapse
-
#banner ⇒ Object
say hello.
-
#cocos ⇒ Object
e.g.
-
#datauris ⇒ Object
e.g.
-
#hex_to_utf8(hex) ⇒ Object
use hex_to_bin - why? why not?.
-
#utf8_to_hex(utf8) ⇒ Object
hexdata encode/decode (hex string NOT binary, utf8-encoded string) utf8-to-hex, hex-to-utf8.
Instance Method Details
#cocos ⇒ Object
e.g. read/write_blob/json etc.
4 |
# File 'lib/calldata.rb', line 4 require 'cocos' |
#datauris ⇒ Object
e.g. first pull-in zero-dependeny gem incl. DataUri.parse/build helpers incl. base64
2 |
# File 'lib/calldata.rb', line 2 require 'datauris' |
#hex_to_utf8(hex) ⇒ Object
use hex_to_bin - why? why not?
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/calldata.rb', line 22 def hex_to_utf8( hex ) ## use hex_to_bin - why? why not? ### cut-off optionial 0x/0X hex = hex[2..-1] if hex.start_with?( '0x' ) || hex.start_with?( '0X' ) ## check if force_encoding( 'UTF-8' ) redundant here? return hex.force_encoding( 'UTF-8' ) if hex.empty? ## empty string - return as is ## add hexchars check here - why? why not? ## do NOT allow space, or anything except a-z, A-Z, 0-9 raise ArgumentError, "hexstring expected; got #{hex}" unless /\A[0-9a-fA-F]+\z/.match?( hex ) ## note: ethscriptions specifies that \u0000 ## (that is, \x00 - 0 byte) gets deleted/removed (even if valid utf-8) ## reason given: 0 byte in utf-8 messes up postgresql storage! ## fix-fix-fix - todo: add support for cleanup / fix corrup utf8 encoding - why? why not? ## unless utf8_string.valid_encoding? ## utf8_string = utf8_string.encode('UTF-8', ## invalid: :replace, ## undef: :replace, ## replace: "\uFFFD") ## end ## check what's the replace char -> "\uFFFD" # note: about string#delete # Returns a copy of str with all characters of its arguments deleted. # Uses the same rules for building the set of characters as String#count. ## ## note: single hexchars get expanded e.g. # ['a'].pack('H*') => "\xA0" [hex].pack('H*').force_encoding( 'UTF-8' ).delete( "\u0000" ) end |
#utf8_to_hex(utf8) ⇒ Object
hexdata encode/decode (hex string NOT binary, utf8-encoded string)
utf8-to-hex, hex-to-utf8
17 18 19 |
# File 'lib/calldata.rb', line 17 def utf8_to_hex( utf8 ) ## use bin_to_hex - why? why not? utf8.unpack('H*').first end |