[Libguestfs] [PATCH v4 4/6] mllib: modify nsplit to take optional noempty and count arguments

Tomas Golembiovsky tgolembi at redhat.com
Tue Jan 3 12:04:46 UTC 2017


On Thu, 22 Dec 2016 18:35:24 +0100
Pino Toscano <ptoscano at redhat.com> wrote:

> On Sunday, 18 December 2016 23:16:31 CET Tomáš Golembiovský wrote:
> > Added two new optional arguments to nsplit:
> >
> > * noempty: if set to false empty elements are not stored in the returned
> >   list. The default is to keep the empty elements
> >
> > * count: specifies how many splits to perform; negative count
> >   (the default) means do as many splits as possible
> >
> > Added tests for nsplit.
> >
> > Signed-off-by: Tomáš Golembiovský <tgolembi at redhat.com>
> > ---
> >  mllib/common_utils.ml       | 12 +++++++++---
> >  mllib/common_utils.mli      | 12 ++++++++++--
> >  mllib/common_utils_tests.ml | 26 ++++++++++++++++++++++++++
> >  3 files changed, 45 insertions(+), 5 deletions(-)
> >
> > diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
> > index f948dce..b6f3046 100644
> > --- a/mllib/common_utils.ml
> > +++ b/mllib/common_utils.ml
> > @@ -130,15 +130,21 @@ module String = struct
> >        done;
> >        if not !r then s else Bytes.to_string b2
> >  
> > -    let rec nsplit sep str =
> > +    let rec nsplit ?(noempty = true) ?(count = -1) sep str =  
>
> Shouldn't the default value of noempty be false, matching the current
> behaviour, and the documentation added?

It seems I managed to confuse myself about what noempty actually means
(keep or drop). It's more than obvious from the fact that the
description in commit message does not match the documentation. 

I will rename the argument to keep_empty to make it more clear.

    Tomas

-- 
Tomáš Golembiovský <tgolembi at redhat.com>




More information about the Libguestfs mailing list