1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

did you actually mean PSYC_MODIFIER_NEED_LENGTH ?

This commit is contained in:
psyc://psyced.org/~lynX 2011-04-25 14:47:16 +02:00
parent 5a1e4825ad
commit 9946307d00
3 changed files with 12 additions and 7 deletions

View file

@ -2,6 +2,11 @@
int PSYC_inherits(char* sho, size_t slen, int PSYC_inherits(char* sho, size_t slen,
char* lon, size_t llen) { char* lon, size_t llen) {
// this allows to pass zero-terminated strings instead of providing
// the length.. but we would be faster here if we expected the callee
// to always use the PSYC_C2ARG() macro instead. additionally, the
// empty string would then be fully supported (in case you want that)
if (!slen) slen = strlen(sho); if (!slen) slen = strlen(sho);
if (!llen) llen = strlen(lon); if (!llen) llen = strlen(lon);

View file

@ -17,11 +17,11 @@ inline PSYC_Modifier PSYC_newModifier(char oper, PSYC_String *name, PSYC_String
if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length
{ {
if (value->length > PSYC_MODIFIER_SIZE_THRESHOLD) if (value->length > PSYC_MODIFIER_SIZE_THRESHOLD)
m.flag = PSYC_PACKET_NEED_LENGTH; m.flag = PSYC_MODIFIER_NEED_LENGTH;
else if (memchr(value->ptr, (int)'\n', value->length)) else if (memchr(value->ptr, (int)'\n', value->length))
m.flag = PSYC_PACKET_NEED_LENGTH; m.flag = PSYC_MODIFIER_NEED_LENGTH;
else else
m.flag = PSYC_PACKET_NO_LENGTH; m.flag = PSYC_MODIFIER_NO_LENGTH;
} }
return m; return m;

View file

@ -5,17 +5,17 @@ inline int PSYC_renderModifier(PSYC_Modifier *m, char *buffer)
{ {
int cur = 0; int cur = 0;
memcpy(buffer + cur++, &m->oper, 1); buffer[cur++] = m->oper;
memcpy(buffer + cur, m->name.ptr, m->name.length); memcpy(buffer + cur, m->name.ptr, m->name.length);
cur += m->name.length; cur += m->name.length;
if (m->flag == PSYC_MODIFIER_NEED_LENGTH) if (m->flag == PSYC_MODIFIER_NEED_LENGTH)
{ {
memcpy(buffer + cur++, " ", 1); buffer[cur++] = ' ';
cur += sprintf(buffer + cur, "%ld", m->value.length); cur += sprintf(buffer + cur, "%ld", m->value.length);
} }
memcpy(buffer + cur, m->value.ptr, m->value.length); memcpy(buffer + cur, m->value.ptr, m->value.length);
cur += m->value.length; cur += m->value.length;
memcpy(buffer + cur++, "\n", 1); buffer[cur++] = '\n';
return cur; return cur;
} }
@ -33,7 +33,7 @@ PSYC_RenderRC PSYC_render(PSYC_Packet *packet, char *buffer, size_t buflen)
if (packet->flag == PSYC_PACKET_NEED_LENGTH) if (packet->flag == PSYC_PACKET_NEED_LENGTH)
cur += sprintf(buffer + cur, "%ld", packet->contentLength); cur += sprintf(buffer + cur, "%ld", packet->contentLength);
memcpy(buffer + cur++, "\n", 1); buffer[cur++] = '\n';
for (i = 0; i < packet->entity.length; i++) for (i = 0; i < packet->entity.length; i++)
cur += PSYC_renderModifier(&packet->entity.ptr[i], buffer + cur); cur += PSYC_renderModifier(&packet->entity.ptr[i], buffer + cur);