]> git.donarmstrong.com Git - lilypond.git/commitdiff
Interface changes for string functions:
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 1 Jun 2008 22:58:58 +0000 (19:58 -0300)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 1 Jun 2008 22:58:58 +0000 (19:58 -0300)
 - replace_all() takes string*
 - remove some scm_i_XXX uses.

13 files changed:
flower/file-name.cc
flower/getopt-long.cc
flower/include/std-string.hh
flower/std-string.cc
lily/accidental.cc
lily/break-substitution.cc
lily/easy-notation.cc
lily/font-metric.cc
lily/general-scheme.cc
lily/lily-guile.cc
lily/misc.cc
lily/program-option-scheme.cc
lily/translator.cc

index bf645df23d78ecdd3fccb67d90978214765477f7..1eff46be5245226db967269c945aa8e0a92c96bf 100644 (file)
@@ -61,8 +61,8 @@ static /* avoid warning */
 string
 slashify (string file_name)
 {
-  replace_all (file_name, '\\', '/');
-  replace_all (file_name, string ("//"), "/");
+  replace_all (&file_name, '\\', '/');
+  replace_all (&file_name, string ("//"), "/");
   return file_name;
 }
 
@@ -185,7 +185,7 @@ File_name::canonicalized () const
 {
   File_name c = *this;
 
-  replace_all (c.dir_, string ("//"), string ("/"));
+  replace_all (&c.dir_, string ("//"), string ("/"));
 
   vector<string> components =  string_split (c.dir_, '/');
   vector<string> new_components;
index 2cb537c67b39724afa5d06e57f8697e3e7115277..37a964219dbecc5929968e497d7c5297b8dcafbe 100644 (file)
@@ -310,7 +310,7 @@ Long_option_init::table_string (Long_option_init *l)
       s += string (wid - s.length () + EXTRA_SPACES, ' ');
 
       string help_text (gettext (l[i].help_str0_));
-      replace_all (help_text, "\n",
+      replace_all (&help_text, "\n",
                   "\n" + string (wid + EXTRA_SPACES + 2, ' '));
       tabstr += s + help_text + "\n";
     }
index 57805bbe21d95206d55d65ea8fc820062a5e43fe..d5933d8f99985075de4908f475dc5bd9cebb3363 100644 (file)
@@ -38,8 +38,8 @@ string to_string (bool b);
 string to_string (char const *format, ...)
   __attribute__ ((format (printf, 1, 2)));
   
-string &replace_all (string &str, string find, string replace);
-string &replace_all (string &str, char find, char replace);
+string &replace_all (string* str, string const &find, string const &replace);
+string &replace_all (stringstr, char find, char replace);
 char *string_copy (string s);
 
 int string_compare (string const &, string const &);
index 1221609c6c0ce4bc2e76a140d4fcbb1ed35f3d11..5232574366c79c950c4e99101b09e5c88535764d 100644 (file)
@@ -71,20 +71,20 @@ to_string (char const *format, ...)
   TODO: this O(n^2) in #occurences of find, due to repeated copying.
  */
 string &
-replace_all (string &str, string find, string replace)
+replace_all (string *str, string const &find, string const &replace)
 {
   ssize len = find.length ();
-  for (ssize i = str.find (find); i != NPOS; i = str.find (find, i + len))
-    str = str.replace (i, len, replace);
-  return str;
+  for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + len))
+    *str = str->replace (i, len, replace);
+  return *str;
 }
 
 string &
-replace_all (string &str, char find, char replace)
+replace_all (string *str, char find, char replace)
 {
-  for (ssize i = str.find (find); i != NPOS; i = str.find (find, i + 1))
-    str[i] = replace;
-  return str;
+  for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + 1))
+    (*str)[i] = replace;
+  return *str;
 }
 
 char *
index c91152522846c48284b9b9cf9cb55ff5c758e40a..7f3a97b4f77153882a5639396f091af9f7fcc498 100644 (file)
@@ -189,7 +189,7 @@ Accidental_interface::get_stencil (Grob *me)
       return SCM_EOL;
     }
   
