2 ** Copyright 2011 Double Precision, Inc.
3 ** See COPYING for distribution information.
7 #include "unicode_config.h"
12 void unicode_buf_init(struct unicode_buf
*p
, size_t max
)
20 void unicode_buf_deinit(struct unicode_buf
*p
)
26 int unicode_buf_append(struct unicode_buf
*p
,
27 const unicode_char
*uc
, size_t l
)
29 if (l
> p
->max
-p
->len
)
32 if (p
->len
+ l
> p
->size
)
34 size_t n
=(p
->len
+ l
) * 2;
43 newp
=p
->ptr
? realloc(p
->ptr
, n
* sizeof(unicode_char
))
44 : malloc(n
* sizeof(unicode_char
));
53 memcpy(p
->ptr
+ p
->len
, uc
, l
* sizeof(unicode_char
));
59 void unicode_buf_append_char(struct unicode_buf
*dst
,
63 unicode_char unicode_buf
[256];
67 size_t n
=sizeof(unicode_buf
)/sizeof(unicode_buf
[0]), i
;
73 unicode_buf
[i
]=(unsigned char)str
[i
];
77 unicode_buf_append(dst
, unicode_buf
, i
);
81 void unicode_buf_remove(struct unicode_buf
*p
,
92 memmove(p
->ptr
+pos
+cnt
, p
->ptr
+pos
, p
->len
-pos
-cnt
);
96 int unicode_buf_cmp(const struct unicode_buf
*a
,
97 const struct unicode_buf
*b
)
101 for (i
=0; i
<a
->len
&& i
<b
->len
; i
++)
103 if (a
->ptr
[i
] < b
->ptr
[i
])
105 if (a
->ptr
[i
] > b
->ptr
[i
])
109 return (a
->len
< b
->len
? -1:a
->len
> b
->len
? 1:0);
112 int unicode_buf_cmp_str(const struct unicode_buf
*p
, const char *c
,
117 for (i
=0; i
<p
->len
&& i
< cl
; ++i
)
119 if (p
->ptr
[i
] < c
[i
])
122 if (p
->ptr
[i
] > c
[i
])
126 return (p
->len
< cl
? -1: p
->len
> cl
? 1:0);