2 binary-source-file.cc -- implement Binary_source_file
4 source file of the LilyPond music typesetter
6 (c) 1997--2006 Jan Nieuwenhuizen
9 #include <climits> // INT_MAX
12 #include "binary-source-file.hh"
13 #include "string-convert.hh"
15 Binary_source_file::Binary_source_file (std::string &file_name_string)
16 : Source_file (file_name_string)
20 Binary_source_file::~Binary_source_file ()
25 Binary_source_file::quote_input (char const *pos_str0) const
28 if (!contains (pos_str0))
31 char const *begin_str0 = max (pos_str0 - 8, c_str ());
32 char const *end_str0 = min (pos_str0 + 7, c_str () + length ());
34 std::string pre_string (begin_str0, pos_str0 - begin_str0);
35 pre_string = String_convert::bin2hex (pre_string);
36 for (ssize i = 2; i < pre_string.length (); i += 3)
37 pre_string = pre_string.substr (0, i)
38 + " " + pre_string.substr (i, NPOS);
39 std::string post_string (pos_str0, end_str0 - pos_str0);
40 post_string = String_convert::bin2hex (post_string);
41 for (ssize i = 2; i < post_string.length (); i += 3)
42 post_string = post_string.substr (0, i)
43 + " " + post_string.substr (i, NPOS);
45 std::string str = pre_string
47 + to_string (' ', pre_string.length () + 1)
53 Binary_source_file::get_line (char const *pos_str0) const
55 if (!contains (pos_str0))
58 return pos_str0 - c_str ();
62 Binary_source_file::get_U8 ()
64 return *(U8 *)forward_str0 (1);
68 Binary_source_file::get_U16 ()
79 naming is wrong. This is a UNIX-endian-32 (as opposed to xinu or ixun)
83 Binary_source_file::get_U32 ()