-  Stencil mol (fm->find_by_name (scm_i_string_chars (glyph_name)));
+  Stencil mol (fm->find_by_name (ly_scm2string (glyph_name)));
   if (to_boolean (me->get_property ("restore-first")))
     {
       /*
index f283010303ae2be12956e40229d51d96661bcff1..67697136d2e36bd5d7ce714ace8c460ee06502ec 100644 (file)
@@ -263,6 +263,8 @@ grob_system_range (Grob *g)
 struct Substitution_entry
 {
   Grob *grob_;
+
+  /* Assumption: we have less than 32k paper columns. */
   short left_;
   short right_;
 
index 34c0a97f781823f9936ae4e625f68ad7e7c3f2d0..c5d886147b59b5c5c3de32a12cf3fe6b0dde8e9e 100644 (file)
@@ -45,8 +45,8 @@ Note_head::brew_ez_stencil (SCM smob)
   else
     {
       char s[2] = "a";
-      s[0] = (pit->get_notename () + 2) % 7 + 'a';
-      s[0] = toupper (s[0]);
+      s[0] = char ((pit->get_notename () + 2) % 7 + 'a');
+      s[0] = char (toupper (s[0]));
       charstr = scm_from_locale_string (s);
     }
 
index 655d992123f4859cbc4d73cbdf430d22fbaafc4e..215bf679812bee9da7f56682e67dd41cfd9b9bb9 100644 (file)
@@ -31,7 +31,7 @@ Font_metric::design_size () const
 Stencil
 Font_metric::find_by_name (string s) const
 {
-  replace_all (s, '-', 'M');
+  replace_all (&s, '-', 'M');
   int idx = name_to_index (s);
   Box b;
 
index 7d4b5c1c30999361db6d9ccfb58e360e61480d1c..fd27481938d232f69edcfa5388d5a4c7e6b40597 100644 (file)
@@ -180,8 +180,9 @@ LY_DEFINE (ly_string_substitute, "ly:string-substitute",
   LY_ASSERT_TYPE (scm_is_string, s, 3);
 
   string ss = ly_scm2string (s);
-  replace_all (ss, string (scm_i_string_chars (a)),
-                  string (scm_i_string_chars (b)));
+  replace_all (&ss, ly_scm2string (a),
+              ly_scm2string (b));
+  
   return ly_string2scm (ss);
 }
   
@@ -245,11 +246,11 @@ LY_DEFINE (ly_protects, "ly:protects",
 }
 
 LY_DEFINE (ly_gettext, "ly:gettext",
-          1, 0, 0, (SCM string),
+          1, 0, 0, (SCM original),
           "A Scheme wrapper function for @code{gettext}.")
 {
-  LY_ASSERT_TYPE (scm_is_string, string, 1);
-  return ly_string2scm (_ (scm_i_string_chars (string)));
+  LY_ASSERT_TYPE (scm_is_string, original, 1);
+  return ly_string2scm (_ (ly_scm2string (original).c_str ()));
 }
 
 LY_DEFINE (ly_output_formats, "ly:output-formats",
index 9da6823f194e89e91ab15a13c4ab751ed3b4d03e..9f62fbb670096940e457dda8c8c79bfda6544e61 100644 (file)
@@ -111,8 +111,13 @@ string
 ly_scm2string (SCM str)
 {
   assert (scm_is_string (str));
-  return string (scm_i_string_chars (str),
-                (int) scm_i_string_length (str));
+  string result;
+  size_t len = scm_c_string_length (str);
+  if (len) {
+    result.resize(len);
+    scm_to_locale_stringbuf(str, &result.at(0), len);
+  }
+  return result;
 }
 
 SCM
@@ -126,30 +131,16 @@ ly_string2scm (string const &str)
 char *
 ly_scm2newstr (SCM str, size_t *lenp)
 {
-  LY_ASSERT_TYPE (scm_is_string, str, 1);
-
-  size_t len = scm_i_string_length (str);
-  if (char *new_str = (char *) malloc ((len + 1) * sizeof (char)))
-    {
-      memcpy (new_str, scm_i_string_chars (str), len);
-      new_str[len] = '\0';
-
-      if (lenp)
-       *lenp = len;
-
-      return new_str;
-    }
-  return 0;
+  char* p = scm_to_locale_stringn(str, lenp);
+  return p;
 }
 
-
 /*
   PAIRS
 */
-SCM
+SCM 
 index_get_cell (SCM s, Direction d)
 {
-
   assert (d);
   return (d == LEFT) ? scm_car (s) : scm_cdr (s);
 }
@@ -178,7 +169,6 @@ ly_scm_hash (SCM s)
   return scm_ihashv (s, ~1u);
 }
 
-
 bool
 is_axis (SCM s)
 {
@@ -634,10 +624,10 @@ mangle_cxx_identifier (string cxx_id)
   else if (cxx_id.substr (cxx_id.length () - 2) == "_x")
     cxx_id = cxx_id.replace (cxx_id.length () - 2, 2, "!");
 
-  cxx_id = replace_all (cxx_id, "_less?", "<?");
-  cxx_id = replace_all (cxx_id, "_2_", "->");
-  cxx_id = replace_all (cxx_id, "__", "::");
-  cxx_id = replace_all (cxx_id, '_', '-');
+  replace_all (&cxx_id, "_less?", "<?");
+  replace_all (&cxx_id, "_2_", "->");
+  replace_all (&cxx_id, "__", "::");
+  replace_all (&cxx_id, '_', '-');
 
 
   return cxx_id;
@@ -661,9 +651,9 @@ parse_symbol_list (char const *symbols)
   while (isspace (*symbols))
     *symbols++;
   string s = symbols;
-  replace_all (s, '\n', ' ');
-  replace_all (s, '\t', ' ');
-  replace_all (s, "  ", " ");
+  replace_all (&s, '\n', ' ');
+  replace_all (&s, '\t', ' ');
+  replace_all (&s, "  ", " ");
   return ly_string_array_to_scm (string_split (s, ' '));
 }
 
index 6837df0d744838c4eff0978318902ff3d6324e6c..3b9d87da162859c339b6a5a66548bd6a17e4d572 100644 (file)
@@ -71,17 +71,17 @@ camel_case_to_lisp_identifier (string in)
   vector<char> out;
   
   /* don't add '-' before first character */
-  out.push_back (tolower (in[0]));
+  out.push_back (char (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]));
+      out.push_back ( char(tolower (in[inpos])));
     }
   
   string result (&out[0], out.size ());
