ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
sh_classify.h
Go to the documentation of this file.
1
21#pragma once
22
23#include <stddef.h>
24#include <stdint.h>
25#include <string.h>
26
37typedef enum : uint8_t {
44
59static inline bool sh_fmt_is_comic(sh_book_fmt_t fmt)
60{
61 return (fmt == k_sh_fmt_cbz) || (fmt == k_sh_fmt_cbr) || (fmt == k_sh_fmt_cbt);
62}
63
74static inline char sh_ascii_lower(char c)
75{
76 return ((c >= 'A') && (c <= 'Z')) ? (char)(c + ('a' - 'A')) : c;
77}
78
95static inline bool sh_ext_match(const char* name, const char* ext)
96{
97 const size_t n = strlen(name);
98 const size_t e = strlen(ext);
99 if (n <= e) {
100 return false;
101 }
102 for (size_t i = 0U; i < e; ++i) {
103 if (sh_ascii_lower(name[n - e + i]) != sh_ascii_lower(ext[i])) {
104 return false;
105 }
106 }
107 return true;
108}
109
129static inline bool sh_book_classify(const char* name, sh_book_fmt_t* out_fmt)
130{
131 if (sh_ext_match(name, ".rabook") || sh_ext_match(name, ".rbk")) {
132 *out_fmt = k_sh_fmt_rabook;
133 return true;
134 }
135 if (sh_ext_match(name, ".epub") || sh_ext_match(name, ".epb")) {
136 *out_fmt = k_sh_fmt_epub;
137 return true;
138 }
139 if (sh_ext_match(name, ".cbz")) {
140 *out_fmt = k_sh_fmt_cbz;
141 return true;
142 }
143 if (sh_ext_match(name, ".cbr")) {
144 *out_fmt = k_sh_fmt_cbr;
145 return true;
146 }
147 if (sh_ext_match(name, ".cbt")) {
148 *out_fmt = k_sh_fmt_cbt;
149 return true;
150 }
151 return false;
152}
size_t strlen(const char *s)
Calculate string length.
static bool sh_ext_match(const char *name, const char *ext)
Case-insensitive test that name ends in the extension ext.
Definition sh_classify.h:95
sh_book_fmt_t
Book container format behind a shelf entry / the open book.
Definition sh_classify.h:37
@ k_sh_fmt_cbr
Comic archive: RAR of page images (.cbr).
Definition sh_classify.h:41
@ k_sh_fmt_epub
EPUB parsed on-device by epub.
Definition sh_classify.h:39
@ k_sh_fmt_cbt
Comic archive: tar of page images (.cbt).
Definition sh_classify.h:42
@ k_sh_fmt_rabook
book RBKC container (demand-paged chunks).
Definition sh_classify.h:38
@ k_sh_fmt_cbz
Comic archive: ZIP of page images (.cbz).
Definition sh_classify.h:40
static char sh_ascii_lower(char c)
Fold one ASCII letter to lower case (non-letters returned unchanged).
Definition sh_classify.h:74
static bool sh_book_classify(const char *name, sh_book_fmt_t *out_fmt)
Classify a root file name into a book format; true if it is a book.
static bool sh_fmt_is_comic(sh_book_fmt_t fmt)
True if fmt is a comic-archive container (CBZ, CBR, or CBT).
Definition sh_classify.h:59