QString OrganiseFormat::GetFilenameForSong(const Song &song) const { QString filename = ParseBlock(format_, song); if (replace_spaces_) filename.replace(QRegExp("\\s"), "_"); if (replace_non_ascii_) { QString stripped; for (int i=0 ; i<filename.length() ; ++i) { const QCharRef c = filename[i]; if (c < 128) stripped.append(c); else { const QString decomposition = c.decomposition(); if (!decomposition.isEmpty() && decomposition[0] < 128) stripped.append(decomposition[0]); else stripped.append("_"); } } filename = stripped; } return filename; }
QString OrganiseFormat::GetFilenameForSong(const Song& song) const { QString filename = ParseBlock(format_, song); if (QFileInfo(filename).completeBaseName().isEmpty()) { // Avoid having empty filenames, or filenames with extension only: in this // case, keep the original filename. // We remove the extension from "filename" if it exists, as // song.basefilename() // also contains the extension. filename = Utilities::PathWithoutFilenameExtension(filename) + song.basefilename(); } if (replace_spaces_) filename.replace(QRegExp("\\s"), "_"); if (replace_non_ascii_) { QString stripped; for (int i = 0; i < filename.length(); ++i) { const QCharRef c = filename[i]; if (c < 128) { stripped.append(c); } else { const QString decomposition = c.decomposition(); if (!decomposition.isEmpty() && decomposition[0] < 128) stripped.append(decomposition[0]); else stripped.append("_"); } } filename = stripped; } // Fix any parts of the path that start with dots. QStringList parts = filename.split("/"); for (int i = 0; i < parts.count(); ++i) { QString* part = &parts[i]; for (int j = 0; j < kInvalidPrefixCharactersCount; ++j) { if (part->startsWith(kInvalidPrefixCharacters[j])) { part->replace(0, 1, '_'); break; } } } return parts.join("/"); }