Browse Source

Add prefix to string functions

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
158a396170
7 changed files with 28 additions and 27 deletions
  1. +10
    -9
      include/util/common.hpp
  2. +2
    -2
      src/app/ModuleBrowser.cpp
  3. +1
    -1
      src/app/RackScene.cpp
  4. +4
    -4
      src/app/RackWidget.cpp
  5. +1
    -1
      src/plugin.cpp
  6. +9
    -9
      src/util/string.cpp
  7. +1
    -1
      src/window.cpp

+ 10
- 9
include/util/common.hpp View File

@@ -126,17 +126,18 @@ inline float DEPRECATED randomf() {return randomUniform();}

/** Converts a printf format string and optional arguments into a std::string */
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 */
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


+ 2
- 2
src/app/ModuleBrowser.cpp View File

@@ -18,8 +18,8 @@ static ModelTag sTagFilter = NO_TAG;


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);
}



+ 1
- 1
src/app/RackScene.cpp View File

@@ -90,7 +90,7 @@ void RackScene::onHoverKey(EventHoverKey &e) {
void RackScene::onPathDrop(EventPathDrop &e) {
if (e.paths.size() >= 1) {
const std::string& firstPath = e.paths.front();
if (extractExtension(firstPath) == "vcv") {
if (stringExtension(firstPath) == "vcv") {
gRackWidget->loadPatch(firstPath);
e.consumed = true;
}


+ 4
- 4
src/app/RackWidget.cpp View File

@@ -69,7 +69,7 @@ void RackWidget::reset() {
}

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);
if (path) {
loadPatch(path);
@@ -88,13 +88,13 @@ void RackWidget::saveDialog() {
}

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);

if (path) {
std::string pathStr = path;
free(path);
std::string extension = extractExtension(pathStr);
std::string extension = stringExtension(pathStr);
if (extension.empty()) {
pathStr += ".vcv";
}
@@ -230,7 +230,7 @@ void RackWidget::fromJson(json_t *rootJ) {
// Detect old patches with ModuleWidget::params/inputs/outputs indices.
// (We now use Module::params/inputs/outputs indices.)
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;
message += "This patch was created with Rack 0.5 or earlier. Saving it will convert it to a Rack 0.6+ patch.\n\n";
}


+ 1
- 1
src/plugin.cpp View File

@@ -370,7 +370,7 @@ static void extractPackages(std::string path) {
std::string message;

for (std::string packagePath : systemListDirectory(path)) {
if (endsWith(packagePath, ".zip")) {
if (stringExtension(packagePath) == "zip") {
// Extract package
if (!extractZip(packagePath.c_str(), path.c_str())) {
message += stringf("Could not extract package %s\n", path);


+ 9
- 9
src/util/string.cpp View File

@@ -24,47 +24,47 @@ std::string stringf(const char *format, ...) {
return s;
}

std::string lowercase(std::string s) {
std::string stringLowercase(std::string s) {
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s;
}

std::string uppercase(std::string s) {
std::string stringUppercase(std::string s) {
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
return s;
}

std::string ellipsize(std::string s, size_t len) {
std::string stringEllipsize(std::string s, size_t len) {
if (s.size() <= len)
return s;
else
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;
}

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;
}

std::string extractDirectory(std::string path) {
std::string stringDirectory(std::string path) {
char *pathDup = strdup(path.c_str());
std::string directory = dirname(pathDup);
free(pathDup);
return directory;
}

std::string extractFilename(std::string path) {
std::string stringFilename(std::string path) {
char *pathDup = strdup(path.c_str());
std::string filename = basename(pathDup);
free(pathDup);
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)
return "";
return ext + 1;


+ 1
- 1
src/window.cpp View File

@@ -436,7 +436,7 @@ void windowRun() {
windowTitle += gApplicationVersion;
if (!gRackWidget->lastPath.empty()) {
windowTitle += " - ";
windowTitle += extractFilename(gRackWidget->lastPath);
windowTitle += stringFilename(gRackWidget->lastPath);
}
if (windowTitle != lastWindowTitle) {
glfwSetWindowTitle(gWindow, windowTitle.c_str());


Loading…
Cancel
Save