STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
Slug.cpp
Go to the documentation of this file.
1#include <cctype>
2
4
5namespace fsw {
6namespace script {
7
8std::string slugify(const std::string& name) {
9 std::string out;
10 out.reserve(name.size());
11 bool pending_gap = false;
12 bool seen = false;
13 for (unsigned char c : name) {
14 if (std::isspace(c)) {
15 if (seen)
16 pending_gap = true; // collapse runs, and drop trailing space entirely
17 continue;
18 }
19 if (pending_gap) {
20 out += '_';
21 pending_gap = false;
22 }
23 out += static_cast<char>(std::toupper(c));
24 seen = true;
25 }
26 return out;
27}
28
29bool is_valid_slug(const std::string& slug) {
30 if (slug.empty())
31 return false;
32 if (!(slug[0] >= 'A' && slug[0] <= 'Z'))
33 return false;
34 for (char c : slug) {
35 const bool ok = (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
36 if (!ok)
37 return false;
38 }
39 return true;
40}
41
42} // namespace script
43} // namespace fsw
static bool ok
Definition flight_e2e.c:435
std::string slugify(const std::string &name)
Canonical name -> slug: trim, uppercase, collapse internal whitespace runs to a single '_'.
Definition Slug.cpp:8
bool is_valid_slug(const std::string &slug)
True when a slug is usable as a bare identifier: ^[A-Z][A-Z0-9_]*$.
Definition Slug.cpp:29
Motorized ball valve position: raw ADC counts -> % open.