30#include <unordered_set>
32#include "musx/dom/Fundamentals.h"
33#include "musx/dom/MusxInstance.h"
34#include "musx/dom/ResolvedFontInfo.h"
51struct EnigmaResolvedStyles;
72 EnigmaStyles(
const std::weak_ptr<dom::Document>& document);
82 std::shared_ptr<dom::FontInfo>
font;
210 template <
typename CharT>
211 static std::string
fromU8(
const CharT* s)
213 static_assert(std::is_same<CharT, char>::value || std::is_same<CharT,
decltype(u8
'a')>::value,
214 "fromU8() only accepts char or char8_t pointers");
215 return std::string(
reinterpret_cast<const char*
>(s));
219 static std::string
toU8(
char32_t cp);
222 static std::string
toU8(
const std::u32string& value);
354 static std::optional<dom::options::AccidentalInsertSymbolType>
commandIsAccidentalType(std::string_view commandText);
376 static std::vector<std::string>
parseComponents(
const std::string& input,
size_t* parsedLength =
nullptr);
383 const std::string& text,
389 const std::string& text,
409 const std::vector<std::string>& parsedCommand
444 return parseEnigmaTextImpl(document, forPartId, rawText,
ignoringInserts(onText), onInsert, options, parsingContext,
EnigmaStyles(document),
nullptr);
452 return parseEnigmaTextImpl(document, forPartId, rawText, onText, onInsert, options, parsingContext,
EnigmaStyles(document),
nullptr);
478 static bool parseStyleCommand(std::vector<std::string> components, EnigmaStyles& styles);
481 static std::string
trimTags(
const std::string& input);
488 static bool parseEnigmaTextImpl(
const std::shared_ptr<dom::Document>& document,
dom::Cmper forPartId,
const std::string& rawText,
490 const EnigmaParsingOptions& options,
const EnigmaParsingContext* parsingContext,
491 const EnigmaStyles& startingStyles,
const EnigmaTextInsert* enclosingInsert);
505 std::optional<int> m_forPageNumber;
511 : m_rawText(nullptr), m_forPartId(dom::SCORE_PARTID), m_insertFunc(
EnigmaString::defaultInsertsCallback)
520 std::optional<dom::Cmper> forPageId = std::nullopt,
522 : m_rawText(std::move(rawText)), m_forPartId(forPartId), m_forPageNumber(forPageId), m_insertFunc(insertFunc)
526 explicit operator bool() const noexcept
527 {
return static_cast<bool>(m_rawText); }
537 std::string
getText(
bool trimTags =
false,
539 const std::unordered_set<std::string_view>& ignoreTags = {})
const;
562 const EnigmaString::EnigmaParsingOptions& options = {})
const;
580 const EnigmaString::EnigmaParsingOptions& options = {})
const;
586 const EnigmaString::EnigmaParsingOptions& options = {})
const;
Wrapper class for interpreting and rendering Enigma-style strings with insert handling.
Definition EnigmaString.h:501
bool affixIsPrefix
True if affixText is a prefix; false if it is a suffix.
Definition EnigmaString.h:530
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.
Definition EnigmaString.cpp:701
dom::MusxInstance< dom::FontInfo > parseFirstFontInfo() const
Returns a shared pointer to a FontInfo instance that reflects the first font information in the text.
Definition EnigmaString.cpp:715
bool parseEnigmaText(const EnigmaString::TextChunkCallback &onText, const EnigmaString::EnigmaParsingOptions &options={}) const
Parse the Enigma text into structured chunks with insert handling.
Definition EnigmaString.h:568
dom::Cmper getRequestedPartId() const
Get the requested part id.
Definition EnigmaString.h:601
std::optional< int > getPageNumber() const
Get the page number that was supplied, if any.
Definition EnigmaString.h:604
dom::MusxInstance< dom::TextsBase > getRawText() const
Get the raw text pointer.
Definition EnigmaString.h:595
std::vector< EnigmaTextChunk > collectEnigmaTextChunks(const EnigmaString::TextInsertCallback &onInsert, const EnigmaString::EnigmaParsingOptions &options={}) const
Collect the Enigma text into styled chunks with insert handling.
Definition EnigmaString.cpp:683
EnigmaParsingContext(dom::MusxInstance< dom::TextsBase > rawText, dom::Cmper forPartId, std::optional< dom::Cmper > forPageId=std::nullopt, EnigmaString::TextInsertCallback insertFunc=EnigmaString::defaultInsertsCallback)
Constructor.
Definition EnigmaString.h:519
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.
Definition EnigmaString.h:547
EnigmaParsingContext()
Null constructor.
Definition EnigmaString.h:510
std::string affixText
Prefix or suffix to be passed in parsing options.
Definition EnigmaString.h:529
Static class that provides utilities to extract information from enigma strings. Enigma strings use t...
Definition EnigmaString.h:207
static std::string trimTags(const std::string &input)
Trims all enigma tags from an enigma string, leaving just the plain text.
Definition EnigmaString.cpp:616
static std::string fromU8(const CharT *s)
Convert u8"" literals to std::string in a way that works both in C++17 and C++20+.
Definition EnigmaString.h:211
static std::optional< dom::options::AccidentalInsertSymbolType > commandIsAccidentalType(std::string_view commandText)
Returns the accidental insert symbol type if the input command is an accidental insert.
Definition EnigmaString.cpp:302
static bool startsWithStyleCommand(const std::string &text)
Returns true if the enigma string starts with a style insert.
Definition EnigmaString.cpp:170
static bool parseStyleCommand(std::vector< std::string > components, EnigmaStyles &styles)
Incorporates an enigma font insert into the supplied dom::FontInfo instance.
Definition EnigmaString.cpp:248
static bool startsWithFontCommand(const std::string &text)
Returns true if the enigma string starts with a font insert.
Definition EnigmaString.cpp:158
AccidentalStyle
Enumeration to specify the type of accidental substitution representation.
Definition EnigmaString.h:253
@ Smufl
Use SMuFL notation-specific accidentals.
@ Ascii
Use ASCII substitutions for accidentals.
@ Unicode
Use Unicode text accidentals.
std::function< bool(const std::string &text, const EnigmaStyles &styles, const EnigmaTextInsert *insert)> TextChunkWithInsertCallback
Variant of TextChunkCallback that also receives the insert a chunk was substituted for,...
Definition EnigmaString.h:392
static std::string toU8(char32_t cp)
Converts a 32-bit codepoint to a utf8-encoded std::string.
Definition EnigmaString.cpp:124
static bool parseEnigmaText(const std::shared_ptr< dom::Document > &document, dom::Cmper forPartId, const std::string &rawText, const TextChunkCallback &onText, const TextInsertCallback &onInsert, const EnigmaParsingOptions &options={}, const EnigmaParsingContext *parsingContext=nullptr)
Parses an Enigma-formatted string, handling font inserts and escaped carets.
Definition EnigmaString.h:440
static TextInsertCallback defaultInsertsCallback
Inserts callback to take all default insert subsitutions determined by parseEnigmaText.
Definition EnigmaString.h:413
static bool parseEnigmaText(const std::shared_ptr< dom::Document > &document, dom::Cmper forPartId, const std::string &rawText, const TextChunkWithInsertCallback &onText, const TextInsertCallback &onInsert, const EnigmaParsingOptions &options={}, const EnigmaParsingContext *parsingContext=nullptr)
Variant of parseEnigmaText whose text handler also receives the insert each chunk was substituted for...
Definition EnigmaString.h:448
static TextChunkWithInsertCallback ignoringInserts(const TextChunkCallback &onText)
Adapts a TextChunkCallback to a TextChunkWithInsertCallback that ignores the insert.
Definition EnigmaString.h:394
AccidentalInsertHandling
Enumeration to specify the default handling for accidental insert commands. Like all Enigma commands,...
Definition EnigmaString.h:230
@ ParseToGlyphs
Parse accidental insert commands into glyph font changes and character strings.
@ Substitute
Substitute accidental insert commands with textual representations.
std::function< bool(const std::string &text, const EnigmaStyles &styles)> TextChunkCallback
Iteration function type that the parser calls back when the font has changed or when recursively pars...
Definition EnigmaString.h:385
static std::string plainTextFromChunks(const std::vector< EnigmaTextChunk > &chunks)
Concatenate the plain text from collected Enigma text chunks.
Definition EnigmaString.cpp:651
static bool parseEnigmaText(const std::shared_ptr< dom::Document > &document, dom::Cmper forPartId, const std::string &rawText, const TextChunkCallback &onText, const EnigmaParsingOptions &options={}, const EnigmaParsingContext *parsingContext=nullptr)
Simplified version of parseEnigmaText that strips unhandled inserts. Useful in particular when the ca...
Definition EnigmaString.h:464
static std::vector< std::string > parseComponents(const std::string &input, size_t *parsedLength=nullptr)
Parses an enigma text insert into its constituent components.
Definition EnigmaString.cpp:184
std::function< std::optional< std::string >(const std::vector< std::string > &parsedCommand)> TextInsertCallback
Iteration function type that the parser calls back when it encounters an Enigma text insert that requ...
Definition EnigmaString.h:410
AccidentalInsertSymbolType
Insert symbol types for accidentals.
Definition Options.h:1480
std::shared_ptr< const T > MusxInstance
Defines the type of a musx instance stored in a pool.
Definition MusxInstance.h:40
int32_t Evpu
EVPU value (288 per inch)
Definition Fundamentals.h:59
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:57
object model for musx file (enigmaxml)
Definition BaseClasses.h:38
Document-independent snapshot of a #FontInfo. (See FontInfo::resolve.)
Definition ResolvedFontInfo.h:36
Document-independent snapshot of #EnigmaStyles. (See EnigmaStyles::resolve.)
Definition EnigmaString.h:94
dom::Evpu baseline
baseline setting (positive means up)
Definition EnigmaString.h:97
EnigmaStyles::CategoryTracking categoryFont
how the font is tracked against a marking category
Definition EnigmaString.h:96
dom::ResolvedFontInfo font
the resolved font
Definition EnigmaString.h:95
int tracking
inter-character tracking in EMs (1/1000 font size)
Definition EnigmaString.h:99
dom::Evpu superscript
superscript setting added to baseline (positive means up)
Definition EnigmaString.h:98
A text chunk with a document-independent snapshot of its styles. (See EnigmaTextChunk::resolve....
Definition EnigmaString.h:111
std::string text
the chunk as valid UTF-8 (see EnigmaTextChunk::text)
Definition EnigmaString.h:112
std::optional< EnigmaTextInsert > insert
the insert the chunk was substituted for (see EnigmaTextChunk::insert)
Definition EnigmaString.h:114
EnigmaResolvedStyles styles
the resolved styles active for the chunk
Definition EnigmaString.h:113
Options for configuring how Enigma strings are parsed.
Definition EnigmaString.h:301
bool ignoreStyleTags
If value is true, font & style tags are ignored. Note that you may still get get font and style chang...
Definition EnigmaString.h:337
EnigmaParsingOptions()
constructor
Definition EnigmaString.h:303
EnigmaParsingOptions(AccidentalStyle accidentalStyle)
constructor for accidental substitution
Definition EnigmaString.h:308
AccidentalStyle substitutionStyle
Specifies the accidental substitution style used when insertHandling is Substitute.
Definition EnigmaString.h:326
std::unordered_set< std::string_view > ignoreTags
Skip tags in this set. Primarily used by the "partname" insert to avoid a situation where the partnam...
Definition EnigmaString.h:344
AccidentalInsertHandling insertHandling
Specifies how accidental insert commands are handled during parsing.
Definition EnigmaString.h:318
bool stripUnknownTags
Specifies whether to strip unknown tags or dump them into the output string.
Definition EnigmaString.h:331
Text styles for enigma strings.
Definition EnigmaString.h:56
EnigmaResolvedStyles resolve() const
Creates a document-independent snapshot of the styles.
Definition EnigmaString.cpp:106
std::shared_ptr< dom::FontInfo > font
the font to use
Definition EnigmaString.h:82
CategoryTracking
Specifies is the current enigma style tracks an expressions marking category font....
Definition EnigmaString.h:64
@ NumberFont
tracks the category's number font (not implemented in Finale U.I.)
@ TextFont
tracks the category's text font
@ None
no category tracking
@ MusicFont
tracks the category's music font
int tracking
inter-character tracking in EMs (1/1000 font size)
Definition EnigmaString.h:86
EnigmaStyles createDeepCopy() const
Creates a deep copy of the styles, including copying any shared pointer instances.
Definition EnigmaString.cpp:99
dom::Evpu superscript
superscript setting added to baseline (positive means up)
Definition EnigmaString.h:85
dom::Evpu baseline
baseline setting (positive means up)
Definition EnigmaString.h:84
CategoryTracking categoryFont
how this font is tracked against a marking category
Definition EnigmaString.h:83
A text chunk with the Enigma styles active for that chunk.
Definition EnigmaString.h:119
std::string text
The chunk as valid UTF-8.
Definition EnigmaString.h:123
std::optional< EnigmaTextInsert > insert
The insert the chunk was substituted for, when it was.
Definition EnigmaString.h:129
EnigmaResolvedTextChunk resolve() const
Creates a document-independent snapshot of the chunk. (See EnigmaStyles::resolve.)
Definition EnigmaString.cpp:119
EnigmaStyles styles
Definition EnigmaString.h:124
The Enigma text insert a chunk was substituted for. (See EnigmaTextChunk::insert.)
Definition EnigmaString.h:104
std::vector< std::string > parameters
the insert's parameters as written, e.g. {"1"} for ^page(1)
Definition EnigmaString.h:106
std::string command
the insert name without the leading caret, e.g. "value" or "flat"
Definition EnigmaString.h:105