Defined in header <cparse/Generator.hh>
virtual std::string replaceNonAlphanums( std::string const& base,
std::string::value_type const rch ) const noexcept;
Returns a copy of base with every byte for which std::isalnum returns false replaced by rch.
Parameters
| Parameter | Description |
|---|---|
base | The input string. Not mutated. |
rch | The replacement character. Typically '_' for identifier sanitisation. |
Return value
A new string of the same length as base.
Exceptions
noexcept.
Notes
Typical use is turning a path or header name into something valid for a #define:
replaceNonAlphanums("include/fedem/parser/Cursor.hh", '_')
// → "include_fedem_parser_Cursor_hh"
Consecutive non-alphanumerics each become a rch, producing runs of the replacement character. The generateHeaderGuard composition explicitly collapses those runs afterwards.
Byte-oriented: std::isalnum operates on unsigned char. Bytes above 127 are non-alphanumeric under the default locale, so a UTF-8 multi-byte sequence is entirely replaced.
See also
- Generator::removeNonAlphanums — the drop-instead-of-replace variant.
- Generator::generateHeaderGuard — a caller.

