Skip to content

Commit

Permalink
Use strrchr() call to find the last '#' character
Browse files Browse the repository at this point in the history
  • Loading branch information
kovmir committed Sep 26, 2024
1 parent f8afe0f commit c4dffdc
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions swege.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ char *
get_title(FILE * in)
{
char *line = NULL;
int n_hashes;
size_t linecap = 0;
getline(&line, &linecap, in);

Expand All @@ -322,11 +321,8 @@ get_title(FILE * in)
}
}
} else if (strlen(line) >= 3 && line[0] == '#') {
/* Count the amount of '#' characters. */
for (n_hashes = 1; line[n_hashes] == '#'; n_hashes++)
;
/* Copy line without the '#' and ' ' immediately after it. */
strncpy(ret, line + n_hashes + 1, (TITLE_SIZE + 1));
strncpy(ret, strrchr(line, '#') + 1, (TITLE_SIZE + 1));
ret[TITLE_SIZE] = '\0'; /* Ensure termination */

rewind(in); /* Leave H1 in place for rendering */
Expand Down

0 comments on commit c4dffdc

Please sign in to comment.