2 * Copyright (C) 2013 FooProject
3 * * 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
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
12 using System.Collections.Generic;
16 namespace FooEditEngine.Test
21 public class CharFoldingMethod : IFoldingStrategy
23 public CharFoldingMethod(char begin, char end)
25 this.BeginChar = begin;
47 public IEnumerable<FoldingItem> AnalyzeDocument(Document doc, int start, int end)
49 Stack<int> BeginIndexColletion = new Stack<int>();
50 for (int i = start; i <= end; i++)
52 if (doc[i] == this.BeginChar)
53 BeginIndexColletion.Push(i);
54 if (doc[i] == this.EndChar)
56 if (BeginIndexColletion.Count == 0)
58 int beginIndex = BeginIndexColletion.Pop();
61 yield return new FoldingItem(beginIndex, i);