aboutsummaryrefslogtreecommitdiffstats
path: root/skeletons/UTF8String.c
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2004-10-23 11:20:06 +0000
committerLev Walkin <vlm@lionet.info>2004-10-23 11:20:06 +0000
commit9a6f65b2a18219811d38b6e4ba8a2ddb567dca53 (patch)
tree2a5606d66477dd2d58594c14bf7f1a94f15d6137 /skeletons/UTF8String.c
parent36b8b8270318e3d814c8092f75fb900bf8721850 (diff)
XER decoding support
Diffstat (limited to 'skeletons/UTF8String.c')
-rw-r--r--skeletons/UTF8String.c98
1 files changed, 58 insertions, 40 deletions
diff --git a/skeletons/UTF8String.c b/skeletons/UTF8String.c
index 1c0c731d..0a47f459 100644
--- a/skeletons/UTF8String.c
+++ b/skeletons/UTF8String.c
@@ -96,54 +96,72 @@ UTF8String_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
return (len < 0) ? -1 : 0;
}
-ssize_t
-UTF8String_length(const UTF8String_t *st) {
+static ssize_t
+UTF8String__process(const UTF8String_t *st, uint32_t *dst, size_t dstlen) {
+ size_t length;
+ uint8_t *buf = st->buf;
+ uint8_t *end = buf + st->size;
- if(st && st->buf) {
- size_t length;
- uint8_t *buf = st->buf;
- uint8_t *end = buf + st->size;
-
- for(length = 0; buf < end; length++) {
- int ch = *buf;
- uint8_t *cend;
- int32_t value;
- int want;
-
- /* Compute the sequence length */
- want = UTF8String_ht[0][ch >> 4];
- switch(want) {
- case -1:
- /* Second half of the table, long sequence */
- want = UTF8String_ht[1][ch & 0x0F];
- if(want != -1) break;
- /* Fall through */
- case 0:
- return U8E_ILLSTART;
- }
-
- /* assert(want >= 1 && want <= 6) */
-
- /* Check character sequence length */
- if(buf + want > end) return U8E_TRUNC;
-
- value = ch & (0xff >> (want + 1));
- cend = buf + want;
- for(buf++; buf < cend; buf++) {
- ch = *buf;
- if(ch < 0x80 || ch > 0xbf) return U8E_NOTCONT;
- value = (value << 6) | (ch & 0x3F);
- }
- if(value < UTF8String_mv[want])
- return U8E_NOTMIN;
+ for(length = 0; buf < end; length++) {
+ int ch = *buf;
+ uint8_t *cend;
+ int32_t value;
+ int want;
+
+ /* Compute the sequence length */
+ want = UTF8String_ht[0][ch >> 4];
+ switch(want) {
+ case -1:
+ /* Second half of the table, long sequence */
+ want = UTF8String_ht[1][ch & 0x0F];
+ if(want != -1) break;
+ /* Fall through */
+ case 0:
+ return U8E_ILLSTART;
}
- return length;
+ /* assert(want >= 1 && want <= 6) */
+
+ /* Check character sequence length */
+ if(buf + want > end) return U8E_TRUNC;
+
+ value = ch & (0xff >> (want + 1));
+ cend = buf + want;
+ for(buf++; buf < cend; buf++) {
+ ch = *buf;
+ if(ch < 0x80 || ch > 0xbf) return U8E_NOTCONT;
+ value = (value << 6) | (ch & 0x3F);
+ }
+ if(value < UTF8String_mv[want])
+ return U8E_NOTMIN;
+ if(dstlen) *dst++ = value; /* Record value */
+ }
+
+ if(dstlen) *dst = 0; /* zero-terminate */
+
+ return length;
+}
+
+
+ssize_t
+UTF8String_length(const UTF8String_t *st) {
+ if(st && st->buf) {
+ return UTF8String__process(st, 0, 0);
} else {
return U8E_EINVAL;
}
}
+size_t
+UTF8String_to_wcs(const UTF8String_t *st, uint32_t *dst, size_t dstlen) {
+ if(st && st->buf) {
+ ssize_t ret = UTF8String__process(st, dst, dstlen);
+ return (ret < 0) ? 0 : ret;
+ } else {
+ return 0;
+ }
+}
+
int
UTF8String_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {