public void ConvertTokensTo(TokenConversionType conversionType) { try { ActiveTextArea.BeginUpdate(); StringBuilder sb = null; HighlightRuleSet rules = ActiveDocument.HighlightingStrategy.GetRuleSet(null); IList <LineSegment> lines = ActiveDocument.LineSegmentCollection; for (int k = 0; k < lines.Count; k++) { LineSegment segment = lines[k]; for (int i = 0; i < segment.Words.Count; i++) { TextWord word = segment.Words[i]; if (word.Type != TextWordType.Word) { continue; } if (rules.KeyWords[ActiveDocument, segment, word.Offset, word.Length] != null) { string newVal = word.Word; switch (conversionType) { case TokenConversionType.Lower: newVal = word.Word.ToLowerInvariant(); break; case TokenConversionType.Upper: newVal = word.Word.ToUpperInvariant(); break; case TokenConversionType.Capitalize: newVal = word.Word; char[] chars = newVal.ToCharArray(); chars[0] = Char.ToUpperInvariant(newVal[0]); sb = new StringBuilder(); sb.Append(chars); newVal = sb.ToString(); break; default: break; } ActiveDocument.Replace(segment.Offset + word.Offset, word.Length, newVal); } } } } finally { ActiveTextArea.EndUpdate(); } }
public void ChangeScriptCase(TokenConversionType conversionType) { try { ActiveTextArea.BeginUpdate(); HighlightRuleSet rules = ActiveDocument.HighlightingStrategy.GetRuleSet(null); IList <LineSegment> lines = ActiveDocument.LineSegmentCollection; for (int k = 0; k < lines.Count; k++) { LineSegment segment = lines[k]; for (int i = 0; i < segment.Words.Count; i++) { TextWord word = segment.Words[i]; if (word.Type != TextWordType.Word) { continue; } string newVal = word.Word; switch (conversionType) { case TokenConversionType.Lower: newVal = word.Word.ToLowerInvariant(); break; case TokenConversionType.Upper: newVal = word.Word.ToUpperInvariant(); break; default: break; } ActiveDocument.Replace(segment.Offset + word.Offset, word.Length, newVal); } } } finally { ActiveTextArea.EndUpdate(); } }