| @@ -27,13 +27,26 @@ std::string ellipsize(const std::string &s, size_t len); | |||||
| std::string ellipsizePrefix(const std::string &s, size_t len); | std::string ellipsizePrefix(const std::string &s, size_t len); | ||||
| bool startsWith(const std::string &str, const std::string &prefix); | bool startsWith(const std::string &str, const std::string &prefix); | ||||
| bool endsWith(const std::string &str, const std::string &suffix); | bool endsWith(const std::string &str, const std::string &suffix); | ||||
| /** Extracts portions of a path */ | |||||
| /** Extracts the directory of the path. | |||||
| Example: directory("dir/file.txt") // "dir" | |||||
| Calls POSIX dirname(). | |||||
| */ | |||||
| std::string directory(const std::string &path); | std::string directory(const std::string &path); | ||||
| /** Extracts the filename of the path. | |||||
| Example: directory("dir/file.txt") // "file.txt" | |||||
| Calls POSIX basename(). | |||||
| */ | |||||
| std::string filename(const std::string &path); | std::string filename(const std::string &path); | ||||
| /** Extracts the portion of a path without the extension */ | |||||
| std::string basename(const std::string &path); | |||||
| /** Extracts the extension of a path */ | |||||
| std::string extension(const std::string &path); | |||||
| /** Extracts the portion of a filename without the extension. | |||||
| Example: filenameBase("file.txt") // "file" | |||||
| Note: Only works on filenames. Call filename(path) to get the filename of the path. | |||||
| */ | |||||
| std::string filenameBase(const std::string &filename); | |||||
| /** Extracts the extension of a filename. | |||||
| Example: filenameExtension("file.txt") // "txt" | |||||
| Note: Only works on filenames. Call filename(path) to get the filename of the path. | |||||
| */ | |||||
| std::string filenameExtension(const std::string &filename); | |||||
| /** Scores how well a query matches a string. | /** Scores how well a query matches a string. | ||||
| A score of 0 means no match. | A score of 0 means no match. | ||||
| The score is arbitrary and is only meaningful for sorting. | The score is arbitrary and is only meaningful for sorting. | ||||
| @@ -204,7 +204,7 @@ struct ModulePresetItem : ui::MenuItem { | |||||
| for (const std::string &presetPath : moduleWidget->model->presetPaths) { | for (const std::string &presetPath : moduleWidget->model->presetPaths) { | ||||
| ModulePresetPathItem *presetItem = new ModulePresetPathItem; | ModulePresetPathItem *presetItem = new ModulePresetPathItem; | ||||
| std::string presetName = string::basename(string::filename(presetPath)); | |||||
| std::string presetName = string::filenameBase(string::filename(presetPath)); | |||||
| presetItem->text = presetName; | presetItem->text = presetName; | ||||
| presetItem->presetPath = presetPath; | presetItem->presetPath = presetPath; | ||||
| presetItem->moduleWidget = moduleWidget; | presetItem->moduleWidget = moduleWidget; | ||||
| @@ -662,7 +662,7 @@ void ModuleWidget::saveDialog() { | |||||
| }); | }); | ||||
| std::string pathStr = path; | std::string pathStr = path; | ||||
| std::string extension = string::extension(pathStr); | |||||
| std::string extension = string::filenameExtension(string::filename(pathStr)); | |||||
| if (extension.empty()) { | if (extension.empty()) { | ||||
| pathStr += ".vcvm"; | pathStr += ".vcvm"; | ||||
| } | } | ||||
| @@ -135,7 +135,7 @@ void Scene::onHoverKey(const widget::HoverKeyEvent &e) { | |||||
| void Scene::onPathDrop(const widget::PathDropEvent &e) { | void Scene::onPathDrop(const widget::PathDropEvent &e) { | ||||
| if (e.paths.size() >= 1) { | if (e.paths.size() >= 1) { | ||||
| const std::string &path = e.paths[0]; | const std::string &path = e.paths[0]; | ||||
| if (string::extension(path) == "vcv") { | |||||
| if (string::filenameExtension(string::filename(path)) == "vcv") { | |||||
| APP->patch->load(path); | APP->patch->load(path); | ||||
| e.consume(this); | e.consume(this); | ||||
| } | } | ||||
| @@ -130,7 +130,7 @@ void PatchManager::saveAsDialog() { | |||||
| }); | }); | ||||
| std::string pathStr = pathC; | std::string pathStr = pathC; | ||||
| if (string::extension(pathStr).empty()) { | |||||
| if (string::filenameExtension(pathStr).empty()) { | |||||
| pathStr += ".vcv"; | pathStr += ".vcv"; | ||||
| } | } | ||||
| @@ -324,7 +324,7 @@ static void extractPackages(const std::string &path) { | |||||
| std::string message; | std::string message; | ||||
| for (std::string packagePath : system::listEntries(path)) { | for (std::string packagePath : system::listEntries(path)) { | ||||
| if (string::extension(packagePath) != "zip") | |||||
| if (string::filenameExtension(packagePath) != "zip") | |||||
| continue; | continue; | ||||
| INFO("Extracting package %s", packagePath.c_str()); | INFO("Extracting package %s", packagePath.c_str()); | ||||
| // Extract package | // Extract package | ||||
| @@ -96,20 +96,18 @@ std::string filename(const std::string &path) { | |||||
| return filename; | return filename; | ||||
| } | } | ||||
| // libgen.h defines a `basename` macro | |||||
| #undef basename | |||||
| std::string basename(const std::string &path) { | |||||
| size_t pos = path.rfind('.'); | |||||
| std::string filenameBase(const std::string &filename) { | |||||
| size_t pos = filename.rfind('.'); | |||||
| if (pos == std::string::npos) | if (pos == std::string::npos) | ||||
| return path; | |||||
| return std::string(path, 0, pos); | |||||
| return filename; | |||||
| return std::string(filename, 0, pos); | |||||
| } | } | ||||
| std::string extension(const std::string &path) { | |||||
| size_t pos = path.rfind('.'); | |||||
| std::string filenameExtension(const std::string &filename) { | |||||
| size_t pos = filename.rfind('.'); | |||||
| if (pos == std::string::npos) | if (pos == std::string::npos) | ||||
| return ""; | return ""; | ||||
| return std::string(path, pos + 1); | |||||
| return std::string(filename, pos + 1); | |||||
| } | } | ||||