summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--synth/util.cpp22
-rw-r--r--synth/util.h2
2 files changed, 18 insertions, 6 deletions
diff --git a/synth/util.cpp b/synth/util.cpp
index 51e6fda..2862fdb 100644
--- a/synth/util.cpp
+++ b/synth/util.cpp
@@ -175,24 +175,34 @@ parameter_enum param_to_enum(string param)
return UNKNOWN;
}
-string extract_var(string s)
+string str_before(string s, char delim, string onfail)
{
size_t p;
- p=s.find('=');
+ p=s.find(delim);
if (p!=string::npos)
return s.substr(0,p);
else
- return "";
+ return onfail;
}
-string extract_val(string s)
+string str_after(string s, char delim, string onfail)
{
size_t p;
- p=s.find('=');
+ p=s.find(delim);
if (p!=string::npos)
return s.substr(p+1);
else
- return s;
+ return onfail;
+}
+
+string extract_var(string s)
+{
+ return str_before(s,'=',"");
+}
+
+string extract_val(string s)
+{
+ return str_after(s,'=',s);
}
string fileext(string f)
diff --git a/synth/util.h b/synth/util.h
index e571c7d..ad88954 100644
--- a/synth/util.h
+++ b/synth/util.h
@@ -28,4 +28,6 @@ string extract_val(string s);
string fileext(string f);
+string str_before(string s, char delim, string onfail="");
+string str_after(string s, char delim, string onfail="");
#endif