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