MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenShadingLanguage / retrieve_source

Method retrieve_source

src/liboslcomp/oslcomp.cpp:1037–1061  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1035
1036
1037std::string
1038OSLCompilerImpl::retrieve_source (ustring filename, int line)
1039{
1040 // If we don't already have the file open, open it
1041 if (filename != m_last_sourcefile) {
1042 bool ok = OIIO::Filesystem::read_text_file (filename, m_filecontents);
1043 if (ok) {
1044 m_last_sourcefile = filename;
1045 } else {
1046 m_last_sourcefile = ustring();
1047 return "<file not found>";
1048 }
1049 }
1050
1051 // Now read lines up to and including the file we want.
1052 OIIO::string_view s (m_filecontents);
1053 for ( ; line > 1; --line) {
1054 size_t p = s.find_first_of ('\n');
1055 if (p == OIIO::string_view::npos)
1056 return "<line not found>";
1057 s.remove_prefix (p+1);
1058 }
1059 s = s.substr (0, s.find_first_of ('\n'));
1060 return s;
1061}
1062
1063
1064

Callers

nothing calls this directly

Calls 1

read_text_fileFunction · 0.85

Tested by

no test coverage detected