Class: Cabriolet::HLP::QuickHelp::TopicBuilder
- Inherits:
-
Object
- Object
- Cabriolet::HLP::QuickHelp::TopicBuilder
- Defined in:
- lib/cabriolet/hlp/quickhelp/topic_builder.rb
Overview
Builds topic data in QuickHelp internal format
Class Method Summary collapse
-
.build_topic_data(text) ⇒ String
Build topic data in QuickHelp internal format.
Class Method Details
.build_topic_data(text) ⇒ String
Build topic data in QuickHelp internal format
Topic format as expected by decompressor:
-
Each line: [text_length][newline][attrs]
-
text_length = text + newline + 1 (for attr_len byte) = text_bytes + 2
-
Line structure: text_length byte + text + newline + attr_len byte + attr_data
The decompressor reads:
-
text_length = data.getbyte(pos)
-
text_bytes = text_length - 2 (reads text, skips newline)
-
attr_length = data.getbyte(pos after text + newline)
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 |
# File 'lib/cabriolet/hlp/quickhelp/topic_builder.rb', line 22 def self.build_topic_data(text) result = +"" # Split text into lines lines = text.split("\n") lines.each do |line| text_bytes = line.b newline = "\x0D" # Carriage return # Attribute section: just 0xFF terminator (attr_len = 1) attr_data = "\xFF" attr_len = 1 # text_length = text + newline + 1 (for attr_len byte) # This ensures text_bytes = text_length - 2 gives correct text length text_length = text_bytes.bytesize + 2 result << text_length.chr result << text_bytes result << newline result << attr_len.chr result << attr_data end result end |