pike.git/
src/
stralloc.c
Branch:
Tag:
Non-build tags
All tags
No tags
2010-05-28
2010-05-28 17:37:52 by Martin Stjernholm <mast@lysator.liu.se>
abeaca3a295f3c0b82db8f78e3dc50ef1e760124 (
40
lines) (+
39
/-
1
)
[
Show
|
Annotate
]
Branch:
7.9
Added string_builder_putchars.
Rev: src/stralloc.c:1.238
Rev: src/stralloc.h:1.112
2:
|| This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: stralloc.c,v 1.
237
2009
/
11
/
30
10
:
08
:
24
grubba
Exp $
+
|| $Id: stralloc.c,v 1.
238
2010
/
05
/
28
17
:
37
:
52
mast
Exp $
*/ #include "global.h"
2330:
s->s->str[s->s->len << s->s->size_shift] = 0; }
+
PMOD_EXPORT void string_builder_putchars(struct string_builder *s, int ch,
+
ptrdiff_t count)
+
{
+
ptrdiff_t len = s->s->len;
+
int mag = min_magnitude(ch);
-
+
if (mag > s->s->size_shift) {
+
string_build_mkspace(s, count, mag);
+
s->known_shift = mag;
+
} else if (((size_t)s->s->len) >= ((size_t)s->malloced)) {
+
string_build_mkspace(s, count, mag);
+
s->known_shift = MAXIMUM(mag, s->known_shift);
+
}
+
+
switch (s->s->size_shift) {
+
case 0:
+
MEMSET (STR0 (s->s) + s->s->len, ch, count);
+
break;
+
case 1: {
+
int i;
+
for (i = 0; i < count; i++)
+
(STR1 (s->s) + s->s->len)[i] = ch;
+
break;
+
}
+
case 2: {
+
int i;
+
for (i = 0; i < count; i++)
+
(STR2 (s->s) + s->s->len)[i] = ch;
+
break;
+
}
+
}
+
+
s->s->len += count;
+
/* Ensure NUL-termination */
+
s->s->str[s->s->len << s->s->size_shift] = 0;
+
}
+
+
PMOD_EXPORT void string_builder_binary_strcat0(struct string_builder *s, const p_wchar0 *str, ptrdiff_t len) {