]> git.donarmstrong.com Git - lilypond.git/commitdiff
c++ interface for camel_case_to_lisp_identifier
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 29 Nov 2006 13:58:50 +0000 (14:58 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 29 Nov 2006 13:58:50 +0000 (14:58 +0100)
lily/include/misc.hh
lily/misc.cc

index 4303d3b7b59e9f7ef7054a30143f3db173e73d3f..fa7555d0861ef6bde612b20967ef6404aaa50fbb 100644 (file)
@@ -38,5 +38,7 @@ linear_interpolate (Real x, Real x1, Real x2, Real y1, Real y2)
 Real directed_round (Real f, Direction d);
 
 Real peak_around (Real epsilon,  Real threshold, Real x);
+string camel_case_to_lisp_identifier (string in);
+
 #endif
 
index e7c3063df234c6ce79bca6185bf9358e837e401b..aa49a697a6e990bac32fc78e76cd3ace09dd66ef 100644 (file)
@@ -55,3 +55,26 @@ peak_around (Real epsilon,  Real threshold, Real x)
     return 1.0;
   return max (- epsilon * (x - threshold) / ((x + epsilon)  * threshold), 0.0);
 }
+
+
+string
+camel_case_to_lisp_identifier (string in)
+{
+  vector<char> out;
+  
+  /* don't add '-' before first character */
+  out.push_back (tolower (in[0]));
+    
+  for (size_t inpos = 1; inpos < in.size (); inpos++)
+    {
+      if (isupper (in[inpos]))
+       out.push_back ('-');
+      out.push_back (tolower (in[inpos]));
+    }
+  
+  string result (&out[0], out.size ());
+  replace_all (result, '_', '-');
+
+  return result;
+}
+