From: Han-Wen Nienhuys Date: Wed, 29 Nov 2006 13:58:50 +0000 (+0100) Subject: c++ interface for camel_case_to_lisp_identifier X-Git-Tag: release/2.11.1-1~46 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=26a80dad98146b2800c6ab508e5758b0281b72ad;p=lilypond.git c++ interface for camel_case_to_lisp_identifier --- 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 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; +} +