Module: C0

Defined in:
lib/c0.rb

Defined Under Namespace

Modules: TokenType Classes: Builder, Document, Group, Record, StreamReader, Table

Constant Summary collapse

SOH =

Assigned C0 control codes.

0x01
STX =
0x02
ETX =
0x03
EOT =
0x04
ENQ =
0x05
DLE =
0x10
ETB =
0x17
SUB =
0x1a
FS =
0x1c
GS =
0x1d
RS =
0x1e
US =
0x1f

Class Method Summary collapse

Class Method Details

.assigned?(byte) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/c0.rb', line 56

def assigned?(byte)
  Ext.is_assigned(byte)
end

.build {|b| ... } ⇒ Object

Build a buffer by driving a fresh builder, returning its bytes.

Yields:

  • (b)


383
384
385
386
387
# File 'lib/c0.rb', line 383

def self.build
  b = Builder.new
  yield b
  b.bytes
end

.canonical?(buf) ⇒ Boolean

Whether bytes are a canonical document unit for content addressing.

Returns:

  • (Boolean)


61
62
63
# File 'lib/c0.rb', line 61

def canonical?(buf)
  Ext.canonical(to_bin(buf))
end

.pretty_format(buf, indent = nil) ⇒ Object

Format compact bytes as a human-readable Unicode string.



76
77
78
# File 'lib/c0.rb', line 76

def pretty_format(buf, indent = nil)
  indent ? Ext.pretty_format(to_bin(buf), indent) : Ext.pretty_format(to_bin(buf))
end

.pretty_parse(text) ⇒ Object

Parse pretty text back to compact bytes.



81
82
83
# File 'lib/c0.rb', line 81

def pretty_parse(text)
  Ext.pretty_parse(text)
end

.to_bin(str) ⇒ Object

Coerce to a binary (ASCII-8BIT) string without copying when already binary.



52
53
54
# File 'lib/c0.rb', line 52

def to_bin(str)
  str.encoding == Encoding::BINARY ? str : str.b
end

.tokenize(buf) ⇒ Object

Array of [type, start, end]. Raises ArgumentError on malformed input.



71
72
73
# File 'lib/c0.rb', line 71

def tokenize(buf)
  Ext.tokenize(to_bin(buf))
end

.unescape(buf) ⇒ Object

Decode DLE escapes, returning the logical bytes.



66
67
68
# File 'lib/c0.rb', line 66

def unescape(buf)
  Ext.unescape(to_bin(buf))
end