[recipes] Add api to get the units for an ingredient
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add api to get the units for an ingredient
- Date: Wed, 14 Dec 2016 01:40:32 +0000 (UTC)
commit 3cbc1e777dcc284497032806d7cc4ecba1b0713f
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 13 20:35:05 2016 -0500
Add api to get the units for an ingredient
src/gr-ingredients-list.c | 36 +++++++++++++++++++++++++++++++++---
src/gr-ingredients-list.h | 9 +++++++--
2 files changed, 40 insertions(+), 5 deletions(-)
---
diff --git a/src/gr-ingredients-list.c b/src/gr-ingredients-list.c
index 4f587e3..1766fe0 100644
--- a/src/gr-ingredients-list.c
+++ b/src/gr-ingredients-list.c
@@ -409,17 +409,23 @@ format_scaled_number (Ingredient *ing, int num, int denom)
}
static void
-ingredient_scale (Ingredient *ing, int num, int denom, GString *s)
+ingredient_scale_unit (Ingredient *ing, int num, int denom, GString *s)
{
g_autofree char *scaled = NULL;
scaled = format_scaled_number (ing, num, denom);
g_string_append (s, scaled);
- g_string_append (s, " ");
if (ing->unit) {
- g_string_append (s, ing->unit);
g_string_append (s, " ");
+ g_string_append (s, ing->unit);
}
+}
+
+static void
+ingredient_scale (Ingredient *ing, int num, int denom, GString *s)
+{
+ ingredient_scale_unit (ing, num, denom, s);
+ g_string_append (s, " ");
g_string_append (s, ing->name);
g_string_append (s, "\n");
}
@@ -458,3 +464,27 @@ gr_ingredients_list_get_ingredients (GrIngredientsList *ingredients)
return ret;
}
+
+char *
+gr_ingredients_list_scale_unit (GrIngredientsList *ingredients,
+ const char *name,
+ int num,
+ int denom)
+{
+ GList *l;
+
+ for (l = ingredients->ingredients; l; l = l->next) {
+ Ingredient *ing = (Ingredient *)l->data;
+
+ if (g_strcmp0 (name, ing->name) == 0) {
+ GString *s;
+
+ s = g_string_new ("");
+ ingredient_scale_unit (ing, num, denom, s);
+
+ return g_string_free (s, FALSE);
+ }
+ }
+
+ return NULL;
+}
diff --git a/src/gr-ingredients-list.h b/src/gr-ingredients-list.h
index f255490..f15c9c7 100644
--- a/src/gr-ingredients-list.h
+++ b/src/gr-ingredients-list.h
@@ -32,9 +32,14 @@ GrIngredientsList *gr_ingredients_list_new (const char *text
gboolean gr_ingredients_list_validate (const char *text,
GError **error);
-gchar *gr_ingredients_list_scale (GrIngredientsList *ingredients,
+char *gr_ingredients_list_scale (GrIngredientsList *ingredients,
int num,
int denom);
-gchar **gr_ingredients_list_get_ingredients (GrIngredientsList *ingredients);
+char *gr_ingredients_list_scale_unit (GrIngredientsList *ingredients,
+ const char *name,
+ int num,
+ int denom);
+char **gr_ingredients_list_get_ingredients (GrIngredientsList *ingredients);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]