tags must be preceeded by whitespace or start at the beginning of the record
#define RECORDS_PER_SEGMENT 65536
#define MAX_RECORD_SIZE 65535 /* No greater than 65535 */
+#define MAX_TAG_LENGTH 64
+#define MAX_TAGS_PER_RECORD 1024
+
#endif //_CONFIG_H
#include "util.h"
#include "config.h"
-#define MAX_TAG_LENGTH 64
-#define MAX_TAGS 1024
-
#define TAG_CHAR(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
+#define WHITESPACE(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r')
int tag_scan(const char *author, const char *data, int len, uint64_t record) {
- char *taglist[MAX_TAGS];
+ char *taglist[MAX_TAGS_PER_RECORD];
+ char last_char = ' ';
int n_tags = 0;
int i, j;
for (i = 0; i < len; i++) {
tag_scan_start:
- if (data[i] == '#' || data[i] == '@') {
- if (n_tags == MAX_TAGS) {
+ if (WHITESPACE(last_char) && (data[i] == '#' || data[i] == '@')) {
+ if (n_tags == MAX_TAGS_PER_RECORD) {
fprintf(stderr, "Too many tags in message\n");
break;
}
if (!strncmp(tag, taglist[j], MAX_TAG_LENGTH)) {
// We already have this tag. Start over.
free(tag);
+ last_char = data[i-1];
goto tag_scan_start;
}
}
taglist[n_tags] = tag;
n_tags++;
+ last_char = data[i-1];
// We goto here so i doesn't get incremented
goto tag_scan_start;
}
+ last_char = data[i];
}
for (i = 0; i < n_tags; i++) {