Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2103)

Side by Side Diff: lily/general-scheme.cc

Issue 109070: Use our own ~s ly:format placeholder, since guile is broken with wide chars (Closed)
Patch Set: Created 14 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | scm/backend-library.scm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 lily-guile.cc -- implement assorted Guile bindings 2 lily-guile.cc -- implement assorted Guile bindings
3 3
4 source file of the GNU LilyPond music typesetter 4 source file of the GNU LilyPond music typesetter
5 5
6 (c) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org> 6 (c) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@xs4all.nl> 7 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */ 8 */
9 9
10 #include "config.hh" 10 #include "config.hh"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 for (; scm_is_pair (s) && k--; s = scm_cdr (s)) 404 for (; scm_is_pair (s) && k--; s = scm_cdr (s))
405 ; 405 ;
406 406
407 if (scm_is_pair (s)) 407 if (scm_is_pair (s))
408 scm_set_cdr_x (s, SCM_EOL); 408 scm_set_cdr_x (s, SCM_EOL);
409 } 409 }
410 return lst; 410 return lst;
411 } 411 }
412 412
413 string 413 string
414 format_single_argument (SCM arg, int precision) 414 format_single_argument (SCM arg, int precision, bool escape = false)
415 { 415 {
416 if (scm_is_integer (arg) && scm_exact_p (arg) == SCM_BOOL_T) 416 if (scm_is_integer (arg) && scm_exact_p (arg) == SCM_BOOL_T)
417 return (String_convert::int_string (scm_to_int (arg))); 417 return (String_convert::int_string (scm_to_int (arg)));
418 else if (scm_is_number (arg)) 418 else if (scm_is_number (arg))
419 { 419 {
420 Real val = scm_to_double (arg); 420 Real val = scm_to_double (arg);
421 421
422 if (isnan (val) || isinf (val)) 422 if (isnan (val) || isinf (val))
423 { 423 {
424 warning (_ ("Found infinity or nan in output. Substituting 0.0")); 424 warning (_ ("Found infinity or nan in output. Substituting 0.0"));
425 return ("0.0"); 425 return ("0.0");
426 if (strict_infinity_checking) 426 if (strict_infinity_checking)
427 abort (); 427 abort ();
428 } 428 }
429 else 429 else
430 return (String_convert::form_string ("%.*lf", precision, val)); 430 return (String_convert::form_string ("%.*lf", precision, val));
431 } 431 }
432 else if (scm_is_string (arg)) 432 else if (scm_is_string (arg)) {
Patrick McCarty 2009/08/21 23:49:51 Can you also fix the indentation (move open brace
433 return (ly_scm2string (arg)); 433 string s = ly_scm2string (arg);
434 else if (scm_is_symbol (arg)) 434 if (escape) {
435 // Escape backslashes and double quotes, wrap it in double quotes
436 replace_all (&s, "\\", "\\\\");
437 replace_all (&s, "\"", "\\\"");
joeneeman 2009/08/21 22:59:33 Don't forget to escape $. Or else use single quote
Reinhold 2009/08/22 00:11:34 Good catch. $ needs to be escaped, too. Using sing
438 s = "\"" + s + "\"";
439 }
440 return s;
441 } else if (scm_is_symbol (arg))
435 return (ly_symbol2string (arg)); 442 return (ly_symbol2string (arg));
436 else 443 else
437 { 444 {
438 ly_progress (scm_from_locale_string ("Unsupported SCM value for format: ~a "), 445 ly_progress (scm_from_locale_string ("Unsupported SCM value for format: ~a "),
439 scm_list_1 (arg)); 446 scm_list_1 (arg));
440 } 447 }
441 ·· 448 ··
442 ···· 449 ····
443 return "";···· 450 return "";····
444 } 451 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 if (spec == '$') 491 if (spec == '$')
485 precision = 2; 492 precision = 2;
486 else if (isdigit (spec)) 493 else if (isdigit (spec))
487 { 494 {
488 precision = spec - '0'; 495 precision = spec - '0';
489 spec = format.at (tilde ++); 496 spec = format.at (tilde ++);
490 } 497 }
491 ··················· 498 ···················
492 if (spec == 'a' || spec == 'A' || spec == 'f' || spec == '$') 499 if (spec == 'a' || spec == 'A' || spec == 'f' || spec == '$')
493 results.push_back (format_single_argument (arg, precision)); 500 results.push_back (format_single_argument (arg, precision));
501 else if (spec == 's' || spec == 'S')
502 results.push_back (format_single_argument (arg, precision, true));
494 else if (spec == 'l') 503 else if (spec == 'l')
495 { 504 {
496 SCM s = arg; 505 SCM s = arg;
497 for (; scm_is_pair (s); s = scm_cdr (s)) 506 for (; scm_is_pair (s); s = scm_cdr (s))
498 { 507 {
499 results.push_back (format_single_argument (scm_car (s), precis ion)); 508 results.push_back (format_single_argument (scm_car (s), precis ion));
500 if (scm_cdr (s) != SCM_EOL) 509 if (scm_cdr (s) != SCM_EOL)
501 results.push_back (" "); 510 results.push_back (" ");
502 } 511 }
503 512
(...skipping 18 matching lines...) Expand all
522 char *ptr = result; 531 char *ptr = result;
523 for (vsize i = 0; i < results.size (); i++) 532 for (vsize i = 0; i < results.size (); i++)
524 { 533 {
525 strncpy (ptr, results[i].c_str (), results[i].size ()); 534 strncpy (ptr, results[i].c_str (), results[i].size ());
526 ptr += results[i].size (); 535 ptr += results[i].size ();
527 } 536 }
528 *ptr = '\0'; 537 *ptr = '\0';
529 ···· 538 ····
530 return scm_take_locale_stringn (result, len); 539 return scm_take_locale_stringn (result, len);
531 } 540 }
OLDNEW
« no previous file with comments | « no previous file | scm/backend-library.scm » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b