diff options
author | Florian Jung <flo@thinkpad.(none)> | 2011-01-10 17:32:36 +0100 |
---|---|---|
committer | Florian Jung <flo@thinkpad.(none)> | 2011-01-10 17:35:46 +0100 |
commit | 4b87549a645fd62107ddc5295a5027b2a5851096 (patch) | |
tree | 56601c12d5d3057fbd403c9c6b46e6b042073cb2 /synth | |
parent | eb81cf5820770c54d33facaf09f7f79a17e272ed (diff) |
Added str_before and str_after functions
str_before ("foo:bar:baz",':',"doesntmatter") returns "foo"
str_after ("foo:bar:baz",':',"doesntmatter") returns "bar:baz"
str_after and str_before ("foobar",':',"default") returns "default"
Also, extract_var and extract_val now use the newly created functions
Diffstat (limited to 'synth')
-rw-r--r-- | synth/util.cpp | 22 | ||||
-rw-r--r-- | synth/util.h | 2 |
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 |