MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / Path_ReadTextFile

Function Path_ReadTextFile

src/vrcore/pathtools_public.cpp:761–793  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

759}
760
761std::string Path_ReadTextFile( const std::string &strFilename )
762{
763 // doing it this way seems backwards, but I don't
764 // see an easy way to do this with C/C++ style IO
765 // that isn't worse...
766 int size;
767 unsigned char* buf = Path_ReadBinaryFile( strFilename, &size );
768 if (!buf)
769 return "";
770
771 int i = 1; /* start working at byte 1 (in-place) */
772 size_t outsize = 1;
773
774 // remove UTF8 BOM
775 if ( size >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF )
776 {
777 i = 3;
778 outsize = 0;
779 }
780
781 // convert CRLF -> LF
782 for ( ; i < size; i++ )
783 {
784 if (buf[i] == '\n' && buf[i-1] == '\r') // CRLF
785 buf[outsize-1] = '\n'; // ->LF
786 else
787 buf[outsize++] = buf[i]; // just copy
788 }
789
790 std::string ret((char *)buf, outsize);
791 delete[] buf;
792 return ret;
793}
794
795
796bool Path_MakeWritable( const std::string &strFilename )

Callers 2

ToJsonStringMethod · 0.70
BLoadFromFileMethod · 0.70

Calls 1

Path_ReadBinaryFileFunction · 0.70

Tested by

no test coverage detected