Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <i18nutil/widthfolding.hxx>
21 :
22 : #include <transliteration_OneToOne.hxx>
23 :
24 : using namespace com::sun::star::uno;
25 : using namespace com::sun::star::lang;
26 :
27 : namespace com { namespace sun { namespace star { namespace i18n {
28 :
29 22 : fullwidthToHalfwidth::fullwidthToHalfwidth()
30 : {
31 22 : func = (TransFunc) 0;
32 22 : table = &widthfolding::getfull2halfTable();
33 22 : transliterationName = "fullwidthToHalfwidth";
34 22 : implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH";
35 22 : }
36 :
37 : /**
38 : * Transliterate fullwidth to halfwidth.
39 : * The output is a reference of OUString. You MUST delete this object when you do not need to use it any more
40 : * The output string contains a transliterated string only, not whole string.
41 : */
42 : OUString SAL_CALL
43 22 : fullwidthToHalfwidth::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
44 : throw(RuntimeException, std::exception)
45 : {
46 : // Decomposition: GA --> KA + voice-mark
47 22 : const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
48 :
49 : // One to One mapping
50 22 : useOffset = false;
51 44 : const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
52 22 : useOffset = true;
53 44 : return tmp;
54 : }
55 :
56 : sal_Unicode SAL_CALL
57 0 : fullwidthToHalfwidth::transliterateChar2Char( sal_Unicode inChar)
58 : throw(RuntimeException, MultipleCharsOutputException, std::exception)
59 : {
60 0 : sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
61 0 : if (newChar == 0xFFFF)
62 0 : throw MultipleCharsOutputException();
63 0 : return transliteration_OneToOne::transliterateChar2Char(inChar);
64 : }
65 :
66 0 : fullwidthKatakanaToHalfwidthKatakana::fullwidthKatakanaToHalfwidthKatakana()
67 : {
68 0 : func = (TransFunc) 0;
69 0 : table = &widthfolding::getfullKana2halfKanaTable();
70 0 : transliterationName = "fullwidthKatakanaToHalfwidthKatakana";
71 0 : implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTHKATAKANA_HALFWIDTHKATAKANA";
72 0 : }
73 :
74 : /**
75 : * Transliterate fullwidth katakana to halfwidth katakana.
76 : */
77 : OUString SAL_CALL
78 0 : fullwidthKatakanaToHalfwidthKatakana::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
79 : throw(RuntimeException, std::exception)
80 : {
81 : // Decomposition: GA --> KA + voice-mark
82 0 : const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
83 :
84 : // One to One mapping
85 0 : useOffset = false;
86 0 : const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
87 0 : useOffset = true;
88 0 : return tmp;
89 : }
90 :
91 : sal_Unicode SAL_CALL
92 0 : fullwidthKatakanaToHalfwidthKatakana::transliterateChar2Char( sal_Unicode inChar )
93 : throw(RuntimeException, MultipleCharsOutputException, std::exception)
94 : {
95 0 : sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
96 0 : if (newChar == 0xFFFF)
97 0 : throw MultipleCharsOutputException();
98 0 : return transliteration_OneToOne::transliterateChar2Char(inChar);
99 : }
100 :
101 2 : fullwidthToHalfwidthLikeASC::fullwidthToHalfwidthLikeASC()
102 : {
103 2 : func = (TransFunc) 0;
104 2 : table = &widthfolding::getfull2halfTableForASC();
105 2 : transliterationName = "fullwidthToHalfwidthLikeASC";
106 2 : implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH_LIKE_ASC";
107 2 : }
108 :
109 : /**
110 : * Transliterate fullwidth to halfwidth like Excel's ASC function.
111 : */
112 : OUString SAL_CALL
113 2 : fullwidthToHalfwidthLikeASC::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
114 : throw(RuntimeException, std::exception)
115 : {
116 : // Decomposition: GA --> KA + voice-mark
117 2 : const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
118 :
119 : // One to One mapping
120 2 : useOffset = false;
121 4 : const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
122 2 : useOffset = true;
123 :
124 4 : return tmp;
125 : }
126 :
127 : sal_Unicode SAL_CALL
128 0 : fullwidthToHalfwidthLikeASC::transliterateChar2Char( sal_Unicode inChar )
129 : throw(RuntimeException, MultipleCharsOutputException, std::exception)
130 : {
131 0 : sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
132 0 : if (newChar == 0xFFFF)
133 0 : throw MultipleCharsOutputException();
134 0 : return transliteration_OneToOne::transliterateChar2Char(inChar);
135 : }
136 :
137 : } } } }
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|