MCPcopy Create free account
hub / github.com/Nic30/hdlConvertor / ANTLRFileStream_with_encoding

Function ANTLRFileStream_with_encoding

src/encodingConversions.cpp:45–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45antlr4::ANTLRInputStream ANTLRFileStream_with_encoding(
46 const std::filesystem::path &file_name, const std::string &encoding) {
47 std::ifstream ifs;
48 std::string str;
49 ifs.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
50 ifs.open(file_name);
51
52 // Sets position to the end of the file.
53 ifs.seekg(0, std::ios::end);
54
55 // Reserves memory for the file.
56 str.reserve(ifs.tellg());
57
58 // Sets position to the start of the file.
59 ifs.seekg(0, std::ios::beg);
60
61 // Sets contents of 'str' to all characters in the file.
62 str.assign(std::istreambuf_iterator<char>(ifs),
63 std::istreambuf_iterator<char>());
64
65 str = _to_utf8(str, encoding);
66
67 try {
68 antlr4::ANTLRInputStream input_stream(str);
69 input_stream.name = file_name.u8string();
70 return input_stream;
71 } catch (const std::range_error &e) {
72 throw std::range_error(
73 std::string("Invalid character/encoding in ")
74 + file_name.u8string() + " file");
75 }
76}
77
78}

Callers 2

run_preproc_fileMethod · 0.85
parse_fileMethod · 0.85

Calls 2

_to_utf8Function · 0.85
openMethod · 0.80

Tested by

no test coverage detected