I am writing this at the top to start over and answer
Caio's questions. Say you have an accidental string name "A..." and the stem is up; then the same accidental with the stem down would be named "-A...". "A".. would be a short string like LilyPond uses for accidentals.
If you want to use the accidental more than one time say 2 then write the strings like this, "A...x2" and "-A...x2". But the second name is wrong, the "x2" part needs to go with the stem. "A...x2" is the logical entry but the "x" needs to be replaced with "-x". Before I do this I need a space before the "x", i replace "x",, if it exists
with " x" if it exists. I now have the 4 possibilities "A...", "-A...", "A... x2", "-A... x2".
My question is, is there a procedure that sees the [-] then searches for "x" and replaces it with "-x".
I could add the "-" to the "x" at entry but want to keep it simple, x (times ) 2 is logical (and saves a stroke). The next step would be to split the strings into two strings if a space exists. So "A... x2" becomes "A..." " x2" and "-A... x2" becomes "-A..." "-x2" ; two glyph each to form ligatures.
Thank you, ƒg