Logo Search packages:      
Sourcecode: pan version File versions

bool pan::file::get_text_file_contents ( const StringView filename,
std::string &  setme,
const char *  fallback_charset_1 = 0,
const char *  fallback_charset_2 = 0 

Given the location of a text file, read it in and massage it to the point where it should be usable -- convert CR/LF to LF, and ensure that it's UTF8-clean.

Definition at line 283 of file file-util.cc.

References pan::StringView::len, and pan::StringView::str.

Referenced by pan::DataImpl::load_server_properties().

  // read in the file...
  char * body (0);
  gsize body_len (0);
  GError * err (0);
  const std::string fname (filename.str, filename.len);
  g_file_get_contents (fname.c_str(), &body, &body_len, &err);
  if (err) {
    Log::add_err_va (_("Error reading file \"%s\": %s"), err->message, g_strerror(errno));
    g_clear_error (&err);
    return false;

  // CRLF => LF
  body_len = std::remove (body, body+body_len, '\r') - body;

  // utf8
  setme = content_to_utf8  (StringView (body, body_len),

  return true;

Generated by  Doxygen 1.6.0   Back to index