@@ -126,17 +126,18 @@ inline float DEPRECATED randomf() {return randomUniform();} | |||||
/** Converts a printf format string and optional arguments into a std::string */ | /** Converts a printf format string and optional arguments into a std::string */ | ||||
std::string stringf(const char *format, ...); | std::string stringf(const char *format, ...); | ||||
std::string lowercase(std::string s); | |||||
std::string uppercase(std::string s); | |||||
std::string stringLowercase(std::string s); | |||||
std::string stringUppercase(std::string s); | |||||
/** Truncates and adds "..." to a string, not exceeding `len` characters */ | /** Truncates and adds "..." to a string, not exceeding `len` characters */ | ||||
std::string ellipsize(std::string s, size_t len); | |||||
bool startsWith(std::string str, std::string prefix); | |||||
bool endsWith(std::string str, std::string suffix); | |||||
std::string extractDirectory(std::string path); | |||||
std::string extractFilename(std::string path); | |||||
std::string extractExtension(std::string path); | |||||
std::string stringEllipsize(std::string s, size_t len); | |||||
bool stringStartsWith(std::string str, std::string prefix); | |||||
bool stringEndsWith(std::string str, std::string suffix); | |||||
/** Extracts portions of a path */ | |||||
std::string stringDirectory(std::string path); | |||||
std::string stringFilename(std::string path); | |||||
std::string stringExtension(std::string path); | |||||
//////////////////// | //////////////////// | ||||
// Operating-system specific utilities | // Operating-system specific utilities | ||||
@@ -18,8 +18,8 @@ static ModelTag sTagFilter = NO_TAG; | |||||
bool isMatch(std::string s, std::string search) { | bool isMatch(std::string s, std::string search) { | ||||
s = lowercase(s); | |||||
search = lowercase(search); | |||||
s = stringLowercase(s); | |||||
search = stringLowercase(search); | |||||
return (s.find(search) != std::string::npos); | return (s.find(search) != std::string::npos); | ||||
} | } | ||||
@@ -90,7 +90,7 @@ void RackScene::onHoverKey(EventHoverKey &e) { | |||||
void RackScene::onPathDrop(EventPathDrop &e) { | void RackScene::onPathDrop(EventPathDrop &e) { | ||||
if (e.paths.size() >= 1) { | if (e.paths.size() >= 1) { | ||||
const std::string& firstPath = e.paths.front(); | const std::string& firstPath = e.paths.front(); | ||||
if (extractExtension(firstPath) == "vcv") { | |||||
if (stringExtension(firstPath) == "vcv") { | |||||
gRackWidget->loadPatch(firstPath); | gRackWidget->loadPatch(firstPath); | ||||
e.consumed = true; | e.consumed = true; | ||||
} | } | ||||
@@ -69,7 +69,7 @@ void RackWidget::reset() { | |||||
} | } | ||||
void RackWidget::openDialog() { | void RackWidget::openDialog() { | ||||
std::string dir = lastPath.empty() ? assetLocal("") : extractDirectory(lastPath); | |||||
std::string dir = lastPath.empty() ? assetLocal("") : stringDirectory(lastPath); | |||||
char *path = osdialog_file(OSDIALOG_OPEN, dir.c_str(), NULL, NULL); | char *path = osdialog_file(OSDIALOG_OPEN, dir.c_str(), NULL, NULL); | ||||
if (path) { | if (path) { | ||||
loadPatch(path); | loadPatch(path); | ||||
@@ -88,13 +88,13 @@ void RackWidget::saveDialog() { | |||||
} | } | ||||
void RackWidget::saveAsDialog() { | void RackWidget::saveAsDialog() { | ||||
std::string dir = lastPath.empty() ? assetLocal("") : extractDirectory(lastPath); | |||||
std::string dir = lastPath.empty() ? assetLocal("") : stringDirectory(lastPath); | |||||
char *path = osdialog_file(OSDIALOG_SAVE, dir.c_str(), "Untitled.vcv", NULL); | char *path = osdialog_file(OSDIALOG_SAVE, dir.c_str(), "Untitled.vcv", NULL); | ||||
if (path) { | if (path) { | ||||
std::string pathStr = path; | std::string pathStr = path; | ||||
free(path); | free(path); | ||||
std::string extension = extractExtension(pathStr); | |||||
std::string extension = stringExtension(pathStr); | |||||
if (extension.empty()) { | if (extension.empty()) { | ||||
pathStr += ".vcv"; | pathStr += ".vcv"; | ||||
} | } | ||||
@@ -230,7 +230,7 @@ void RackWidget::fromJson(json_t *rootJ) { | |||||
// Detect old patches with ModuleWidget::params/inputs/outputs indices. | // Detect old patches with ModuleWidget::params/inputs/outputs indices. | ||||
// (We now use Module::params/inputs/outputs indices.) | // (We now use Module::params/inputs/outputs indices.) | ||||
int legacy = 0; | int legacy = 0; | ||||
if (startsWith(version, "0.3.") || startsWith(version, "0.4.") || startsWith(version, "0.5.") || version == "" || version == "dev") { | |||||
if (stringStartsWith(version, "0.3.") || stringStartsWith(version, "0.4.") || stringStartsWith(version, "0.5.") || version == "" || version == "dev") { | |||||
legacy = 1; | legacy = 1; | ||||
message += "This patch was created with Rack 0.5 or earlier. Saving it will convert it to a Rack 0.6+ patch.\n\n"; | message += "This patch was created with Rack 0.5 or earlier. Saving it will convert it to a Rack 0.6+ patch.\n\n"; | ||||
} | } | ||||
@@ -370,7 +370,7 @@ static void extractPackages(std::string path) { | |||||
std::string message; | std::string message; | ||||
for (std::string packagePath : systemListDirectory(path)) { | for (std::string packagePath : systemListDirectory(path)) { | ||||
if (endsWith(packagePath, ".zip")) { | |||||
if (stringExtension(packagePath) == "zip") { | |||||
// Extract package | // Extract package | ||||
if (!extractZip(packagePath.c_str(), path.c_str())) { | if (!extractZip(packagePath.c_str(), path.c_str())) { | ||||
message += stringf("Could not extract package %s\n", path); | message += stringf("Could not extract package %s\n", path); | ||||
@@ -24,47 +24,47 @@ std::string stringf(const char *format, ...) { | |||||
return s; | return s; | ||||
} | } | ||||
std::string lowercase(std::string s) { | |||||
std::string stringLowercase(std::string s) { | |||||
std::transform(s.begin(), s.end(), s.begin(), ::tolower); | std::transform(s.begin(), s.end(), s.begin(), ::tolower); | ||||
return s; | return s; | ||||
} | } | ||||
std::string uppercase(std::string s) { | |||||
std::string stringUppercase(std::string s) { | |||||
std::transform(s.begin(), s.end(), s.begin(), ::toupper); | std::transform(s.begin(), s.end(), s.begin(), ::toupper); | ||||
return s; | return s; | ||||
} | } | ||||
std::string ellipsize(std::string s, size_t len) { | |||||
std::string stringEllipsize(std::string s, size_t len) { | |||||
if (s.size() <= len) | if (s.size() <= len) | ||||
return s; | return s; | ||||
else | else | ||||
return s.substr(0, len - 3) + "..."; | return s.substr(0, len - 3) + "..."; | ||||
} | } | ||||
bool startsWith(std::string str, std::string prefix) { | |||||
bool stringStartsWith(std::string str, std::string prefix) { | |||||
return str.substr(0, prefix.size()) == prefix; | return str.substr(0, prefix.size()) == prefix; | ||||
} | } | ||||
bool endsWith(std::string str, std::string suffix) { | |||||
bool stringEndsWith(std::string str, std::string suffix) { | |||||
return str.substr(str.size() - suffix.size(), suffix.size()) == suffix; | return str.substr(str.size() - suffix.size(), suffix.size()) == suffix; | ||||
} | } | ||||
std::string extractDirectory(std::string path) { | |||||
std::string stringDirectory(std::string path) { | |||||
char *pathDup = strdup(path.c_str()); | char *pathDup = strdup(path.c_str()); | ||||
std::string directory = dirname(pathDup); | std::string directory = dirname(pathDup); | ||||
free(pathDup); | free(pathDup); | ||||
return directory; | return directory; | ||||
} | } | ||||
std::string extractFilename(std::string path) { | |||||
std::string stringFilename(std::string path) { | |||||
char *pathDup = strdup(path.c_str()); | char *pathDup = strdup(path.c_str()); | ||||
std::string filename = basename(pathDup); | std::string filename = basename(pathDup); | ||||
free(pathDup); | free(pathDup); | ||||
return filename; | return filename; | ||||
} | } | ||||
std::string extractExtension(std::string path) { | |||||
const char *ext = strrchr(path.c_str(), '.'); | |||||
std::string stringExtension(std::string path) { | |||||
const char *ext = strrchr(stringFilename(path).c_str(), '.'); | |||||
if (!ext) | if (!ext) | ||||
return ""; | return ""; | ||||
return ext + 1; | return ext + 1; | ||||
@@ -436,7 +436,7 @@ void windowRun() { | |||||
windowTitle += gApplicationVersion; | windowTitle += gApplicationVersion; | ||||
if (!gRackWidget->lastPath.empty()) { | if (!gRackWidget->lastPath.empty()) { | ||||
windowTitle += " - "; | windowTitle += " - "; | ||||
windowTitle += extractFilename(gRackWidget->lastPath); | |||||
windowTitle += stringFilename(gRackWidget->lastPath); | |||||
} | } | ||||
if (windowTitle != lastWindowTitle) { | if (windowTitle != lastWindowTitle) { | ||||
glfwSetWindowTitle(gWindow, windowTitle.c_str()); | glfwSetWindowTitle(gWindow, windowTitle.c_str()); | ||||