OSDN Git Service

Remove unused variable.
[neighbornote/NeighborNote.git] / src / com / swabunga / spell / event / XMLWordFinder.java
1 /*\r
2 Jazzy - a Java library for Spell Checking\r
3 Copyright (C) 2001 Mindaugas Idzelis\r
4 Full text of license can be found in LICENSE.txt\r
5 \r
6 This library is free software; you can redistribute it and/or\r
7 modify it under the terms of the GNU Lesser General Public\r
8 License as published by the Free Software Foundation; either\r
9 version 2.1 of the License, or (at your option) any later version.\r
10 \r
11 This library is distributed in the hope that it will be useful,\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
14 Lesser General Public License for more details.\r
15 \r
16 You should have received a copy of the GNU Lesser General Public\r
17 License along with this library; if not, write to the Free Software\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
19 */\r
20 //:folding=indent:\r
21 package com.swabunga.spell.event;\r
22 \r
23 \r
24 /**\r
25  * A word finder for XML or HTML documents, which searches text for sequences\r
26  * of letters, but ignores the text inside any tags.\r
27  *\r
28  * @author Anthony Roy  (ajr@antroy.co.uk)\r
29  */\r
30 public class XMLWordFinder extends AbstractWordFinder {\r
31 \r
32   //~ Instance/static variables ...............................................\r
33 \r
34   //~ Constructors ............................................................\r
35 \r
36   /**\r
37    * Creates a new DefaultWordFinder object.\r
38    *\r
39    * @param inText the text to search.\r
40    */\r
41   public XMLWordFinder(String inText) {\r
42     super(inText);\r
43   }\r
44 \r
45   //~ Methods .................................................................\r
46 \r
47   /**\r
48    * This method scans the text from the end of the last word,  and returns a\r
49    * new Word object corresponding to the next word.\r
50    *\r
51    * @return the next word.\r
52    * @throws WordNotFoundException search string contains no more words.\r
53    */\r
54   public Word next() {\r
55 \r
56     if (currentWord == null)\r
57       throw new WordNotFoundException("No more words found.");\r
58 \r
59     currentWord.copy(nextWord);\r
60 \r
61     setSentenceIterator(currentWord);\r
62 \r
63     int i = currentWord.getEnd();\r
64     boolean finished = false;\r
65     boolean started = false;\r
66 \r
67     search:      /* Find words. */\r
68     while (i < text.length() && !finished) {\r
69       if (!started && isWordChar(i)) {\r
70         nextWord.setStart(i++);\r
71         started = true;\r
72         continue search;\r
73       } else if (started) {\r
74         if (isWordChar(i)) {\r
75           i++;\r
76           continue search;\r
77         } else {\r
78           nextWord.setText(text.substring(nextWord.getStart(), i));\r
79           finished = true;\r
80           break search;\r
81         }\r
82       }\r
83 \r
84       //Ignore things inside tags.\r
85       int i2 = ignore(i, '<', '>');\r
86       i = (i2 == i ? i + 1 : i2);\r
87     }\r
88 \r
89     if (!started) {\r
90       nextWord = null;\r
91     } else if (!finished) {\r
92       nextWord.setText(text.substring(nextWord.getStart(), i));\r
93     }\r
94 \r
95     return currentWord;\r
96   }\r
97 }\r