[beast: 22/24] BEAST: use Rapicorn's string_format()
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 22/24] BEAST: use Rapicorn's string_format()
- Date: Thu, 24 Sep 2015 20:11:27 +0000 (UTC)
commit 9480590f2512f358562066a982b5877b197f6152
Author: Tim Janik <timj gnu org>
Date: Wed Sep 23 20:57:03 2015 +0200
BEAST: use Rapicorn's string_format()
beast-gtk/bstpatterncolumns.cc | 3 ++-
beast-gtk/bstpatternview.cc | 18 +++++++-----------
beast-gtk/bstpianoroll.cc | 9 ++++-----
beast-gtk/bsttrackroll.cc | 9 ++++-----
beast-gtk/gxk/gxktexttools.cc | 5 ++---
5 files changed, 19 insertions(+), 25 deletions(-)
---
diff --git a/beast-gtk/bstpatterncolumns.cc b/beast-gtk/bstpatterncolumns.cc
index 4054a84..8c16e8d 100644
--- a/beast-gtk/bstpatterncolumns.cc
+++ b/beast-gtk/bstpatterncolumns.cc
@@ -321,9 +321,10 @@ pattern_column_event_to_string (BstPatternColumn *column, gchar buffer[64], cons
static const char *formats[] = { "%01x", "%02x", "%03x", "%04x", "%05x", "%06x", "%07x", "%08x",
"%09x" };
format = formats[n_digits - 1];
}
+ String tmp = string_format (format, ABS (ival));
if (is_signed)
*p++ = ival == 0 ? ' ' : ival > 0 ? '+' : '-';
- g_snprintf (p, 63, format, ABS (ival));
+ strcpy (p, tmp.c_str());
if (ivalue_p)
*ivalue_p = ival;
}
diff --git a/beast-gtk/bstpatternview.cc b/beast-gtk/bstpatternview.cc
index fdfa66d..80ac0c6 100644
--- a/beast-gtk/bstpatternview.cc
+++ b/beast-gtk/bstpatternview.cc
@@ -221,7 +221,6 @@ pattern_view_get_layout (GxkScrollCanvas *scc,
BstPatternView *self = BST_PATTERN_VIEW (scc);
PangoFontDescription *fdesc;
PangoRectangle rect = { 0 };
- gchar buffer[64];
guint i, accu = 0;
/* hpanel writings */
@@ -235,8 +234,7 @@ pattern_view_get_layout (GxkScrollCanvas *scc,
pango_font_description_merge (fdesc, STYLE (self)->font_desc, FALSE);
pango_layout_set_font_description (PLAYOUT_VPANEL (self), fdesc);
pango_font_description_free (fdesc);
- g_snprintf (buffer, 64, "%05x", self->max_ticks);
- pango_layout_set_text (PLAYOUT_VPANEL (self), buffer, -1);
+ pango_layout_set_text (PLAYOUT_VPANEL (self), string_format ("%05x", self->max_ticks).c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_VPANEL (self), NULL, &rect);
layout->left_panel_width = rect.width + 2 * XTHICKNESS (self);
@@ -622,7 +620,6 @@ bst_pattern_view_draw_hpanel (GxkScrollCanvas *scc,
BstPatternView *self = BST_PATTERN_VIEW (scc);
GdkGC *draw_gc = STYLE (self)->fg_gc[STATE (self)];
PangoRectangle rect = { 0 };
- gchar buffer[64];
gint i, width, height;
gdk_window_get_size (drawable, &width, &height);
bst_pattern_view_overlap_grow_hpanel_area (self, area);
@@ -640,8 +637,8 @@ bst_pattern_view_draw_hpanel (GxkScrollCanvas *scc,
tact4 /= (self->tpt * 4);
next_pixel = tick_to_coord (self, (tact4 + 1) * (self->tpt * 4));
- g_snprintf (buffer, 64, "%u", tact4 + 1);
- pango_layout_set_text (PLAYOUT_HPANEL (self), buffer, -1);
+ String tact4str = string_format ("%u", tact4 + 1);
+ pango_layout_set_text (PLAYOUT_HPANEL (self), tact4str.c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_HPANEL (self), NULL, &rect);
/* draw this tact if there's enough space */
@@ -660,8 +657,8 @@ bst_pattern_view_draw_hpanel (GxkScrollCanvas *scc,
if (tact == 1444)
continue; /* would draw on top of tact4 number */
- g_snprintf (buffer, 64, ":%u", tact % 4 + 1);
- pango_layout_set_text (PLAYOUT_HPANEL (self), buffer, -1);
+ String tact4str = string_format (":%u", tact % 4 + 1);
+ pango_layout_set_text (PLAYOUT_HPANEL (self), tact4str.c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_HPANEL (self), NULL, &rect);
/* draw this tact if there's enough space */
@@ -683,7 +680,6 @@ bst_pattern_view_draw_vpanel (GxkScrollCanvas *scc,
GdkGC *draw_gc = STYLE (self)->fg_gc[STATE (self)];
gint row = coord_to_row (self, area->y, NULL);
gint validrow, width, height;
- gchar buffer[64];
GdkRectangle rect;
gdk_window_get_size (VPANEL (self), &width, &height);
@@ -693,8 +689,8 @@ bst_pattern_view_draw_vpanel (GxkScrollCanvas *scc,
PangoRectangle prect = { 0 };
gint tick;
row_to_ticks (self, row, &tick, NULL);
- g_snprintf (buffer, 64, "%05x", tick);
- pango_layout_set_text (PLAYOUT_VPANEL (self), buffer, -1);
+ String tickstr = string_format ("%05x", tick);
+ pango_layout_set_text (PLAYOUT_VPANEL (self), tickstr.c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_VPANEL (self), NULL, &prect);
gdk_draw_layout (drawable, draw_gc,
width - prect.width - XTHICKNESS (self),
diff --git a/beast-gtk/bstpianoroll.cc b/beast-gtk/bstpianoroll.cc
index b8d4003..19e72be 100644
--- a/beast-gtk/bstpianoroll.cc
+++ b/beast-gtk/bstpianoroll.cc
@@ -868,7 +868,6 @@ bst_piano_roll_draw_hpanel (GxkScrollCanvas *scc,
BstPianoRoll *self = BST_PIANO_ROLL (scc);
GdkGC *draw_gc = STYLE (self)->fg_gc[STATE (self)];
PangoRectangle rect = { 0 };
- gchar buffer[64];
int width, height;
gdk_window_get_size (drawable, &width, &height);
bst_piano_roll_overlap_grow_hpanel_area (self, area);
@@ -887,8 +886,8 @@ bst_piano_roll_draw_hpanel (GxkScrollCanvas *scc,
tact /= (self->ppqn * self->qnpt);
next_pixel = tick_to_coord (self, (tact + 1) * (self->ppqn * self->qnpt));
- g_snprintf (buffer, 64, "%u", tact + 1);
- pango_layout_set_text (PLAYOUT_HPANEL (self), buffer, -1);
+ String tact1str = string_format ("%u", tact + 1);
+ pango_layout_set_text (PLAYOUT_HPANEL (self), tact1str.c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_HPANEL (self), NULL, &rect);
/* draw this tact if there's enough space */
@@ -908,8 +907,8 @@ bst_piano_roll_draw_hpanel (GxkScrollCanvas *scc,
if (qn == 1)
continue; /* would draw on top of tact number */
- g_snprintf (buffer, 64, ":%u", qn);
- pango_layout_set_text (PLAYOUT_HPANEL (self), buffer, -1);
+ String qnstr = string_format (":%u", qn);
+ pango_layout_set_text (PLAYOUT_HPANEL (self), qnstr.c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_HPANEL (self), NULL, &rect);
/* draw this tact if there's enough space */
diff --git a/beast-gtk/bsttrackroll.cc b/beast-gtk/bsttrackroll.cc
index adf3731..a40dd3c 100644
--- a/beast-gtk/bsttrackroll.cc
+++ b/beast-gtk/bsttrackroll.cc
@@ -690,7 +690,6 @@ bst_track_roll_draw_hpanel (GxkScrollCanvas *scc,
BstTrackRoll *self = BST_TRACK_ROLL (scc);
GdkGC *draw_gc = STYLE (self)->fg_gc[STATE (self)];
PangoRectangle rect = { 0 };
- gchar buffer[64];
gint i, width, height;
gdk_window_get_size (drawable, &width, &height);
bst_track_roll_overlap_grow_hpanel_area (self, area);
@@ -708,8 +707,8 @@ bst_track_roll_draw_hpanel (GxkScrollCanvas *scc,
tact4 /= (self->tpt * 4);
next_pixel = tick_to_coord (self, (tact4 + 1) * (self->tpt * 4));
- g_snprintf (buffer, 64, "%u", tact4 * 4 + 1);
- pango_layout_set_text (PLAYOUT_HPANEL (self), buffer, -1);
+ String tact4str = string_format ("%u", tact4 * 4 + 1);
+ pango_layout_set_text (PLAYOUT_HPANEL (self), tact4str.c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_HPANEL (self), NULL, &rect);
/* draw this tact if there's enough space */
@@ -725,8 +724,8 @@ bst_track_roll_draw_hpanel (GxkScrollCanvas *scc,
tact /= self->tpt;
next_pixel = tick_to_coord (self, (tact + 1) * self->tpt);
- g_snprintf (buffer, 64, "%u", tact + 1);
- pango_layout_set_text (PLAYOUT_HPANEL (self), buffer, -1);
+ String tact1str = string_format ("%u", tact + 1);
+ pango_layout_set_text (PLAYOUT_HPANEL (self), tact1str.c_str(), -1);
pango_layout_get_pixel_extents (PLAYOUT_HPANEL (self), NULL, &rect);
/* draw this tact if there's enough space */
diff --git a/beast-gtk/gxk/gxktexttools.cc b/beast-gtk/gxk/gxktexttools.cc
index 0e4e750..a8b8d25 100644
--- a/beast-gtk/gxk/gxktexttools.cc
+++ b/beast-gtk/gxk/gxktexttools.cc
@@ -1958,9 +1958,8 @@ scroll_text_reload (GtkWidget *sctext)
);
while (n--)
{
- gchar istr[256];
- g_snprintf (istr, sizeof (istr), "<%lu> ", flist[n]->d_ino);
- g_string_append_printf (gstring, " %.20s ", istr);
+ std::string istr = string_format ("<%u> ", flist[n]->d_ino);
+ g_string_append (gstring, string_format (" %.20s ", istr).c_str());
g_string_append (gstring, "<span tag='hyperlink'><xlink ref='");
tmp = g_strconcat (file, "/", flist[n]->d_name, NULL);
g_string_add_xmlstr (gstring, tmp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]