Index: example.c =================================================================== --- example.c (revision 28942) +++ example.c (revision 28943) @@ -18,7 +18,7 @@ /* split and print fields */ printf("Splitting '%s':\n", s); - argc = qparse3(s, &argv, QPARSE_DOUBLE_QUOTE | QPARSE_SINGLE_QUOTE | QPARSE_TERM_SEMICOLON | QPARSE_SEP_COMMA, &cons); + argc = qparse3(s, &argv, QPARSE_DOUBLE_QUOTE | QPARSE_SINGLE_QUOTE | QPARSE_TERM_SEMICOLON | QPARSE_SEP_COMMA | QPARSE_COLON_LAST, &cons); for(n = 0; n < argc; n++) printf(" [%d] '%s'\n", n, argv[n]); qparse_free(argc, &argv); Index: qparse.c =================================================================== --- qparse.c (revision 28942) +++ qparse.c (revision 28943) @@ -26,7 +26,8 @@ qp_normal, qp_dquote, qp_squote, - qp_paren + qp_paren, + qp_lastarg } qp_state_t; #define qpush(chr) \ @@ -88,12 +89,18 @@ for(s = input; *s != '\0'; s++) { switch (state) { + case qp_lastarg: + switch (*s) { + case '\n': + case '\r': + if (flg & QPARSE_TERM_NEWLINE) + goto stop; + default: + qpush(*s); + } + break; case qp_normal: switch (*s) { - case '\\': - s++; - qbackslash(*s); - break; case '"': if (flg & QPARSE_DOUBLE_QUOTE) state = qp_dquote; @@ -113,6 +120,11 @@ qpush(*s); break; + case '\\': + s++; + qbackslash(*s); + break; + case ';': if (flg & QPARSE_TERM_SEMICOLON) goto stop; @@ -135,6 +147,10 @@ qnext(); break; default: + if ((flg & QPARSE_COLON_LAST) && (buff_used == 0) && *s == ':') { + state = qp_lastarg; + break; + } qpush(*s); } /* End of qp_normal */ Index: qparse.h =================================================================== --- qparse.h (revision 28942) +++ qparse.h (revision 28943) @@ -20,7 +20,8 @@ QPARSE_MULTISEP = 8, /* multiple separators are taken as a single separator */ QPARSE_TERM_NEWLINE = 16, /* terminate parsing at newline */ QPARSE_TERM_SEMICOLON = 32, /* terminate parsing at semicolon */ - QPARSE_SEP_COMMA = 64 /* comma is a separator, like whitespace */ + QPARSE_SEP_COMMA = 64, /* comma is a separator, like whitespace */ + QPARSE_COLON_LAST = 128 /* if an argument starts with a colon, it's the last argument until the end of the message or line (IRC) */ } flags_t; int qparse2(const char *input, char **argv_ret[], flags_t flg);