dynamic-string: Make ds_chomp() return true if it removed a character.
authorBen Pfaff <blp@ovn.org>
Wed, 10 Feb 2016 04:54:03 +0000 (20:54 -0800)
committerBen Pfaff <blp@ovn.org>
Fri, 19 Feb 2016 08:02:16 +0000 (00:02 -0800)
This will be used in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
lib/dynamic-string.c
lib/dynamic-string.h

index a6c8f6c..a5a3460 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -446,10 +446,13 @@ ds_last(const struct ds *ds)
     return ds->length > 0 ? (unsigned char) ds->string[ds->length - 1] : EOF;
 }
 
-void
+bool
 ds_chomp(struct ds *ds, int c)
 {
     if (ds->length > 0 && ds->string[ds->length - 1] == (char) c) {
         ds->string[--ds->length] = '\0';
+        return true;
+    } else {
+        return false;
     }
 }
index f1e0a36..cc064c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -73,7 +73,7 @@ void ds_destroy(struct ds *);
 void ds_swap(struct ds *, struct ds *);
 
 int ds_last(const struct ds *);
-void ds_chomp(struct ds *, int c);
+bool ds_chomp(struct ds *, int c);
 \f
 /* Inline functions. */