static string trailingSpaces(string text) { var lines = text.Split(@"\r\n"); var matcher = new Matcher(); for (var i = 0; i < lines.Length; i++) { if (lines[i].IsEmpty()) { continue; } if (matcher.IsMatch(lines[i], @"([ \t]*)$")) { Slicer space = matcher[0, 1]; for (var j = 0; j < space.Length; j++) { space[j, 1] = space[j, 1] == "\t" ? "¬" : "•"; } matcher[0, 1] = space.ToString(); } lines[i] = matcher.ToString(); } return(lines.Listify("\r\n")); }
public Value Each() { using (var assistant = new ParameterAssistant(Arguments)) { var block = assistant.Block(); if (block == null) { return(null); } RegionManager.Regions.Push("string-indexer"); var changes = new Hash <int, string>(); var indexes = getIndexes(); foreach (var index in indexes) { var correctedIndex = WrapIndex(index, text.Text.Length, true); assistant.SetParameterValues(text.Text.Skip(index).Take(1), index.ToString(), correctedIndex); var result = block.Evaluate(); var signal = ParameterAssistant.Signal(); if (signal == ParameterAssistant.SignalType.Breaking) { break; } switch (signal) { case ParameterAssistant.SignalType.Continuing: continue; case ParameterAssistant.SignalType.ReturningNull: return(null); } if (result != null) { changes[correctedIndex] = result.Text; } } Slicer slicer = text.Text; foreach (var item in changes) { slicer[item.Key] = item.Value; } text.Text = slicer.ToString(); RegionManager.Regions.Pop("string-indexer"); return(null); } }
protected Result <string> getText(MemberData memberData) => tryTo(() => { var slicer = new Slicer(memberData.Source); foreach (var item in memberData.Pairs) { item.Value.Replace(obj, slicer); } return(slicer.ToString()); });
protected bool result(bool success) { State.PatternDepth--; if (success) { if (startIndex > -1 && stopIndex > -1 && Replacement != null) { if (multiScan) { Replacement = Replacement.Clone(); } State.SaveWorkingInput(); var slicer = new Slicer(State.WorkingInput); var length = stopIndex - startIndex; var text = slicer[startIndex, length]; State.WorkingInput = text; Regions.SetPatternPositionData(startIndex, length); if (Replacement.Immediate) { var replacementText = Replacement.Text; if (replacementText != null) { slicer[startIndex, length] = replacementText; State.RestoreWorkingInput(); State.WorkingInput = slicer.ToString(); } else { State.RestoreWorkingInput(); } } else { State.Replacements.Add(startIndex, length, Replacement); State.RestoreWorkingInput(); } } if (!SubPattern) { State.Replacements.Replace(); } } return(success); }
public Value Remove() { var indexes = getIndexes(); Slicer slicer = text.Text; foreach (var index in indexes) { var correctedIndex = index; if (correctedIndex < 0) { correctedIndex = WrapIndex(correctedIndex, text.Text.Length, true); } slicer[correctedIndex, 1] = ""; } text.Text = slicer.ToString(); return(this); }