X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;ds=sidebyside;f=Core%2FTest%2FXmlHilighter.cs;fp=Common%2FTest%2FXmlHilighter.cs;h=b489fdc456a52944539bf679be5320e50e2e0c57;hb=4f5291ad69ffaa783529a5fad93a2f9d67352dbc;hp=47edd41de94992c1776b09a521ccf3d8829d7e1a;hpb=b9fb4df56e6716015915db076f3ce208f9b86ef4;p=fooeditengine%2FFooEditEngine.git
diff --git a/Common/Test/XmlHilighter.cs b/Core/Test/XmlHilighter.cs
similarity index 96%
rename from Common/Test/XmlHilighter.cs
rename to Core/Test/XmlHilighter.cs
index 47edd41..b489fdc 100644
--- a/Common/Test/XmlHilighter.cs
+++ b/Core/Test/XmlHilighter.cs
@@ -1,204 +1,207 @@
-/*
- * Copyright (C) 2013 FooProject
- * * 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.Text;
-using FooEditEngine;
-
-namespace Test
-{
- enum TextParserMode
- {
- Literal,
- ScriptPart,
- MultiLineComment,
- TextPart,
- }
- class XmlHilighter : IHilighter
- {
- private TextParserMode mode;
- private StringBuilder word;
- private TokenType KeyWordType;
-
- public XmlHilighter()
- {
- this.word = new StringBuilder();
- this.Reset();
- }
-
- #region IHilighter ã¡ã³ãã¼
-
- public void Reset()
- {
- this.mode = TextParserMode.TextPart;
- this.KeyWordType = TokenType.None;
- this.word.Clear();
- }
-
- public int DoHilight(string text, int length, TokenSpilitHandeler action)
- {
- int encloserLevel = 0;
- int i,wordPos = 0;
- for (i = 0; i < length;)
- {
- if (IsMatch(text,i,""))
- {
- encloserLevel--;
- if (TransModeAndAction(TextParserMode.TextPart, action, word, 3, true, ref i, wordPos))
- break;
- }
- else if (text[i] == '<' && this.mode != TextParserMode.MultiLineComment)
- {
- encloserLevel++;
- if (TransModeAndAction(TextParserMode.ScriptPart, action, word, 1, true, ref i, wordPos))
- break;
- this.KeyWordType = TokenType.Keyword1;
- }
- else if (text[i] == '>' && this.mode == TextParserMode.ScriptPart)
- {
- encloserLevel--;
- if (TransModeAndAction(TextParserMode.TextPart, action, word, 1, false, ref i, wordPos))
- break;
- }
- else if (IsMatch(text, i, "![CDATA[") && this.mode == TextParserMode.ScriptPart)
- {
- encloserLevel++;
- if (TransModeAndAction(TextParserMode.Literal, action, word, 8, false, ref i, wordPos))
- break;
- }
- else if ((text[i] == '\"' || text[i] == '\'') && this.mode == TextParserMode.ScriptPart)
- {
- encloserLevel++;
- if (TransModeAndAction(TextParserMode.Literal, action, word, 1, false, ref i, wordPos))
- break;
- }
- else if ((text[i] == '\"' || text[i] == '\'' ) && this.mode == TextParserMode.Literal)
- {
- encloserLevel--;
- if (TransModeAndAction(TextParserMode.ScriptPart, action, word, 1, true, ref i, wordPos))
- break;
- }
- else if (IsMatch(text, i, "]]") && this.mode == TextParserMode.Literal)
- {
- encloserLevel--;
- if (TransModeAndAction(TextParserMode.ScriptPart, action, word, 2, true, ref i, wordPos))
- break;
- }
- else if (text[i] == ' ')
- {
- if (TransModeAndAction(this.mode, action, word, 1, false, ref i, wordPos))
- break;
- this.KeyWordType = TokenType.Keyword2;
- }
- else if (text[i] == '=')
- {
- if (TransModeAndAction(this.mode, action, word, 1, false, ref i, wordPos))
- break;
- this.KeyWordType = TokenType.None;
- }
- else
- {
- if (word.Length == 0)
- wordPos = i;
- word.Append(text[i]);
- i++;
- continue;
- }
- }
-
- if (word.Length > 0)
- {
- action(new TokenSpilitEventArgs(wordPos,word.Length, GetMode(this.mode,KeyWordType)));
- word.Clear();
- }
-
- return encloserLevel;
- }
-
- #endregion
-
- ///
- /// æååãä¸è´ãããã©ãã確ããã
- ///
- /// æ¤æ»ãããæåå
- /// æ¤æ»ãéå§ããã¤ã³ããã¯ã¹
- /// æ¤æ»å¯¾è±¡ã®æåå
- ///
- private bool IsMatch(string s, int index, string pattern)
- {
- if (index + pattern.Length >= s.Length)
- return false;
- bool result = false;
- for (int i = index, j = 0; i < index + pattern.Length; i++, j++)
- {
- if ((j == 0 || j > 0 && result) && s[i] == pattern[j])
- result = true;
- else
- result = false;
- }
-
- return result;
- }
-
- private bool TransModeAndAction(TextParserMode toMode, TokenSpilitHandeler action, StringBuilder word, int tokenLength, bool TranAfterAction, ref int index, int wordPos)
- {
- TokenSpilitEventArgs e = new TokenSpilitEventArgs();
-
- if (word.Length > 0)
- {
- e.index = wordPos;
- e.length = word.Length;
- e.type = GetMode(this.mode, this.KeyWordType);
- action(e);
- word.Clear();
- if (e.breaked)
- return true;
- }
-
- if (TranAfterAction == false)
- this.mode = toMode;
-
- e.index = index;
- e.length = tokenLength;
- e.type = GetMode(this.mode, TokenType.None);
- action(e);
- if (e.breaked)
- return true;
-
- if (TranAfterAction)
- this.mode = toMode;
-
- index += tokenLength;
-
- return false;
- }
-
- private TokenType GetMode(TextParserMode mode,TokenType isKeyword)
- {
- switch (mode)
- {
- case TextParserMode.Literal:
- return TokenType.Literal;
- case TextParserMode.ScriptPart:
- return isKeyword;
- case TextParserMode.MultiLineComment:
- return TokenType.Comment;
- default:
- return TokenType.None;
- }
- }
- }
-}
+/*
+ * Copyright (C) 2013 FooProject
+ * * 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.Text;
+using FooEditEngine;
+
+namespace FooEditEngine.Test
+{
+ enum TextParserMode
+ {
+ Literal,
+ ScriptPart,
+ MultiLineComment,
+ TextPart,
+ }
+ ///
+ /// XMLããã¥ã¡ã³ãç¨ãã¤ã©ã¤ã¿ã¼
+ ///
+ public class XmlHilighter : IHilighter
+ {
+ private TextParserMode mode;
+ private StringBuilder word;
+ private TokenType KeyWordType;
+
+ public XmlHilighter()
+ {
+ this.word = new StringBuilder();
+ this.Reset();
+ }
+
+ #region IHilighter ã¡ã³ãã¼
+
+ public void Reset()
+ {
+ this.mode = TextParserMode.TextPart;
+ this.KeyWordType = TokenType.None;
+ this.word.Clear();
+ }
+
+ public int DoHilight(string text, int length, TokenSpilitHandeler action)
+ {
+ int encloserLevel = 0;
+ int i,wordPos = 0;
+ for (i = 0; i < length;)
+ {
+ if (IsMatch(text,i,""))
+ {
+ encloserLevel--;
+ if (TransModeAndAction(TextParserMode.TextPart, action, word, 3, true, ref i, wordPos))
+ break;
+ }
+ else if (text[i] == '<' && this.mode != TextParserMode.MultiLineComment)
+ {
+ encloserLevel++;
+ if (TransModeAndAction(TextParserMode.ScriptPart, action, word, 1, true, ref i, wordPos))
+ break;
+ this.KeyWordType = TokenType.Keyword1;
+ }
+ else if (text[i] == '>' && this.mode == TextParserMode.ScriptPart)
+ {
+ encloserLevel--;
+ if (TransModeAndAction(TextParserMode.TextPart, action, word, 1, false, ref i, wordPos))
+ break;
+ }
+ else if (IsMatch(text, i, "![CDATA[") && this.mode == TextParserMode.ScriptPart)
+ {
+ encloserLevel++;
+ if (TransModeAndAction(TextParserMode.Literal, action, word, 8, false, ref i, wordPos))
+ break;
+ }
+ else if ((text[i] == '\"' || text[i] == '\'') && this.mode == TextParserMode.ScriptPart)
+ {
+ encloserLevel++;
+ if (TransModeAndAction(TextParserMode.Literal, action, word, 1, false, ref i, wordPos))
+ break;
+ }
+ else if ((text[i] == '\"' || text[i] == '\'' ) && this.mode == TextParserMode.Literal)
+ {
+ encloserLevel--;
+ if (TransModeAndAction(TextParserMode.ScriptPart, action, word, 1, true, ref i, wordPos))
+ break;
+ }
+ else if (IsMatch(text, i, "]]") && this.mode == TextParserMode.Literal)
+ {
+ encloserLevel--;
+ if (TransModeAndAction(TextParserMode.ScriptPart, action, word, 2, true, ref i, wordPos))
+ break;
+ }
+ else if (text[i] == ' ')
+ {
+ if (TransModeAndAction(this.mode, action, word, 1, false, ref i, wordPos))
+ break;
+ this.KeyWordType = TokenType.Keyword2;
+ }
+ else if (text[i] == '=')
+ {
+ if (TransModeAndAction(this.mode, action, word, 1, false, ref i, wordPos))
+ break;
+ this.KeyWordType = TokenType.None;
+ }
+ else
+ {
+ if (word.Length == 0)
+ wordPos = i;
+ word.Append(text[i]);
+ i++;
+ continue;
+ }
+ }
+
+ if (word.Length > 0)
+ {
+ action(new TokenSpilitEventArgs(wordPos,word.Length, GetMode(this.mode,KeyWordType)));
+ word.Clear();
+ }
+
+ return encloserLevel;
+ }
+
+ #endregion
+
+ ///
+ /// æååãä¸è´ãããã©ãã確ããã
+ ///
+ /// æ¤æ»ãããæåå
+ /// æ¤æ»ãéå§ããã¤ã³ããã¯ã¹
+ /// æ¤æ»å¯¾è±¡ã®æåå
+ ///
+ private bool IsMatch(string s, int index, string pattern)
+ {
+ if (index + pattern.Length >= s.Length)
+ return false;
+ bool result = false;
+ for (int i = index, j = 0; i < index + pattern.Length; i++, j++)
+ {
+ if ((j == 0 || j > 0 && result) && s[i] == pattern[j])
+ result = true;
+ else
+ result = false;
+ }
+
+ return result;
+ }
+
+ private bool TransModeAndAction(TextParserMode toMode, TokenSpilitHandeler action, StringBuilder word, int tokenLength, bool TranAfterAction, ref int index, int wordPos)
+ {
+ TokenSpilitEventArgs e = new TokenSpilitEventArgs();
+
+ if (word.Length > 0)
+ {
+ e.index = wordPos;
+ e.length = word.Length;
+ e.type = GetMode(this.mode, this.KeyWordType);
+ action(e);
+ word.Clear();
+ if (e.breaked)
+ return true;
+ }
+
+ if (TranAfterAction == false)
+ this.mode = toMode;
+
+ e.index = index;
+ e.length = tokenLength;
+ e.type = GetMode(this.mode, TokenType.None);
+ action(e);
+ if (e.breaked)
+ return true;
+
+ if (TranAfterAction)
+ this.mode = toMode;
+
+ index += tokenLength;
+
+ return false;
+ }
+
+ private TokenType GetMode(TextParserMode mode,TokenType isKeyword)
+ {
+ switch (mode)
+ {
+ case TextParserMode.Literal:
+ return TokenType.Literal;
+ case TextParserMode.ScriptPart:
+ return isKeyword;
+ case TextParserMode.MultiLineComment:
+ return TokenType.Comment;
+ default:
+ return TokenType.None;
+ }
+ }
+ }
+}