poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] base64.pk: use chrstr from the standard library


From: Jose E. Marchesi
Subject: [COMMITTED] base64.pk: use chrstr from the standard library
Date: Sat, 28 Oct 2023 16:30:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Instead of its own implementation as before.

2023-10-28  Jose E. Marchesi  <jemarch@gnu.org>

        * pickles/base64.pk: Use std's strchr.
---
 ChangeLog         |  4 ++++
 pickles/base64.pk | 16 +---------------
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fd1cbf65..10dfdcbc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2023-10-28  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * pickles/base64.pk: Use std's strchr.
+
 2023-10-28  Jose E. Marchesi  <jemarch@gnu.org>
 
        * libpoke/std.pk (strstr): New function.
diff --git a/pickles/base64.pk b/pickles/base64.pk
index 12046f1c..b35718d2 100644
--- a/pickles/base64.pk
+++ b/pickles/base64.pk
@@ -103,20 +103,6 @@ fun base64_encode = (uint<8>[] src) string:
 
 fun base64_decode = (string src) uint<8>[]:
 {
-  /* XXX move strchr to std  */
-  fun strchr = (string s, uint<8> c) uint<32>:
-  {
-    var res = 0UL;
-    for (t in s)
-      {
-        if (t == c)
-          return res;
-        res += 1;
-      }
-
-    return -1;
-  }
-
   fun invalid_input = (string cause, int<32> position) void:
   {
     raise Exception { code = EC_inval,
@@ -148,7 +134,7 @@ fun base64_decode = (string src) uint<8>[]:
 
       var pos = strchr (base64_chars, ch);
 
-      if (pos == -1) /* A non-base64 character.  */
+      if (pos == base64_chars'length) /* A non-base64 character.  */
         invalid_input ("non-base64 character passed to base_64_decode", s - 1);
 
       if (state == 0)
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]