comparison dwtx/jface/text/rules/WhitespaceRule.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13
14 module dwtx.jface.text.rules.WhitespaceRule;
15
16 import dwt.dwthelper.utils;
17
18
19 import dwtx.core.runtime.Assert;
20
21
22 /**
23 * An implementation of <code>IRule</code> capable of detecting whitespace.
24 * A whitespace rule uses a whitespace detector in order to find out which
25 * characters are whitespace characters.
26 *
27 * @see IWhitespaceDetector
28 */
29 public class WhitespaceRule : IRule {
30
31 /** The whitespace detector used by this rule */
32 protected IWhitespaceDetector fDetector;
33
34 /**
35 * Creates a rule which, with the help of an
36 * whitespace detector, will return a whitespace
37 * token when a whitespace is detected.
38 *
39 * @param detector the rule's whitespace detector, may not be <code>null</code>
40 */
41 public WhitespaceRule(IWhitespaceDetector detector) {
42 Assert.isNotNull(detector);
43 fDetector= detector;
44 }
45
46 /*
47 * @see IRule#evaluate(ICharacterScanner)
48 */
49 public IToken evaluate(ICharacterScanner scanner) {
50 int c= scanner.read();
51 if (fDetector.isWhitespace((char) c)) {
52 do {
53 c= scanner.read();
54 } while (fDetector.isWhitespace((char) c));
55 scanner.unread();
56 return Token.WHITESPACE;
57 }
58
59 scanner.unread();
60 return Token.UNDEFINED;
61 }
62 }