Browse Source

add findstring

georges 25 years ago
parent
commit
d6340a6941
2 changed files with 30 additions and 0 deletions
  1. 29 0
      ppremake/ppScope.cxx
  2. 1 0
      ppremake/ppScope.h

+ 29 - 0
ppremake/ppScope.cxx

@@ -838,6 +838,8 @@ r_expand_variable(const string &str, size_t &vp,
       return expand_length(params);
     } else if (funcname == "substr") {
       return expand_substr(params);
+    } else if (funcname == "findstring") {
+      return expand_findstring(params);
     } else if (funcname == "dir") {
       return expand_dir(params);
     } else if (funcname == "notdir") {
@@ -1515,6 +1517,8 @@ expand_shell(const string &params) {
 }
 
 
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PPScope::expand_standardize
 //       Access: Private
@@ -2099,6 +2103,31 @@ expand_subst(const string &params) {
   return str;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_findstrnig
+//       Access: Private
+//  Description: Expands the "findstring" function variable.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_findstring(const string &params) {
+  // Split the string up into tokens based on the commas.
+  vector<string> tokens;
+  tokenize_params(params, tokens, true);
+
+  if (tokens.size() != 2) {
+    cerr << "findstring requires two parameters.\n";
+    return string();
+  }
+  string str = tokens.back();
+  const string &srchstr = tokens[0];
+  size_t q = 0;
+  size_t p = str.find(srchstr, q);
+  if(p == string::npos)
+    str = "";
+
+  return str;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PPScope::expand_wordsubst
 //       Access: Private

+ 1 - 0
ppremake/ppScope.h

@@ -94,6 +94,7 @@ private:
   string expand_standardize(const string &params);
   string expand_length(const string &params);
   string expand_substr(const string &params);
+  string expand_findstring(const string &params);
   string expand_dir(const string &params);
   string expand_notdir(const string &params);
   string expand_suffix(const string &params);