summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@redhat.com>2016-11-10 13:06:50 +0100
committerDodji Seketeli <dodji@redhat.com>2016-11-10 14:09:51 +0100
commitf9ed75b8c4105a420bbef173e78c577cdc166829 (patch)
treec03eb6468c06e08e4322b909e9462711f659d956
parentRename config::property_vector into config::properties_type (diff)
downloadlibabigail-f9ed75b8c4105a420bbef173e78c577cdc166829.tar.gz
libabigail-f9ed75b8c4105a420bbef173e78c577cdc166829.tar.bz2
libabigail-f9ed75b8c4105a420bbef173e78c577cdc166829.tar.xz
Support empty properties in INI files
The ini file parser doesn't support parsing properties with no value. This patch adds that feature, as it turned out to be a pre-requisite for reading Linux Kernel ABI whitelist files. * include/abg-ini.h (simple_property::simple_property): Add a new constructor for empty values. (simple_property::has_empty_value): Declare new member function. * src/abg-ini.cc (simple_property::{simple_property, has_empty_value}): Define new member functions. (read_context::read_property): Support reading a property with no value. (write_property_value, write_property): Support writting a property with empty value. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
-rw-r--r--include/abg-ini.h5
-rw-r--r--src/abg-ini.cc54
2 files changed, 50 insertions, 9 deletions
diff --git a/include/abg-ini.h b/include/abg-ini.h
index e8ecb91d..bd4ed520 100644
--- a/include/abg-ini.h
+++ b/include/abg-ini.h
@@ -244,12 +244,17 @@ public:
244 simple_property(const string& name, 244 simple_property(const string& name,
245 const string_property_value_sptr& value); 245 const string_property_value_sptr& value);
246 246
247 simple_property(const string& name);
248
247 const string_property_value_sptr& 249 const string_property_value_sptr&
248 get_value() const; 250 get_value() const;
249 251
250 void 252 void
251 set_value(const string_property_value_sptr& value); 253 set_value(const string_property_value_sptr& value);
252 254
255 bool
256 has_empty_value() const;
257
253 virtual ~simple_property(); 258 virtual ~simple_property();
254}; // end class simple_property 259}; // end class simple_property
255 260
diff --git a/src/abg-ini.cc b/src/abg-ini.cc
index 2cae7890..b528d164 100644
--- a/src/abg-ini.cc
+++ b/src/abg-ini.cc
@@ -576,6 +576,16 @@ simple_property::simple_property(const string& name,
576 priv_(new priv(value)) 576 priv_(new priv(value))
577{} 577{}
578 578
579/// Constructor for the @ref simple_property type.
580///
581/// This one constructs a property with an empty value.
582///
583/// @param name the name of the property.
584simple_property::simple_property(const string& name)
585 : property(name),
586 priv_(new priv)
587{}
588
579/// Getter for the string value of the property. 589/// Getter for the string value of the property.
580/// 590///
581/// @return the string value of the property. 591/// @return the string value of the property.
@@ -590,6 +600,19 @@ void
590simple_property::set_value(const string_property_value_sptr& value) 600simple_property::set_value(const string_property_value_sptr& value)
591{priv_->value_ = value;} 601{priv_->value_ = value;}
592 602
603/// Test if the property has an empty value.
604///
605/// An empty value is either no value at all or an empty string value.
606///
607/// @return true iff the property has an empty value.
608bool
609simple_property::has_empty_value() const
610{
611 if (!priv_->value_)
612 return true;
613 return priv_->value_->as_string().empty();
614}
615
593/// Destructor of the @ref simple_property type. 616/// Destructor of the @ref simple_property type.
594simple_property::~simple_property() 617simple_property::~simple_property()
595{} 618{}
@@ -1523,14 +1546,22 @@ public:
1523 return nil; 1546 return nil;
1524 1547
1525 skip_white_spaces(); 1548 skip_white_spaces();
1526 if (!good())
1527 return nil;
1528 1549
1529 char c = 0; 1550 property_sptr result;
1530 if (!read_next_char(c) || c != '=') 1551
1531 return nil; 1552 char c = peek();
1553 if (c == '=')
1554 {
1555 assert(read_next_char(c));
1556 assert(c == '=');
1557 skip_white_spaces();
1558 }
1559 else
1560 {
1561 property_sptr empty_value_property(new simple_property(name));
1562 return empty_value_property;
1563 }
1532 1564
1533 skip_white_spaces();
1534 if (!good()) 1565 if (!good())
1535 return nil; 1566 return nil;
1536 1567
@@ -1538,7 +1569,6 @@ public:
1538 if (!value) 1569 if (!value)
1539 return nil; 1570 return nil;
1540 1571
1541 property_sptr result;
1542 if (tuple_property_value_sptr tv = is_tuple_property_value(value)) 1572 if (tuple_property_value_sptr tv = is_tuple_property_value(value))
1543 result.reset(new tuple_property(name, tv)); 1573 result.reset(new tuple_property(name, tv));
1544 else if (list_property_value_sptr lv = is_list_property_value(value)) 1574 else if (list_property_value_sptr lv = is_list_property_value(value))
@@ -1791,7 +1821,10 @@ write_property_value(const property_sptr& prop)
1791{ 1821{
1792 string result; 1822 string result;
1793 if (simple_property_sptr simple_prop = is_simple_property(prop)) 1823 if (simple_property_sptr simple_prop = is_simple_property(prop))
1794 result = simple_prop->get_value()->as_string(); 1824 {
1825 if (!simple_prop->has_empty_value())
1826 result = simple_prop->get_value()->as_string();
1827 }
1795 else if (list_property_sptr list_prop = is_list_property(prop)) 1828 else if (list_property_sptr list_prop = is_list_property(prop))
1796 result = list_prop->get_value()->as_string(); 1829 result = list_prop->get_value()->as_string();
1797 else if (tuple_property_sptr tuple_prop = is_tuple_property(prop)) 1830 else if (tuple_property_sptr tuple_prop = is_tuple_property(prop))
@@ -1813,7 +1846,10 @@ static bool
1813write_property(const property_sptr& prop, 1846write_property(const property_sptr& prop,
1814 std::ostream& out) 1847 std::ostream& out)
1815{ 1848{
1816 out << prop->get_name() << " = " << write_property_value(prop); 1849 out << prop->get_name();
1850 string value = write_property_value(prop);
1851 if (!value.empty())
1852 out << " = " << write_property_value(prop);
1817 return out.good(); 1853 return out.good();
1818} 1854}
1819 1855