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

Re: [Libvir] [PATCH] Enhance virBuffer code



On Thu, Dec 13, 2007 at 11:21:31PM +0100, Jim Meyering wrote:
> "Richard W.M. Jones" <rjones redhat com> wrote:
> ...
> > + * virBufferURIEncodeString:
> > + * @buf:  the buffer to append to
> > + * @str:  the string argument which will be URI-encoded
> > + *
> > + * Append the string to the buffer.  The string will be URI-encoded
> > + * during the append (ie any non alpha-numeric characters are replaced
> > + * with '%xx' hex sequences).
> > + *
> > + * Returns 0 successful, -1 in case of internal or API error.
> > + */
> > +int
> > +virBufferURIEncodeString (virBufferPtr buf, const char *str)
> > +{
> > +    int grow_size = 0;
> > +    const char *p;
> > +    unsigned char uc;
> > +    const char *hex = "0123456789abcdef";
> > +
> > +    for (p = str; *p; ++p) {
> > +        /* Want to leave only strict 7 bit ASCII alphanumerics ... */
> > +        if ((*p >= '0' && *p <= '9') ||
> > +            (*p >= 'a' && *p <= 'z') ||
> > +            (*p >= 'A' && *p <= 'Z'))
> ...
> > +    for (p = str; *p; ++p) {
> > +        if ((*p >= '0' && *p <= '9') ||
> > +            (*p >= 'a' && *p <= 'z') ||
> > +            (*p >= 'A' && *p <= 'Z'))
> 
> Hi Rich,
> 
> What do you think of using this?
> 
>   isascii (*p) && isalnum (*p)

  I have learned to be very cautious of the is* macros because they
tend to be local dependant whichis usually really not what you would
like or expect. In that case this may work, but explicit ranges
are 100% clear about what you intend to accept or not, that's why I 
usually prefer them.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


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