MUSX Document Model
Loading...
Searching...
No Matches
musx::util::EnigmaParsingContext Class Reference

Wrapper class for interpreting and rendering Enigma-style strings with insert handling. More...

#include <EnigmaString.h>

Public Member Functions

 EnigmaParsingContext ()
 Null constructor.
 
 EnigmaParsingContext (const std::shared_ptr< const dom::TextsBase > &rawText, dom::Cmper forPartId, std::optional< dom::Cmper > forPageId=std::nullopt, EnigmaString::TextInsertCallback insertFunc=EnigmaString::defaultInsertsCallback)
 Constructor.
 
 operator bool () const noexcept
 Check whether the context holds a valid raw text pointer.
 
std::string getText (bool trimTags=false, EnigmaString::AccidentalStyle accidentalStyle=EnigmaString::AccidentalStyle::Ascii, const std::unordered_set< std::string_view > &ignoreTags={}) const
 Return displayable text with Enigma tags converted.
 
bool parseEnigmaText (const EnigmaString::TextChunkCallback &onText, const EnigmaString::TextInsertCallback &onInsert, const EnigmaString::EnigmaParsingOptions &options={}) const
 Parse the Enigma text into structured chunks with insert handling.
 
bool parseEnigmaText (const EnigmaString::TextChunkCallback &onText, const EnigmaString::EnigmaParsingOptions &options={}) const
 Parse the Enigma text into structured chunks with insert handling.
 
std::shared_ptr< dom::FontInfoparseFirstFontInfo () const
 Returns a shared pointer to a FontInfo instance that reflects the first font information in the text.
 
std::shared_ptr< const dom::TextsBasegetRawText () const
 Get the raw text pointer.
 
dom::Cmper getRequestedPartId () const
 Get the requested part id.
 
std::optional< int > getPageNumber () const
 Get the page number that was supplied, if any.
 

Public Attributes

std::string affixText
 Prefix or suffix to be passed in parsing options.
 
bool affixIsPrefix {}
 True if affixText is a prefix; false if it is a suffix.
 

Detailed Description

Wrapper class for interpreting and rendering Enigma-style strings with insert handling.

This class provides implementations of getText() and parseEnigmaText() that retrieve the raw text from a TextsBase object, either directly or by ID, and perform substitution of special insert commands such as ^page, ^date, etc.

Constructor & Destructor Documentation

◆ EnigmaParsingContext()

musx::util::EnigmaParsingContext::EnigmaParsingContext ( const std::shared_ptr< const dom::TextsBase > &  rawText,
dom::Cmper  forPartId,
std::optional< dom::Cmper forPageId = std::nullopt,
EnigmaString::TextInsertCallback  insertFunc = EnigmaString::defaultInsertsCallback 
)
inline

Constructor.

Parameters
rawTextThe raw text to use
forPartIdThe linked part ID to use for ^partname and ^totpages inserts
forPageIdThe value to use as page number for ^page inserts. ("#" is inserted if not provided, mimicing Finale behavior.)
insertFuncA common handler for insert conversions.

Member Function Documentation

◆ getText()

std::string musx::util::EnigmaParsingContext::getText ( bool  trimTags = false,
EnigmaString::AccidentalStyle  accidentalStyle = EnigmaString::AccidentalStyle::Ascii,
const std::unordered_set< std::string_view > &  ignoreTags = {} 
) const

Return displayable text with Enigma tags converted.

Parameters
trimTagsWhether to trim unknown tags or dump them into the output.
accidentalStyleThe accidental substitution style to use. (ASCII, Unicode, SMuFL)
ignoreTagsA list of tags to ignore. (Normally only used internally.)
Returns
The final rendered string.

◆ parseEnigmaText() [1/2]

bool musx::util::EnigmaParsingContext::parseEnigmaText ( const EnigmaString::TextChunkCallback onText,
const EnigmaString::EnigmaParsingOptions options = {} 
) const
inline

Parse the Enigma text into structured chunks with insert handling.

Parameters
onTextThe handler for font and text style changes.
optionsThe options for the parsing session.
Returns
True if parsing was successful.

◆ parseEnigmaText() [2/2]

bool musx::util::EnigmaParsingContext::parseEnigmaText ( const EnigmaString::TextChunkCallback onText,
const EnigmaString::TextInsertCallback onInsert,
const EnigmaString::EnigmaParsingOptions options = {} 
) const

Parse the Enigma text into structured chunks with insert handling.

Parameters
onTextThe handler for font and text style changes.
onInsertThe handler for insert conversions. This function is called first. If it returns a string, the default insert value is skipped.
optionsThe options for the parsing session.
Returns
True if parsing was successful.