summaryrefslogtreecommitdiff
path: root/appl/lib/convcs/utf8_btos.b
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /appl/lib/convcs/utf8_btos.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/lib/convcs/utf8_btos.b')
-rw-r--r--appl/lib/convcs/utf8_btos.b35
1 files changed, 35 insertions, 0 deletions
diff --git a/appl/lib/convcs/utf8_btos.b b/appl/lib/convcs/utf8_btos.b
new file mode 100644
index 00000000..7ed10ddd
--- /dev/null
+++ b/appl/lib/convcs/utf8_btos.b
@@ -0,0 +1,35 @@
+implement Btos;
+
+include "sys.m";
+include "convcs.m";
+
+sys : Sys;
+
+init(nil : string) : string
+{
+ sys = load Sys Sys->PATH;
+ return nil;
+}
+
+btos(nil : Convcs->State, b : array of byte, n : int) : (Convcs->State, string, int)
+{
+ nbytes := 0;
+ str := "";
+
+ if (n == -1) {
+ # gather as much as possible
+ nbytes = sys->utfbytes(b, len b);
+ if (nbytes > 0)
+ str = string b[:nbytes];
+ } else {
+ for (; nbytes < len b && len str < n;) {
+ (ch, l, s) := sys->byte2char(b, nbytes);
+ if (l > 0) {
+ str[len str] = ch;
+ nbytes += l;
+ } else
+ break;
+ }
+ }
+ return (nil, str, nbytes);
+}