Bladeren bron

Jon Parise adds $[join]

Jon Parise 23 jaren geleden
bovenliggende
commit
c273c065f5
2 gewijzigde bestanden met toevoegingen van 29 en 0 verwijderingen
  1. 28 0
      ppremake/ppScope.cxx
  2. 1 0
      ppremake/ppScope.h

+ 28 - 0
ppremake/ppScope.cxx

@@ -1047,6 +1047,8 @@ r_expand_variable(const string &str, size_t &vp,
       return expand_filter(params);
     } else if (funcname == "filter_out" || funcname == "filter-out") {
       return expand_filter_out(params);
+    } else if (funcname == "join") {
+      return expand_join(params);
     } else if (funcname == "sort") {
       return expand_sort(params);
     } else if (funcname == "unique") {
@@ -2390,6 +2392,32 @@ expand_wordsubst(const string &params) {
   return result;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_join
+//       Access: Private
+//  Description: Expands the "join" function variable: joins the list
+//               of words using the specified separator.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_join(const string &params) {
+  // Split the string up into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(params), words);
+
+  if (words.size() < 2) {
+    cerr << "joins requires at least two parameters.\n";
+    return string();
+  }
+
+  const string sep(words[0]);
+
+  // Remove the first word in the list (which we use as the separator).
+  words.erase(words.begin());
+  
+  string result = repaste(words, sep);
+  return result;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PPScope::expand_sort
 //       Access: Private

+ 1 - 0
ppremake/ppScope.h

@@ -113,6 +113,7 @@ private:
   string expand_filter_out(const string &params);
   string expand_wordsubst(const string &params);
   string expand_subst(const string &params);
+  string expand_join(const string &params);
   string expand_sort(const string &params);
   string expand_unique(const string &params);
   string expand_matrix(const string &params);