|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #ifndef TINYANALYSIS_INL_ |
|
18 #define TINYANALYSIS_INL_ |
|
19 |
|
20 #include "CLucene.h" |
|
21 |
|
22 /* |
|
23 * TODO: |
|
24 * |
|
25 * Move more functionality in here |
|
26 * |
|
27 */ |
|
28 |
|
29 namespace analysis { |
|
30 namespace tiny { |
|
31 namespace cl { |
|
32 |
|
33 template<int SIZE> |
|
34 wchar_t ReaderBuffer<SIZE>::operator[](int i) |
|
35 { |
|
36 if ( i < read_ - SIZE ) throw TooOldIndexException(); |
|
37 // fill |
|
38 while (i >= read_) { |
|
39 int c = reader_.read(); |
|
40 buf_[cut_++] = ( c == -1 ? '\0' : c ); |
|
41 cut_ %= SIZE; |
|
42 if (read_++ >= SIZE) { |
|
43 offset_++; |
|
44 } |
|
45 } |
|
46 // guaranteed that i < read |
|
47 return buf_[i % SIZE]; |
|
48 } |
|
49 |
|
50 template<int SIZE> |
|
51 ReaderBuffer<SIZE>::ReaderBuffer(lucene::util::Reader& reader) |
|
52 : reader_(reader), read_(0), cut_(0), offset_(0) {} |
|
53 |
|
54 template<int SIZE> |
|
55 typename ReaderBuffer<SIZE>::iterator ReaderBuffer<SIZE>::at(int i) { |
|
56 return iterator(*this, i); |
|
57 } |
|
58 |
|
59 template<int SIZE> |
|
60 typename ReaderBuffer<SIZE>::iterator ReaderBuffer<SIZE>::begin() { |
|
61 return iterator(*this, 0); |
|
62 } |
|
63 |
|
64 } |
|
65 |
|
66 template <typename Iterator> |
|
67 void Token<Iterator>::copyTo(lucene::analysis::Token* token) { |
|
68 token->resetTermTextLen(); |
|
69 token->growBuffer(utf16size()+1); |
|
70 token->setPositionIncrement(1); |
|
71 Utf16Writer<wchar_t*> out(token->_termText); |
|
72 Iterator i = begin_; |
|
73 token->setStartOffset(i); |
|
74 for (int n = length_; n; n--) { |
|
75 out<<*i; ++i; |
|
76 } |
|
77 out<<L'\0'; |
|
78 token->setEndOffset(i); |
|
79 } |
|
80 |
|
81 } |
|
82 } |
|
83 |
|
84 #endif /* TINYANALYSIS_INL_ */ |