qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] util/uri: Remove is_hex() function
@ 2024-01-12  5:17 Thomas Huth
  2024-01-12  6:35 ` Markus Armbruster
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2024-01-12  5:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, qemu-trivial, Thomas Huth

We can simply use the g_ascii_isxdigit() from the glib instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 util/uri.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/util/uri.c b/util/uri.c
index dcb3305236..7411c5ba14 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -1561,15 +1561,6 @@ done_cd:
     return 0;
 }
 
-static int is_hex(char c)
-{
-    if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
-        ((c >= 'A') && (c <= 'F'))) {
-        return 1;
-    }
-    return 0;
-}
-
 /**
  * uri_string_unescape:
  * @str:  the string to unescape
@@ -1607,7 +1598,7 @@ char *uri_string_unescape(const char *str, int len, char *target)
     in = str;
     out = ret;
     while (len > 0) {
-        if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
+        if (len > 2 && *in == '%' && g_ascii_isxdigit(in[1]) && g_ascii_isxdigit(in[2])) {
             in++;
             if ((*in >= '0') && (*in <= '9')) {
                 *out = (*in - '0');
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] util/uri: Remove is_hex() function
  2024-01-12  5:17 [PATCH] util/uri: Remove is_hex() function Thomas Huth
@ 2024-01-12  6:35 ` Markus Armbruster
  2024-01-12  7:19   ` Stefan Weil via
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2024-01-12  6:35 UTC (permalink / raw)
  To: Thomas Huth; +Cc: qemu-devel, Paolo Bonzini, qemu-trivial

Thomas Huth <thuth@redhat.com> writes:

> We can simply use the g_ascii_isxdigit() from the glib instead.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  util/uri.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)
>
> diff --git a/util/uri.c b/util/uri.c
> index dcb3305236..7411c5ba14 100644
> --- a/util/uri.c
> +++ b/util/uri.c
> @@ -1561,15 +1561,6 @@ done_cd:
>      return 0;
>  }
>  
> -static int is_hex(char c)
> -{
> -    if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
> -        ((c >= 'A') && (c <= 'F'))) {
> -        return 1;
> -    }
> -    return 0;
> -}
> -
>  /**
>   * uri_string_unescape:
>   * @str:  the string to unescape
> @@ -1607,7 +1598,7 @@ char *uri_string_unescape(const char *str, int len, char *target)
>      in = str;
>      out = ret;
>      while (len > 0) {
> -        if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
> +        if (len > 2 && *in == '%' && g_ascii_isxdigit(in[1]) && g_ascii_isxdigit(in[2])) {
>              in++;
>              if ((*in >= '0') && (*in <= '9')) {
>                  *out = (*in - '0');

Suggest to replace *in by in[0] while there, for symmetry.

Long line, easy to break:

           if (len > 2 && in[0] == '%'
               && g_ascii_isxdigit(in[1])
               && g_ascii_isxdigit(in[2])) {



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] util/uri: Remove is_hex() function
  2024-01-12  6:35 ` Markus Armbruster
@ 2024-01-12  7:19   ` Stefan Weil via
  2024-01-17 13:54     ` Thomas Huth
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Weil via @ 2024-01-12  7:19 UTC (permalink / raw)
  To: Markus Armbruster, Thomas Huth; +Cc: qemu-devel, Paolo Bonzini, qemu-trivial



Am 12.01.24 um 07:35 schrieb Markus Armbruster:
> Thomas Huth <thuth@redhat.com> writes:
> 
>> We can simply use the g_ascii_isxdigit() from the glib instead.

... or even use unescape_string() from the glib?

https://docs.gtk.org/glib/type_func.Uri.unescape_string.html

Regards,
Stefan


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] util/uri: Remove is_hex() function
  2024-01-12  7:19   ` Stefan Weil via
@ 2024-01-17 13:54     ` Thomas Huth
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2024-01-17 13:54 UTC (permalink / raw)
  To: Stefan Weil, Markus Armbruster; +Cc: qemu-devel, Paolo Bonzini, qemu-trivial

On 12/01/2024 08.19, Stefan Weil via wrote:
> 
> 
> Am 12.01.24 um 07:35 schrieb Markus Armbruster:
>> Thomas Huth <thuth@redhat.com> writes:
>>
>>> We can simply use the g_ascii_isxdigit() from the glib instead.
> 
> ... or even use unescape_string() from the glib?
> 
> https://docs.gtk.org/glib/type_func.Uri.unescape_string.html

Thanks, that sounds like an interesting idea! I'll give it a try when I've 
got some spare time... not within the next days, though, so if you'd like to 
have a try instead, let me know!

  Thomas



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-17 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12  5:17 [PATCH] util/uri: Remove is_hex() function Thomas Huth
2024-01-12  6:35 ` Markus Armbruster
2024-01-12  7:19   ` Stefan Weil via
2024-01-17 13:54     ` Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).