// Returns whether haystack contains needle (case-sensitive, both should be pre-lowercased) bool str_contains(String haystack, String needle) { return replace(haystack, needle, "\x01") != haystack; } RENDER(Request& context) { String q = to_lower(trim(context.get["q"])); if(q.length() < 2) { return; } u32 count = 0; for(auto file_name : ls("pages/")) { String ft = nibble(file_name, "."); String name = ft; String badge = ""; if(ft.substr(0, 2) == "0_") { nibble(name, "_"); badge = "struct"; } else if(ft.substr(0, 2) == "1_") { nibble(name, "_"); badge = "directive"; } String content = file_get_contents("pages/" + ft + ".txt"); if(str_contains(to_lower(name), q) || str_contains(to_lower(content), q)) { // Find first content line that contains the query for a snippet String snippet = ""; for(auto line : split(content, "\n")) { String t = trim(line); if(t.length() > 4 && t.substr(0, 1) != ":" && str_contains(to_lower(t), q)) { snippet = t; if(snippet.length() > 100) snippet = snippet.substr(0, 100) + "…"; break; } } <>
No results for "= html_escape(q) ?>"
> } }