From e7e022a05aa37c605108a4a83bf1d7e297e985b6 Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Mon, 25 Apr 2011 14:47:16 +0200 Subject: [PATCH] did you actually mean PSYC_MODIFIER_NEED_LENGTH ? --- src/match.c | 5 +++++ src/psyc.c | 6 +++--- src/render.c | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/match.c b/src/match.c index 9cd79d0..4e7e3ff 100644 --- a/src/match.c +++ b/src/match.c @@ -2,6 +2,11 @@ int PSYC_inherits(char* sho, size_t slen, 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 (!llen) llen = strlen(lon); diff --git a/src/psyc.c b/src/psyc.c index 6aec5e1..a3942bf 100644 --- a/src/psyc.c +++ b/src/psyc.c @@ -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 (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)) - m.flag = PSYC_PACKET_NEED_LENGTH; + m.flag = PSYC_MODIFIER_NEED_LENGTH; else - m.flag = PSYC_PACKET_NO_LENGTH; + m.flag = PSYC_MODIFIER_NO_LENGTH; } return m; diff --git a/src/render.c b/src/render.c index bcf9d7f..4a148f4 100644 --- a/src/render.c +++ b/src/render.c @@ -5,17 +5,17 @@ inline int PSYC_renderModifier(PSYC_Modifier *m, char *buffer) { int cur = 0; - memcpy(buffer + cur++, &m->oper, 1); + buffer[cur++] = m->oper; memcpy(buffer + cur, m->name.ptr, m->name.length); cur += m->name.length; if (m->flag == PSYC_MODIFIER_NEED_LENGTH) { - memcpy(buffer + cur++, " ", 1); + buffer[cur++] = ' '; cur += sprintf(buffer + cur, "%ld", m->value.length); } memcpy(buffer + cur, m->value.ptr, m->value.length); cur += m->value.length; - memcpy(buffer + cur++, "\n", 1); + buffer[cur++] = '\n'; 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) cur += sprintf(buffer + cur, "%ld", packet->contentLength); - memcpy(buffer + cur++, "\n", 1); + buffer[cur++] = '\n'; for (i = 0; i < packet->entity.length; i++) cur += PSYC_renderModifier(&packet->entity.ptr[i], buffer + cur);