]> mj.ucw.cz Git - libucw.git/blobdiff - charset/stk-charconv.c
Opt: Constify
[libucw.git] / charset / stk-charconv.c
index 10af721180478165c5947ae189f62fa3748eb034..e296c73bcfa04a8eec59c6fdb1df2f38fd60bd9b 100644 (file)
@@ -1,60 +1,60 @@
 /*
 /*
- *     Sherlock Library -- Character Conversion with Allocation on the Stack 
+ *     Sherlock Library -- Character Conversion with Allocation on the Stack
  *
  *     (c) 2006 Pavel Charvat <pchar@ucw.cz>
  *
  *     (c) 2006 Pavel Charvat <pchar@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
  */
 
-#include "lib/lib.h"
-#include "charset/stk-charconv.h"
+#include <ucw/lib.h>
+#include <charset/stk-charconv.h>
 #include <string.h>
 
 #define INITIAL_MIN_SIZE       16
 #define INITIAL_SCALE          2
 
 #include <string.h>
 
 #define INITIAL_MIN_SIZE       16
 #define INITIAL_SCALE          2
 
-void
-stk_conv_init(struct stk_conv_context *c, byte *s, uns in_cs, uns out_cs)
+uint
+stk_strconv_init(struct conv_context *c, const byte *s, uint in_cs, uint out_cs)
 {
 {
-  uns l = strlen(s);
+  uint l = strlen(s);
   if (in_cs == out_cs)
   {
   if (in_cs == out_cs)
   {
-    c->c.source = s;
-    c->c.source_end = NULL;
-    c->len = l + 1;
-    return;
+    c->source = s;
+    c->source_end = NULL;
+    return l + 1;
   }
   }
-  conv_init(&c->c);
-  conv_set_charset(&c->c, in_cs, out_cs);
-  c->c.source = s;
-  c->c.source_end = s + l + 1;
+  conv_init(c);
+  conv_set_charset(c, in_cs, out_cs);
+  c->source = s;
+  c->source_end = s + l + 1;
   if (l < (INITIAL_MIN_SIZE - 1) / INITIAL_SCALE)
   if (l < (INITIAL_MIN_SIZE - 1) / INITIAL_SCALE)
-    c->len = INITIAL_MIN_SIZE;
+    return INITIAL_MIN_SIZE;
   else
   else
-    c->len = l * INITIAL_SCALE + 1;
-  c->len = 1;
+    return l * INITIAL_SCALE + 1;
 }
 
 }
 
-int
-stk_conv_step(struct stk_conv_context *c, byte *buf)
+uint
+stk_strconv_step(struct conv_context *c, byte *buf, uint len)
 {
 {
-  if (!c->c.source_end)
+  if (!c->source_end)
   {
   {
-    memcpy(buf, c->c.source, c->len);
-    c->c.dest_start = buf;
+    memcpy(buf, c->source, len);
+    c->dest_start = buf;
     return 0;
   }
     return 0;
   }
-  if (c->c.dest_start)
+  if (c->dest_start)
   {
   {
-    uns l = c->c.dest_end - c->c.dest_start;
-    memcpy(buf, c->c.dest_start, l);
-    c->c.dest = buf + l;
+    uint l = c->dest_end - c->dest_start;
+    memcpy(buf, c->dest_start, l);
+    c->dest = buf + l;
   }
   else
   }
   else
-    c->c.dest = buf;
-  c->c.dest_start = buf;
-  c->c.dest_end = buf + c->len;
-  if ((conv_run(&c->c) & CONV_SOURCE_END))
+    c->dest = buf;
+  c->dest_start = buf;
+  c->dest_end = buf + len;
+  if (conv_run(c) & CONV_SOURCE_END)
     return 0;
     return 0;
-  c->len <<= 1;
-  return 1;
+  return len << 1;
 }
 
 }