]> O.S.I.I.S - jp/crowedit.git/commitdiff
Crow.Coding namespace, rename CodeTextBuffer->CodeBuffer
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 30 Aug 2017 17:16:58 +0000 (19:16 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 30 Aug 2017 17:16:58 +0000 (19:16 +0200)
CrowEdit.csproj
src/CSharpParser.cs
src/CodeBuffer.cs [new file with mode: 0644]
src/CodeTextBuffer.cs [deleted file]
src/Parser.cs
src/SourceEditor.cs
src/Token.cs
src/TokenList.cs
src/XMLParser.cs

index 6a66e49980dc107e09064d8ae6d1f95de11d6531..ea89cf2365e43d32d78068bc4e222f30c62d6eb9 100644 (file)
@@ -69,7 +69,6 @@
     <Compile Include="src\CrowEdit.cs" />
     <Compile Include="src\CrowEditExtentions.cs" />
     <Compile Include="src\Token.cs" />
-    <Compile Include="src\CodeTextBuffer.cs" />
     <Compile Include="CrowWindow.cs" />
     <Compile Include="InterfaceControler.cs" />
     <Compile Include="OpenGL\Extensions.cs" />
@@ -81,6 +80,7 @@
     <Compile Include="src\XMLParser.cs" />
     <Compile Include="src\CSharpParser.cs" />
     <Compile Include="src\TokenList.cs" />
+    <Compile Include="src\CodeBuffer.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="ui\" />
index 8105b8980087b61e627c18d846d548a43c6b997e..f9d7cbae0c926230d9f7f738edffbd7ce1ac0512 100644 (file)
@@ -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 (file)
index 0000000..ab764f7
--- /dev/null
@@ -0,0 +1,149 @@
+//
+//  CodeTextBuffer.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  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 <http://www.gnu.org/licenses/>.
+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<CodeBufferEventArgs> LineUpadateEvent;
+               public event EventHandler<CodeBufferEventArgs> LineRemoveEvent;
+               public event EventHandler<CodeBufferEventArgs> LineAdditionEvent;
+               public event EventHandler BufferCleared;
+               #endregion
+
+               #region CTOR
+               public CodeTextBuffer () : base() {}
+               #endregion
+
+
+               List<string> lines = new List<string>();
+
+               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;
+                               }
+                       }
+               }
+               /// <summary> line break could be '\r' or '\n' or '\r\n' </summary>
+               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;
+               }
+               /// <summary>
+               /// return all lines with linebreaks
+               /// </summary>
+               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 (file)
index b218ae3..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-//
-//  CodeTextBuffer.cs
-//
-//  Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-//  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 <http://www.gnu.org/licenses/>.
-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<CodeBufferEventArgs> LineUpadateEvent;
-               public event EventHandler<CodeBufferEventArgs> LineRemoveEvent;
-               public event EventHandler<CodeBufferEventArgs> LineAdditionEvent;
-               public event EventHandler BufferCleared;
-               #endregion
-
-               #region CTOR
-               public CodeTextBuffer () : base() {}
-               #endregion
-
-
-               List<string> lines = new List<string>();
-
-               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;
-                               }
-                       }
-               }
-               /// <summary> line break could be '\r' or '\n' or '\r\n' </summary>
-               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;
-               }
-               /// <summary>
-               /// return all lines with linebreaks
-               /// </summary>
-               public string FullText{
-                       get {
-                               return lines.Count > 0 ? lines.Aggregate((i, j) => i + this.lineBreak + j) : "";
-                       }
-               }
-       }
-}
-
index 19c3df4ac1c920f2aeba6d5b43e9f1cd63e6746c..4d5b0ce5f8792048450999e29edfb9397316392f 100644 (file)
@@ -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<TokenList> ();
@@ -59,7 +59,7 @@ namespace CrowEdit
                protected Token currentTok;
                protected bool eof = true;
 
-               CodeTextBuffer buffer;
+               CodeBuffer buffer;
 
                public List<TokenList> Tokens;
                protected TokenList TokensLine;
index a653b0e239f5ba40b19167b768250e533dc91f38..f2304f9e191eb32a61dcf6ae84e807fcafcb70b8 100644 (file)
@@ -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 () {
index e306c763c2b11d16c01736579bdba6fb037069f6..df9f66e7ec3bf54aa1aec1bc9b539de5b71f9671 100644 (file)
@@ -21,7 +21,7 @@
 using System;
 using CrowEdit;
 
-namespace Crow
+namespace Crow.Coding
 {
        public struct Token
        {
index 902c184d7a50fe44c120f6a5c11d31db715c8853..382bb23c001bd9fd83bdc697822059c24fb1586a 100644 (file)
@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 
-namespace Crow
+namespace Crow.Coding
 {
        public class TokenList : List<Token>
        {
index 57c2f08484076353d09f6840ab9ea22d86361ee4..6e4a3ea111ee52c001d14738744218e487117681 100644 (file)
@@ -4,7 +4,7 @@ using System.Collections.Generic;
 using System.Text.RegularExpressions;
 using System.Diagnostics;
 
-namespace CrowEdit
+namespace Crow.Coding
 {
        public class XMLParser : Parser
        {