Skip to content

Commit

Permalink
Syntax highlighting of C++ usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed May 12, 2020
1 parent 7056543 commit ca7f4b5
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions _build/usage_cpp_stl.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,60 @@
</ul>
<div class="tab-content" style="margin-top: 6px">
<div role="tabpanel" class="tab-pane active" id="example-local-file">
<pre><code class="cpp">#include &lt;fstream&gt;
<%= code cur_lang, <<-CODE
#include <fstream>
std::ifstream is("path/to/local/file.<%= meta['file-extension'] || meta['id'] %>", std::ifstream::binary);</code></pre>
std::ifstream is("path/to/local/file.#{meta['file-extension'] || meta['id']}", std::ifstream::binary);
CODE
%>
</div>
<div role="tabpanel" class="tab-pane" id="example-std-string">
<pre><code class="cpp">#include &lt;sstream&gt;
<%= code cur_lang, <<-CODE
#include <sstream>
std::istringstream is(str);</code></pre>
std::istringstream is(str);
CODE
%>
</div>
<div role="tabpanel" class="tab-pane" id="example-char-ptr">
<pre><code class="cpp">#include &lt;sstream&gt;
<%= code cur_lang, <<-CODE
#include <sstream>
const char buf[] = { ... };
std::string str(buf, sizeof buf);
std::istringstream is(str);</code></pre>
std::istringstream is(str);
CODE
%>
</div>
</div>

</li>

<li>We need to wrap our input stream into Kaitai stream:

<pre><code class="cpp">#include &lt;kaitai/kaitaistream.h&gt;
<%= code cur_lang, <<-CODE
#include <kaitai/kaitaistream.h>
kaitai::kstream ks(&amp;is);</code></pre></li>
kaitai::kstream ks(&is);
CODE
%>
</li>

<li>And finally, we can invoke the parsing:

<pre><code class="cpp"><%= class_name %> data(&amp;ks);</code></pre></li>
<%= code cur_lang, <<-CODE
#{class_name} data(&ks);
CODE
%>
</li>
</ol>

<p>After that, one can get various attributes from the structure by invoking getter methods like:</p>

<pre><code class="cpp"><% usage_attrs.each { |attr| %>data.<%= attr[:name] %>() // => <%= attr[:doc] %><% } %></code></pre>
<% src_usage_attrs = ""
usage_attrs.each { |attr|
src_usage_attrs += <<-CODE
data.#{ attr[:name] }() // => #{ attr[:doc] }
CODE
}
%>
<%= code cur_lang, src_usage_attrs %>

0 comments on commit ca7f4b5

Please sign in to comment.