X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmisc.cc;h=d605eb88a5fa9ec3fec46a339da4b9f5a7b0836c;hb=08bfc5231f319373ded486c5d99fbebc428b9415;hp=bd7cce55c7e4fc887e3985d18c5ba20ec107d225;hpb=7e72a1e50e94a7f9738d62599de79fe7745f600c;p=lilypond.git diff --git a/lily/misc.cc b/lily/misc.cc index bd7cce55c7..d605eb88a5 100644 --- a/lily/misc.cc +++ b/lily/misc.cc @@ -3,34 +3,69 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2004 Han-Wen Nienhuys - Jan Nieuwenhuizen + (c) 1997--2006 Han-Wen Nienhuys + Jan Nieuwenhuizen */ -#include + #include "misc.hh" +#include "string.hh" /* - Return the 2-log, rounded down - */ + Return the 2-log, rounded down +*/ int intlog2 (int d) { assert (d); - int i=0; - while ((d != 1)) + int i = 0; + while ((d != 1)) { d /= 2; i++; } - - assert (! (d/2)); + + assert (! (d / 2)); return i; } double log_2 (double x) { - return log (x) /log (2.0); + return log (x) / log (2.0); +} + +Array +split_string (String s, char c) +{ + Array rv; + while (s.length ()) + { + int i = s.index (c); + + if (i == 0) + { + s = s.nomid_string (0, 1); + continue; + } + + if (i == NPOS) + i = s.length (); + + rv.push (s.cut_string (0, i)); + s = s.nomid_string (0, i); + } + + return rv; +} + + +Real +directed_round (Real f, Direction d) +{ + if (d < 0) + return floor (f); + else + return ceil (f); }