| 759 | } |
| 760 | |
| 761 | std::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 | |
| 796 | bool Path_MakeWritable( const std::string &strFilename ) |
no test coverage detected