cvsimport
[beagle.git] / beagled / Lucene.Net / Analysis / KeywordTokenizer.cs
bloba69b41a84ca608af6a3f91d6d2b4f63e6a012e16
1 /*
2 * Copyright 2004-2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System;
19 namespace Lucene.Net.Analysis
22 /// <summary> Emits the entire input as a single token.</summary>
23 public class KeywordTokenizer : Tokenizer
26 private const int DEFAULT_BUFFER_SIZE = 256;
28 private bool done;
29 private char[] buffer;
31 public KeywordTokenizer(System.IO.TextReader input) : this(input, DEFAULT_BUFFER_SIZE)
35 public KeywordTokenizer(System.IO.TextReader input, int bufferSize) : base(input)
37 this.buffer = new char[bufferSize];
38 this.done = false;
41 public override Token Next()
43 if (!done)
45 done = true;
46 System.Text.StringBuilder buffer = new System.Text.StringBuilder();
47 int length;
48 while (true)
50 length = input.Read((System.Char[]) this.buffer, 0, this.buffer.Length);
51 if (length <= 0)
52 break;
54 buffer.Append(this.buffer, 0, length);
56 System.String text = buffer.ToString();
57 return new Token(text, 0, text.Length);
59 return null;