static void fgets(STRING & s, FILE * f) { s.resize(0); char c; while (fgetc(c, f)) { if (c == '\n' || c == '\r') { if (c == '\r' && (!fgetc(c, f) || c != '\n')) RuntimeError("fgets: malformed text file, CR without LF"); break; } s.push_back(c); // strip Unicode BOM // We strip it from any string, not just at the start. // This allows to UNIX-'cat' multiple UTF-8 files with BOMs. // Since the BOM is otherwise invalid within a file, this is well-defined and upwards compatible. if (s.size() == 3 && BeginsWithUnicodeBOM(s.c_str())) s.clear(); } }