wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
CodeGenUtils Namespace Reference

Functions

QString removeForbiddenChars (const QString &input, const bool stripFirst=false)
 Converts input into a legal language identifier.
QString sanitizeComment (const QString &input)
 Makes input safe to embed in a single-line "//" comment.
QString stripAccents (const QString &input)
 Strips Unicode diacritic marks (accents) from input using NFC → NFD decomposition.

Function Documentation

◆ removeForbiddenChars()

QString CodeGenUtils::removeForbiddenChars ( const QString & input,
const bool stripFirst = false )
inline

Converts input into a legal language identifier.

Lowercases, trims whitespace, replaces spaces and dashes with underscores, removes all remaining non-word characters, prepends '_' if the result starts with a digit, and returns "_unnamed" for empty results.

Parameters
inputThe raw string to sanitise.
stripFirstIf true, accent-strips input before processing (required for Arduino C++ identifiers; not needed for SystemVerilog).

Definition at line 36 of file CodeGenUtils.h.

References stripAccents().

◆ sanitizeComment()

QString CodeGenUtils::sanitizeComment ( const QString & input)
inline

Makes input safe to embed in a single-line "//" comment.

Neutralizes embedded line breaks. Without this, a label containing "\n" (settable via a crafted .panda file's label field, or the MCP create_element/set_element_properties "label" parameter — neither restricts content beyond length) could break out of the comment and inject an arbitrary line into the generated Arduino/SystemVerilog file.

Definition at line 60 of file CodeGenUtils.h.

◆ stripAccents()

QString CodeGenUtils::stripAccents ( const QString & input)
inline

Strips Unicode diacritic marks (accents) from input using NFC → NFD decomposition.

Definition at line 18 of file CodeGenUtils.h.

Referenced by removeForbiddenChars().