From: Jean-Philippe Bruyère Date: Wed, 30 Aug 2017 17:16:58 +0000 (+0200) Subject: Crow.Coding namespace, rename CodeTextBuffer->CodeBuffer X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=1c8eacec333223ac202c6b1540dbeaeaa98a9815;p=jp%2Fcrowedit.git Crow.Coding namespace, rename CodeTextBuffer->CodeBuffer --- diff --git a/CrowEdit.csproj b/CrowEdit.csproj index 6a66e49..ea89cf2 100644 --- a/CrowEdit.csproj +++ b/CrowEdit.csproj @@ -69,7 +69,6 @@ - @@ -81,6 +80,7 @@ + diff --git a/src/CSharpParser.cs b/src/CSharpParser.cs index 8105b89..f9d7cba 100644 --- a/src/CSharpParser.cs +++ b/src/CSharpParser.cs @@ -1,7 +1,7 @@ using System; using Crow; -namespace CrowEdit +namespace Crow.Coding { public class CSharpParser : Parser { diff --git a/src/CodeBuffer.cs b/src/CodeBuffer.cs new file mode 100644 index 0000000..ab764f7 --- /dev/null +++ b/src/CodeBuffer.cs @@ -0,0 +1,149 @@ +// +// CodeTextBuffer.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2017 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace Crow.Coding +{ + public class CodeBufferEventArgs : EventArgs { + public int LineStart; + public int LineCount; + + public CodeBufferEventArgs(int lineNumber) { + LineStart = lineNumber; + LineCount = 1; + } + public CodeBufferEventArgs(int lineStart, int lineCount) { + LineStart = lineStart; + LineCount = lineCount; + } + } + + public class CodeTextBuffer + { + #region Events + public event EventHandler LineUpadateEvent; + public event EventHandler LineRemoveEvent; + public event EventHandler LineAdditionEvent; + public event EventHandler BufferCleared; + #endregion + + #region CTOR + public CodeTextBuffer () : base() {} + #endregion + + + List lines = new List(); + + public int Length { get { return lines.Count;}} + + public string this[int i] + { + get { return lines[i]; } + set { + if (lines [i] == value) + return; + lines[i] = value; + LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i)); + } + } + + public void RemoveAt(int i){ + lines.RemoveAt(i); + LineRemoveEvent.Raise (this, new CodeBufferEventArgs (i)); + } + public void Insert(int i, string item){ + lines.Insert (i, item); + LineAdditionEvent.Raise (this, new CodeBufferEventArgs (i)); + } + public void AddRange (string[] items){ + int start = lines.Count; + lines.AddRange (items); + LineAdditionEvent.Raise (this, new CodeBufferEventArgs (start, items.Length)); + } + public void Clear () { + lines.Clear(); + BufferCleared.Raise (this, null); + } + + + public void Load(string rawSource) { + this.Clear(); + + if (string.IsNullOrEmpty (rawSource)) + return; + + AddRange (Regex.Split (rawSource, "\r\n|\r|\n|\\\\n")); + + lineBreak = detectLineBreakKind (rawSource); + findLongestLine (); + } + string lineBreak = Interface.LineBreak; + + public int longestLineIdx = 0; + public int longestLineCharCount = 0; + + void findLongestLine(){ + longestLineCharCount = 0; + for (int i = 0; i < lines.Count; i++) { + if (lines[i].Length > longestLineCharCount) { + longestLineCharCount = lines[i].Length; + longestLineIdx = i; + } + } + } + /// line break could be '\r' or '\n' or '\r\n' + static string detectLineBreakKind(string buffer){ + string strLB = ""; + + if (string.IsNullOrEmpty(buffer)) + return Interface.LineBreak; + int i = 0; + while ( i < buffer.Length) { + if (buffer [i] == '\r') { + strLB += '\r'; + i++; + } + if (i < buffer.Length) { + if (buffer [i] == '\r') + return "\r"; + if (buffer[i] == '\n') + strLB += '\n'; + } + if (!string.IsNullOrEmpty (strLB)) + return strLB; + i++; + } + return Interface.LineBreak; + } + /// + /// return all lines with linebreaks + /// + public string FullText{ + get { + return lines.Count > 0 ? lines.Aggregate((i, j) => i + this.lineBreak + j) : ""; + } + } + } +} + diff --git a/src/CodeTextBuffer.cs b/src/CodeTextBuffer.cs deleted file mode 100644 index b218ae3..0000000 --- a/src/CodeTextBuffer.cs +++ /dev/null @@ -1,149 +0,0 @@ -// -// CodeTextBuffer.cs -// -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2017 jp -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; - -namespace Crow -{ - public class CodeBufferEventArgs : EventArgs { - public int LineStart; - public int LineCount; - - public CodeBufferEventArgs(int lineNumber) { - LineStart = lineNumber; - LineCount = 1; - } - public CodeBufferEventArgs(int lineStart, int lineCount) { - LineStart = lineStart; - LineCount = lineCount; - } - } - - public class CodeTextBuffer - { - #region Events - public event EventHandler LineUpadateEvent; - public event EventHandler LineRemoveEvent; - public event EventHandler LineAdditionEvent; - public event EventHandler BufferCleared; - #endregion - - #region CTOR - public CodeTextBuffer () : base() {} - #endregion - - - List lines = new List(); - - public int Length { get { return lines.Count;}} - - public string this[int i] - { - get { return lines[i]; } - set { - if (lines [i] == value) - return; - lines[i] = value; - LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i)); - } - } - - public void RemoveAt(int i){ - lines.RemoveAt(i); - LineRemoveEvent.Raise (this, new CodeBufferEventArgs (i)); - } - public void Insert(int i, string item){ - lines.Insert (i, item); - LineAdditionEvent.Raise (this, new CodeBufferEventArgs (i)); - } - public void AddRange (string[] items){ - int start = lines.Count; - lines.AddRange (items); - LineAdditionEvent.Raise (this, new CodeBufferEventArgs (start, items.Length)); - } - public void Clear () { - lines.Clear(); - BufferCleared.Raise (this, null); - } - - - public void Load(string rawSource) { - this.Clear(); - - if (string.IsNullOrEmpty (rawSource)) - return; - - AddRange (Regex.Split (rawSource, "\r\n|\r|\n|\\\\n")); - - lineBreak = detectLineBreakKind (rawSource); - findLongestLine (); - } - string lineBreak = Interface.LineBreak; - - public int longestLineIdx = 0; - public int longestLineCharCount = 0; - - void findLongestLine(){ - longestLineCharCount = 0; - for (int i = 0; i < lines.Count; i++) { - if (lines[i].Length > longestLineCharCount) { - longestLineCharCount = lines[i].Length; - longestLineIdx = i; - } - } - } - /// line break could be '\r' or '\n' or '\r\n' - static string detectLineBreakKind(string buffer){ - string strLB = ""; - - if (string.IsNullOrEmpty(buffer)) - return Interface.LineBreak; - int i = 0; - while ( i < buffer.Length) { - if (buffer [i] == '\r') { - strLB += '\r'; - i++; - } - if (i < buffer.Length) { - if (buffer [i] == '\r') - return "\r"; - if (buffer[i] == '\n') - strLB += '\n'; - } - if (!string.IsNullOrEmpty (strLB)) - return strLB; - i++; - } - return Interface.LineBreak; - } - /// - /// return all lines with linebreaks - /// - public string FullText{ - get { - return lines.Count > 0 ? lines.Aggregate((i, j) => i + this.lineBreak + j) : ""; - } - } - } -} - diff --git a/src/Parser.cs b/src/Parser.cs index 19c3df4..4d5b0ce 100644 --- a/src/Parser.cs +++ b/src/Parser.cs @@ -4,7 +4,7 @@ using Crow; using System.Collections.Generic; using System.Diagnostics; -namespace CrowEdit +namespace Crow.Coding { public abstract class Parser { @@ -44,7 +44,7 @@ namespace CrowEdit } #region CTOR - public Parser (CodeTextBuffer _buffer) + public Parser (CodeBuffer _buffer) { buffer = _buffer; Tokens = new List (); @@ -59,7 +59,7 @@ namespace CrowEdit protected Token currentTok; protected bool eof = true; - CodeTextBuffer buffer; + CodeBuffer buffer; public List Tokens; protected TokenList TokensLine; diff --git a/src/SourceEditor.cs b/src/SourceEditor.cs index a653b0e..f2304f9 100644 --- a/src/SourceEditor.cs +++ b/src/SourceEditor.cs @@ -36,7 +36,7 @@ using System.Linq; using System.Diagnostics; using CrowEdit; -namespace Crow +namespace Crow.Coding { public struct TextFormating { public Color Foreground; @@ -71,7 +71,7 @@ namespace Crow buffer.LineRemoveEvent += Buffer_LineRemoveEvent; buffer.BufferCleared += Buffer_BufferCleared; - parser = new CrowEdit.XMLParser (buffer); + parser = new XMLParser (buffer); } #endregion @@ -124,7 +124,7 @@ namespace Crow void Buffer_BufferCleared (object sender, EventArgs e) { - parser = new CrowEdit.XMLParser (buffer); + parser = new XMLParser (buffer); RegisterForGraphicUpdate (); } void reparseSource () { diff --git a/src/Token.cs b/src/Token.cs index e306c76..df9f66e 100644 --- a/src/Token.cs +++ b/src/Token.cs @@ -21,7 +21,7 @@ using System; using CrowEdit; -namespace Crow +namespace Crow.Coding { public struct Token { diff --git a/src/TokenList.cs b/src/TokenList.cs index 902c184..382bb23 100644 --- a/src/TokenList.cs +++ b/src/TokenList.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Crow +namespace Crow.Coding { public class TokenList : List { diff --git a/src/XMLParser.cs b/src/XMLParser.cs index 57c2f08..6e4a3ea 100644 --- a/src/XMLParser.cs +++ b/src/XMLParser.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Text.RegularExpressions; using System.Diagnostics; -namespace CrowEdit +namespace Crow.Coding { public class XMLParser : Parser {