From 26a80dad98146b2800c6ab508e5758b0281b72ad Mon Sep 17 00:00:00 2001
From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Wed, 29 Nov 2006 14:58:50 +0100
Subject: [PATCH] c++ interface for camel_case_to_lisp_identifier

---
 lily/include/misc.hh |  2 ++
 lily/misc.cc         | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/lily/include/misc.hh b/lily/include/misc.hh
index 4303d3b7b5..fa7555d086 100644
--- a/lily/include/misc.hh
+++ b/lily/include/misc.hh
@@ -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
 
diff --git a/lily/misc.cc b/lily/misc.cc
index e7c3063df2..aa49a697a6 100644
--- a/lily/misc.cc
+++ b/lily/misc.cc
@@ -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;
+}
+
-- 
2.39.5