Logo Search packages:      
Sourcecode: pan version File versions  Download package

std::string pan::file::sanitize ( const StringView fname  ) 

Attempt to make a filename safe for use.

  1. Replacing illegal characters with '_'.
  2. Ensure the resulting string is UTF8-safe

Attempt to make a filename safe for use. This is done by replacing illegal characters with '_'. This function assumes the input is UTF8 since gmime uses UTF8 interface. return value must be g_free'd.

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

References pan::StringView::empty().

Referenced by get_unique_fname().

  std::string ret;

  // sanity checks
  pan_return_val_if_fail (!fname.empty(), ret);

  ret = content_to_utf8(fname);

  // strip illegal characters
# ifdef G_OS_WIN32
  static const char* illegal_chars = "/\\:?*\"\'<>|";
# else
  static const char* illegal_chars = "/\\";
# endif
  for (const char *pch(illegal_chars); *pch; ++pch)
    std::replace (ret.begin(), ret.end(), *pch, '_');

  return ret;

Generated by  Doxygen 1.6.0   Back to index