droplet 1.3.0
A multipurpose Discord bot with the hacker in mind
Loading...
Searching...
No Matches
CppLearningIntent.hpp
Go to the documentation of this file.
1/*
2 * (c) Copyright erarnitox.de - All rights reserved
3 * Author: Erarnitox <david@erarnitox.de>
4 *
5 * License: MIT License
6 *
7 * Description: Compile-time phrase table and ASCII lowercase scan for the
8 * "how to learn C++" message hint. Kept header-only so unit tests and the
9 * hot-path bench can measure it without Discord/DPP.
10 */
11
12#pragma once
13
14#include <algorithm>
15#include <array>
16#include <cctype>
17#include <string>
18#include <string_view>
19
21
22inline constexpr std::array<std::string_view, 28> k_phrases{
23 "how to learn c++",
24 "how do i learn c++",
25 "how can i learn c++",
26 "where to learn c++",
27 "where can i learn c++",
28 "want to learn c++",
29 "wanna learn c++",
30 "learn c++",
31 "learning c++",
32 "c++ tutorial",
33 "tutorial for c++",
34 "tutorials for c++",
35 "cpp tutorial",
36 "tutorial cpp",
37 "learn cpp",
38 "learning cpp",
39 "how to learn cpp",
40 "how do i learn cpp",
41 "start learning c++",
42 "getting started with c++",
43 "beginner c++",
44 "new to c++",
45 "teach me c++",
46 "best way to learn c++",
47 "good resource c++",
48 "resources to learn c++",
49 "any tutorial c++",
50 "recommend c++ course",
51};
52
53[[nodiscard]] inline std::string lowercase_ascii(std::string_view text) {
54 std::string out(text.begin(), text.end());
55 std::transform(
56 out.begin(), out.end(), out.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
57 return out;
58}
59
60[[nodiscard]] inline bool mentions_cpp_learning_intent(std::string_view original_text) {
61 const std::string lower = lowercase_ascii(original_text);
62 for (const std::string_view phrase : k_phrases) {
63 if (lower.find(phrase) != std::string::npos) {
64 return true;
65 }
66 }
67 return false;
68}
69
70} // namespace cpp_learning_intent
Definition CppLearningIntent.hpp:20
std::string lowercase_ascii(std::string_view text)
Definition CppLearningIntent.hpp:53
bool mentions_cpp_learning_intent(std::string_view original_text)
Definition CppLearningIntent.hpp:60
constexpr std::array< std::string_view, 28 > k_phrases
Definition CppLearningIntent.hpp:22