[recipes] Add new units



commit e4ffc78498ac5410c7d0e1a54e66f0f151306924
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Nov 11 19:15:21 2017 -0500

    Add new units
    
    Add a 'none' unit which will be used in cases where
    we don't need an amount, e.g. for 'Salt', and a 'number'
    unit which will be used for plan numbers, e.g. '5 apples'.

 src/gr-unit.c |   12 +++++++-----
 src/gr-unit.h |   13 ++++++++-----
 2 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/src/gr-unit.c b/src/gr-unit.c
index e0b3120..62fd4f5 100644
--- a/src/gr-unit.c
+++ b/src/gr-unit.c
@@ -40,7 +40,9 @@
  } GrUnitData;
  
  static GrUnitData units[] = {
-         { GR_UNIT_UNKNOWN,     GR_DIMENSION_DISCRETE, "",        "",                                "",     
                  "" },
+         { GR_UNIT_UNKNOWN,     GR_DIMENSION_NONE,      "",        "",                                "",    
                   "" },
+         { GR_UNIT_NONE,        GR_DIMENSION_NONE,      "",        "",                                "",    
                   "" },
+         { GR_UNIT_NUMBER,      GR_DIMENSION_DISCRETE,  "",        "",                                "",    
                   "" },
          { GR_UNIT_GRAM,        GR_DIMENSION_MASS,     "g",       NC_("unit abbreviation", "g"),     
NC_("unit name", "gram"), NC_("unit plural", "grams") },
          { GR_UNIT_KILOGRAM,    GR_DIMENSION_MASS,     "kg",      NC_("unit abbreviation", "kg"),    
NC_("unit name", "kilogram"), NC_("unit plural", "kilograms") },
          { GR_UNIT_POUND,       GR_DIMENSION_MASS,     "lb",      NC_("unit abbreviation", "lb"),    
NC_("unit name", "pound"), NC_("unit plural", "pounds") },
@@ -127,7 +129,7 @@
          GrUnitData *data = find_unit (unit);
          if (data)
                  return data->dimension;
-         return GR_DIMENSION_DISCRETE;
+         return GR_DIMENSION_NONE;
  }
  
  GrUnit
@@ -137,7 +139,7 @@
          int i;
          const char *nu;
  
-         for (i = 0; i < G_N_ELEMENTS (units); i++) {
+         for (i = 1; i < G_N_ELEMENTS (units); i++) {
                  nu = g_dpgettext2 (NULL, "unit name", units[i].display_name);
                  if (g_str_has_prefix (*input, nu) && space_or_nul ((*input)[strlen (nu)])) {
                          *input += strlen (nu);
@@ -145,7 +147,7 @@
                  }
          }
  
-         for (i = 0; i < G_N_ELEMENTS (units); i++) {
+         for (i = 1; i < G_N_ELEMENTS (units); i++) {
                  nu = g_dpgettext2 (NULL, "unit abbreviation", units[i].abbreviation);
                  if (g_str_has_prefix (*input, nu) && space_or_nul ((*input)[strlen (nu)])) {
                          *input += strlen (nu);
@@ -153,7 +155,7 @@
                  }
          }
  
-         for (i = 0; i < G_N_ELEMENTS (units); i++) {
+         for (i = 1; i < G_N_ELEMENTS (units); i++) {
                  nu = units[i].name;
                  if (g_str_has_prefix (*input, nu) && space_or_nul ((*input)[strlen (nu)])) {
                          *input += strlen (nu);
diff --git a/src/gr-unit.h b/src/gr-unit.h
index c75a957..f2089bf 100644
--- a/src/gr-unit.h
+++ b/src/gr-unit.h
@@ -24,6 +24,8 @@
  
  typedef enum {
          GR_UNIT_UNKNOWN,
+         GR_UNIT_NONE,
+         GR_UNIT_NUMBER,
          GR_UNIT_GRAM,
          GR_UNIT_KILOGRAM,
          GR_UNIT_POUND,
@@ -51,10 +53,11 @@
  } GrUnit;
  
  typedef enum {
-         GR_DIMENSION_DISCRETE,
-         GR_DIMENSION_VOLUME,
-         GR_DIMENSION_MASS,
-         GR_DIMENSION_LENGTH
+        GR_DIMENSION_NONE,
+        GR_DIMENSION_DISCRETE,
+        GR_DIMENSION_VOLUME,
+        GR_DIMENSION_MASS,
+        GR_DIMENSION_LENGTH
  } GrDimension;
  
  GrUnit       gr_unit_parse (char   **string,
@@ -68,4 +71,4 @@
  GrDimension  gr_unit_get_dimension (GrUnit unit);
  
  G_END_DECLS
- 
\ No newline at end of file
+ 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]