~ubuntu-branches/ubuntu/raring/clucene-core/raring-proposed

« back to all changes in this revision

Viewing changes to src/contribs-lib/CLucene/highlighter/SimpleHTMLEncoder.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-08-11 09:33:38 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120811093338-fgrx41ftqew3qt6a
Tags: 2.3.3.4-1
* New upstream release (Closes: #661703).
* Convert package to multiarch.
* Drop obsolete patches:
  - 01_add_missing_include_bug505667.diff
  - 02_posixness_fix_bug530308.diff
* Add patches:
  - Fixing_ZLIB_configuration_in_shared_CMakeLists.patch
  - Fix-pkgconfig-file-by-adding-clucene-shared-library.patch
  - Install-contribs-lib.patch
  - multiarch.patch
* Update debian/compat: bump to 8.
* Update debian/control:
  - update build dependencies (add cmake, libboost-dev and libz-dev).
  - bump Standards-Version to 3.9.3.
  - rename packages due to ABI bump: libclucene0ldbl -> libclucene-core1.
  - add libclucene-contribs1 package.
* Update debian/rules:
  - rewrite to use CMake.
  - add multiarch support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2002-2004 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.
 
15
 */
 
16
 
 
17
#include "CLucene/_ApiHeader.h"
 
18
#include "SimpleHTMLEncoder.h"
 
19
#include "Formatter.h"
 
20
#include "CLucene/util/StringBuffer.h"
 
21
 
 
22
CL_NS_DEF2(search,highlight)
 
23
 
 
24
SimpleHTMLEncoder::SimpleHTMLEncoder(void)
 
25
{
 
26
}
 
27
 
 
28
SimpleHTMLEncoder::~SimpleHTMLEncoder(void)
 
29
{
 
30
}
 
31
 
 
32
TCHAR* SimpleHTMLEncoder::encodeText(TCHAR* originalText)
 
33
{
 
34
        return htmlEncode(originalText);
 
35
}
 
36
 
 
37
TCHAR* SimpleHTMLEncoder::htmlEncode(TCHAR* plainText) 
 
38
{
 
39
        size_t plainTextLen = _tcslen(plainText);
 
40
        if (plainText == NULL || plainTextLen == 0)
 
41
        {
 
42
                return STRDUP_TtoT(_T(""));
 
43
        }
 
44
 
 
45
        CL_NS(util)::StringBuffer result(plainTextLen);
 
46
 
 
47
        for (int32_t index=0; index<plainTextLen; index++) 
 
48
        {
 
49
                TCHAR ch = plainText[index];
 
50
 
 
51
                switch (ch) 
 
52
                {
 
53
                case '"':
 
54
                        result.append(_T("&quot;"));
 
55
                        break;
 
56
 
 
57
                case '&':
 
58
                        result.append(_T("&amp;"));
 
59
                        break;
 
60
 
 
61
                case '<':
 
62
                        result.append(_T("&lt;"));
 
63
                        break;
 
64
 
 
65
                case '>':
 
66
                        result.append(_T("&gt;"));
 
67
                        break;
 
68
 
 
69
                default:
 
70
                        if (ch < 128)
 
71
                                result.appendChar(ch);
 
72
                        else{
 
73
                    result.append(_T("&#"));
 
74
                                result.appendInt(ch);
 
75
                                result.append(_T(";"));
 
76
                        }
 
77
                }
 
78
        }
 
79
 
 
80
        return result.toString();
 
81
}
 
82
 
 
83
CL_NS_END2