-  replace_all (result, '_', '-');
+  replace_all (&result, '_', '-');
 
   return result;
 }
index 4ec898092e09af3933cbe951c291624cfc920c14..f47abed2cc53fd1ac2448db7b41fab85ac8ee5cf 100644 (file)
@@ -149,7 +149,7 @@ get_help_string ()
       SCM opt_help_scm
        = scm_object_property (sym, ly_symbol2scm ("program-option-documentation"));
       string opt_help = ly_scm2string (opt_help_scm);
-      replace_all (opt_help,
+      replace_all (&opt_help,
                   string ("\n"),
                   string ("\n")
                   + String_convert::char_string (' ', HELP_INDENT));
index e4cb27d3b716c230a2af889ef55d25b83f7cd71b..dc70c155ce97058e9491a598360ceb7f3d19012c 100644 (file)
@@ -171,7 +171,7 @@ Translator::add_translator_listener (translator_listener_record **listener_list,
 {
   /* ev_class is the C++ identifier name. Convert to scm symbol */
   string name = string (ev_class);
-  name = replace_all (name, '_', '-');
+  name = replace_all (&name, '_', '-');
   name += "-event";
   
   SCM class_sym = scm_str2symbol (name.c_str ());
@@ -275,7 +275,7 @@ add_acknowledger (Engraver_void_function_engraver_grob_info ptr,
 
   string interface_name (func_name);
 
-  interface_name = replace_all (interface_name, '_', '-');
+  interface_name = replace_all (&interface_name, '_', '-');
   interface_name += "-interface";
 
   /*
@@ -342,7 +342,7 @@ internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const ch
 
       /* "listen_foo_bar" -> "foo-bar" */
       ev_class.erase (0, strlen (prefix));
-      replace_all (ev_class, '_', '-');
+      replace_all (&ev_class, '_', '-');
 
       new_ev->origin ()->warning (_f ("Two simultaneous %s events, junking this one", ev_class.c_str ()));
       (*old_ev)->origin ()->warning (_f ("Previous %s event here", ev_class.c_str ()));