2 * Copyright (c) 1997, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: odr_unicode.c,v $
7 * Revision 1.1 1997-09-17 12:25:49 adam
8 * First Unicode attempt.
15 int odr_unicode(ODR o, wchar_t **p, int opt)
24 o->t_class = ODR_UNIVERSAL;
25 o->t_tag = ODR_OCTETSTRING;
27 if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
31 if (o->direction == ODR_PRINT)
33 size_t i, wlen = wcslen(*p);
34 fprintf(o->print, "%sL'", odr_indent(o));
35 for (i = 0; i < wlen; i++)
37 if ((*p)[i] > 126 || (*p)[i] == '\\')
38 fprintf (o->print, "\\%04lX", (*p)[i]);
42 fprintf (o->print, "%c", ch);
45 fprintf(o->print, "'\n");
48 t = odr_malloc(o, sizeof(Odr_oct));
49 if (o->direction == ODR_ENCODE)
51 size_t i, wlen = 1+wcslen(*p);
52 t->size = t->len = wlen*2;
53 t->buf = odr_malloc (o, t->size);
54 for (i = 0; i < wlen; i++)
56 t->buf[i*2] = (*p)[i] & 255;
57 t->buf[i*2+1] = ((*p)[i] >> 8) & 255;
66 if (!ber_octetstring(o, t, cons))
68 if (o->direction == ODR_DECODE)
70 size_t i, wlen = t->len/2;
71 *p = odr_malloc (o, wlen*sizeof(**p));
72 for (i = 0; i<wlen; i++)
73 (*p)[i] = t->buf[i*2] + (t->buf[i*2+1]<<8);