private string Group2WithSpaceElimination(Match match, Group g) { var cc = match.Length - g.Length - 1; var d = new Block() { index = blocks.Count, start = match.Index, length = g.Length + 1, lineSeparator = -1, }; var str = "\\vlink[" + blocks.Count + "]{\\" + g.Value + "}"; blocks.Add(d); for (int i = 0; i < cc; i++) { var d2 = new Block() { index = blocks.Count, start = match.Index + g.Length + 1 + i, length = 1, lineSeparator = -1, }; str += "\\vlink[" + blocks.Count + "]{ }"; blocks.Add(d2); } return(str); }
internal Block GetPrevious(Block block) { if (block.index > 0) { return(blocks[block.index - 1]); } else { return(block); } }
internal Block GetNext(Block block) { if (block.index < blocks.Count - 1) { return(blocks[block.index + 1]); } else { return(block); } }
internal int GetBlockLineNumber(Block b) { var i = b.index; do { if (blocks[i].lineSeparator >= 0) { return(blocks[i].lineSeparator); } } while (i-- >= 0); return(0); }
internal Block GetBlockBefore(int pos) { Block b = new Block() { index = -1 }; foreach (var i in blocks) { if (i.start > pos) { break; } b = i; } return(b); }
public override string ReplaceString(string original) { blocks.Clear(); int line = 0; original = m_pattern.Replace(original, (match) => { if (!match.Groups[5].Success && match.Length > 2) { // skip commands, fonts, big operators, delimiter var g = match.Groups[1]; int s; var m = TEXPreference.main; if (!g.Success || TexFormulaParser.isCommandRegistered(g.Value) || m.GetFontIndexByID(g.Value) >= 0) { return(match.Value); } else if ((s = m.symbols.GetValue(g.Value)) > 0 && (m.GetChar(s).nextLargerExist || m.GetChar(s).extensionExist)) { return(match.Value); } else if (match.Length > g.Length + 1) { // extra spaces can't be tolerated // alternate to custom logic return(Group2WithSpaceElimination(match, g)); } } var cmd = "\\vlink[" + blocks.Count + "]"; Block dyn = new Block() { index = blocks.Count, start = match.Index, length = match.Length, // see text input cursor lineSeparator = -1, }; if (match.Value == "\n") { dyn.lineSeparator = line++; blocks.Add(dyn); return("\n" + cmd + "{}"); } else if (match.Value == "\\") { blocks.Add(dyn); return(cmd + "{\\\\}"); } else if (match.Groups[4].Success) { dyn.start++; dyn.length = 0; blocks.Add(dyn); return("{" + cmd + "{" + emptyPlaceholder + "}}"); } else { blocks.Add(dyn); return(cmd + "{" + match.Value + "}"); } }); { // keep things stable by capturing words original = m_wrapholder.Replace(original, @"{$1}"); // sanitize invalid scripts original = m_scriptEscape.Replace(original, @"{$1}$2"); } return(original); }