Re: [PATCHv2 2/5] Add functions dealing with control characters in strings

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

 



On Wed, Apr 15, 2015 at 12:00:51PM +0200, Peter Krempa wrote:
> On Tue, Apr 14, 2015 at 13:28:47 +0200, Ján Tomko wrote:
> > Add virStringHasControlChars that checks if the string has
> > any control characters other than \t\r\n,
> > and virStringStripControlChars that removes them in-place.
> > ---
> >  src/libvirt_private.syms |  2 ++
> >  src/util/virstring.c     | 39 +++++++++++++++++++++++++++++++++++++++
> >  src/util/virstring.h     |  2 ++
> >  tests/virstringtest.c    | 39 +++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 82 insertions(+)

> > +
> > +bool
> > +virStringHasControlChars(const char *str)
> > +{
> > +    if (!str)
> > +        return false;
> > +
> > +    return strcspn(str, control_chars) != strlen(str);
> > +}

> > + */
> > +void
> > +virStringStripControlChars(char *str)
> > +{
> > +    size_t len, i, j;
> > +
> > +    if (!virStringHasControlChars(str))
> > +        return;
> 
> The check above calls strlen and iterates through the string looking for
> the characters.

Right, the check can do just:
  return str[strcspn(str, control_chars)] != '\0';

Jan

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]