001: /*
002: * StandardSeparatorHandler.java: Implementation of the SeparatorHandler
003: *
004: * Copyright (C) 2002 Heiko Blau
005: *
006: * This file belongs to the JTopas Library.
007: * JTopas is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as published by the
009: * Free Software Foundation; either version 2.1 of the License, or (at your
010: * option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE.
015: * See the GNU Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License along
018: * with JTopas. If not, write to the
019: *
020: * Free Software Foundation, Inc.
021: * 59 Temple Place, Suite 330,
022: * Boston, MA 02111-1307
023: * USA
024: *
025: * or check the Internet: http://www.fsf.org
026: *
027: * Contact:
028: * email: heiko@susebox.de
029: */
030:
031: package de.susebox.jtopas.spi;
032:
033: //-----------------------------------------------------------------------------
034: // Imports
035: //
036: import de.susebox.jtopas.TokenizerProperty;
037: import de.susebox.jtopas.TokenizerProperties;
038: import de.susebox.jtopas.Flags;
039:
040: //-----------------------------------------------------------------------------
041: // class StandardSeparatorHandler
042: //
043:
044: /**<p>
045: * Simple implementation of the {@link SeparatorHandler} interface. This class
046: * works only with the {@link de.susebox.jtopas.TokenizerProperties} interface
047: * methods and is aware of changes in these properties. It does not cache any
048: * information and is therefore a more or less slow way to handle separators.
049: *</p><p>
050: * This class is a bridge between arbitrary {@link de.susebox.jtopas.Tokenizer}
051: * implementations using the SPI interface {@link SeparatorHandler} and any
052: * {@link de.susebox.jtopas.TokenizerProperties} implementation that does not
053: * implement the <code>SeparatorHandler</code> interface itself.
054: *</p>
055: *
056: * @see SeparatorHandler
057: * @see de.susebox.jtopas.Tokenizer
058: * @see de.susebox.jtopas.TokenizerProperties
059: * @author Heiko Blau
060: */
061: public class StandardSeparatorHandler implements SeparatorHandler {
062:
063: /**
064: * The constructor takes the {@link de.susebox.jtopas.TokenizerProperties}
065: * that provide the separators.
066: *
067: * @param props the {@link de.susebox.jtopas.TokenizerProperties} to take the
068: * separators from
069: */
070: public StandardSeparatorHandler(TokenizerProperties props) {
071: _properties = props;
072: }
073:
074: /**
075: * This method checks if the character is a separator.
076: *
077: * @param testChar check this character
078: * @return <code>true</code> if the given character is a separator,
079: * <code>false</code> otherwise
080: */
081: public boolean isSeparator(char testChar) {
082: String separators;
083:
084: if (_properties != null
085: && (separators = _properties.getWhitespaces()) != null) {
086: if (_properties.isFlagSet(Flags.F_NO_CASE)) {
087: return separators.toLowerCase().indexOf(
088: Character.toLowerCase(testChar)) >= 0;
089: } else {
090: return separators.indexOf(testChar) >= 0;
091: }
092: } else {
093: return false;
094: }
095: }
096:
097: //---------------------------------------------------------------------------
098: // Members
099: //
100:
101: /**
102: * The {@link TokenizerProperties} that provide the separators and the
103: * control flags.
104: */
105: private TokenizerProperties _properties = null;
106: }
|