From aabfe37483233382e3a823af5202ad29d2ef3868 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 5 Sep 2019 13:51:08 -0400 Subject: Decode entities in titles --- bin/title.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bin/title.c b/bin/title.c index 84f4f382..6f882223 100644 --- a/bin/title.c +++ b/bin/title.c @@ -36,7 +36,48 @@ static regex_t regex(const char *pattern) { errx(EX_SOFTWARE, "regcomp: %s: %s", buf, pattern); } +static const struct Entity { + wchar_t ch; + const char *name; +} Entities[] = { + { L'"', """ }, + { L'&', "&" }, + { L'<', "<" }, + { L'>', ">" }, + { L'␤', " " }, +}; + +static wchar_t entity(const char *name) { + for (size_t i = 0; i < sizeof(Entities) / sizeof(Entities[0]); ++i) { + struct Entity entity = Entities[i]; + if (strncmp(name, entity.name, strlen(entity.name))) continue; + return entity.ch; + } + if (!strncmp(name, "&#x", 3)) return strtoul(&name[3], NULL, 16); + if (!strncmp(name, "&#", 2)) return strtoul(&name[2], NULL, 10); + return 0; +} + +static const char EntityPattern[] = { + "[[:space:]]+|&([[:alpha:]]+|#([[:digit:]]+|x[[:xdigit:]]+));" +}; +static regex_t EntityRegex; + static void showTitle(const char *title) { + regmatch_t match = {0}; + for (; *title; title += match.rm_eo) { + if (regexec(&EntityRegex, title, 1, &match, 0)) break; + if (title[match.rm_so] != '&') { + printf("%.*s ", (int)match.rm_so, title); + continue; + } + wchar_t ch = entity(&title[match.rm_so]); + if (ch) { + printf("%.*s%lc", (int)match.rm_so, title, (wint_t)ch); + } else { + printf("%.*s", (int)match.rm_eo, title); + } + } printf("%s\n", title); } @@ -98,6 +139,7 @@ static CURLcode fetchTitle(const char *url) { } int main(int argc, char *argv[]) { + EntityRegex = regex(EntityPattern); TitleRegex = regex(TitlePattern); setlocale(LC_CTYPE, ""); -- cgit 1.4.1 b9bed61c8b449d5f6a7094d95ea1710082683d06&follow=1'>root/txt/music.md (unfollow)
Commit message (Expand)Author
2018-10-03Fill 03 through 1F of sans6x10June McEnroe
2018-10-03Fix ¼ glyph of sans6x8June McEnroe
2018-10-03Fill A6 through AF of sans6x10June McEnroe
2018-10-02Rewrite schemeJune McEnroe
2018-10-02Allow setting colors in psf2pngJune McEnroe
2018-09-30Add some '80s music notesJune McEnroe
2018-09-30Fix case of ASCII constants in psfedJune McEnroe
2018-09-29Squish Ñ in sans6x10 consistentlyJune McEnroe
2018-09-29Add -c and -s to psf2pngJune McEnroe
2018-09-29Add box drawing glyphs to sans6x10June McEnroe
2018-09-29Tweak sans6x8 shading blocksJune McEnroe
2018-09-29Fill 7F through A5 of sans6x10June McEnroe
2018-09-29Add f and ' to psfedJune McEnroe
2018-09-28Add sans6x10 basic glyphsJune McEnroe
2018-09-28Make sans6x8 double quote narrowerJune McEnroe
2018-09-28Add greek glyphs to sans6x8June McEnroe
2018-09-28Add png target in etc/psfJune McEnroe
2018-09-28Disable visual bell in light terminal profileJune McEnroe
2018-09-28Add psf2pngJune McEnroe
2018-09-27Add HJKL for moving glyphs to psfedJune McEnroe
2018-09-27Move psfed paste to edit modeJune McEnroe
2018-09-27Export PWDJune McEnroe
2018-09-27Add sans6x8 PSF2 fontJune McEnroe
2018-09-26Add copy paste to psfedJune McEnroe
2018-09-25Add r to psfed for invertJune McEnroe
2018-09-24Add psfed, a PSF2 font editorJune McEnroe
2018-09-21Add scheme -i to swap white and blackJune McEnroe
2018-09-21Map caps lock to escape on Linux consoleJune McEnroe
2018-09-19Fix README mandoc lintsJune McEnroe
2018-09-19Un-NOT trans.alpha values in pngoJune McEnroe
2018-09-18Refactor reads in pngo and clear palette between filesJune McEnroe
2018-09-17Add tRNS support to pngoJune McEnroe
2018-09-11Move gfx man pages to gfx/manJune McEnroe
2018-09-11Move bin man pages to bin/manJune McEnroe
2018-09-11Rewrite gfx.7 and render plaintext READMEJune McEnroe
2018-09-11Remove GAMES from BINSJune McEnroe
2018-09-11Rewrite bin.7 and render to plaintext READMEJune McEnroe
2018-09-11Add "blank" lines to man pagesJune McEnroe
2018-09-10Add mdoc syntax fileJune McEnroe
2018-09-08Fix Nm usage in multi-name man pagesJune McEnroe
2018-09-08Put real dates on man pagesJune McEnroe
2018-09-08Replace gfx README with REAMDE.7June McEnroe
2018-09-08Link gfx man pages in ~/.localJune McEnroe