notes: count words in notes during artifact parsing

This commit is contained in:
William Casarin
2023-06-01 11:45:04 -07:00
parent fe077fa5c2
commit 6ca9bda01e
6 changed files with 28 additions and 13 deletions

View File

@@ -46,6 +46,7 @@ typedef struct note_block {
} block_t;
typedef struct note_blocks {
int words;
int num_blocks;
struct note_block *blocks;
} blocks_t;

View File

@@ -216,6 +216,7 @@ int damus_parse_content(struct note_blocks *blocks, const char *content) {
struct note_block block;
u8 *start, *pre_mention;
blocks->words = 0;
blocks->num_blocks = 0;
make_cursor((u8*)content, (u8*)content + strlen(content), &cur);
@@ -224,6 +225,11 @@ int damus_parse_content(struct note_blocks *blocks, const char *content) {
cp = peek_char(&cur, -1);
c = peek_char(&cur, 0);
// new word
if (is_whitespace(cp) && !is_whitespace(c)) {
blocks->words++;
}
pre_mention = cur.p;
if (cp == -1 || is_whitespace(cp) || c == '#') {
if (c == '#' && (parse_mention_index(&cur, &block) || parse_hashtag(&cur, &block))) {