1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_i18npool.hxx"
26
27 // prevent internal compiler error with MSVC6SP3
28 #include <utility>
29
30 #include <i18nutil/widthfolding.hxx>
31 #define TRANSLITERATION_fullwidthToHalfwidth
32 #define TRANSLITERATION_fullwidthKatakanaToHalfwidthKatakana
33 #define TRANSLITERATION_fullwidthToHalfwidthLikeASC
34 #include <transliteration_OneToOne.hxx>
35
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::lang;
38 using namespace rtl;
39
40 namespace com { namespace sun { namespace star { namespace i18n {
41
fullwidthToHalfwidth()42 fullwidthToHalfwidth::fullwidthToHalfwidth()
43 {
44 func = (TransFunc) 0;
45 table = &widthfolding::getfull2halfTable();
46 transliterationName = "fullwidthToHalfwidth";
47 implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH";
48 }
49
50 /**
51 * Transliterate fullwidth to halfwidth.
52 * The output is a reference of OUString. You MUST delete this object when you do not need to use it any more
53 * The output string contains a transliterated string only, not whole string.
54 */
55 OUString SAL_CALL
transliterate(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount,Sequence<sal_Int32> & offset)56 fullwidthToHalfwidth::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
57 throw(RuntimeException)
58 {
59 // Decomposition: GA --> KA + voice-mark
60 const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
61
62 // One to One mapping
63 useOffset = sal_False;
64 const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
65 useOffset = sal_True;
66 return tmp;
67 }
68
69 sal_Unicode SAL_CALL
transliterateChar2Char(sal_Unicode inChar)70 fullwidthToHalfwidth::transliterateChar2Char( sal_Unicode inChar)
71 throw(RuntimeException, MultipleCharsOutputException)
72 {
73 sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
74 if (newChar == 0xFFFF)
75 throw MultipleCharsOutputException();
76 return transliteration_OneToOne::transliterateChar2Char(inChar);
77 }
78
fullwidthKatakanaToHalfwidthKatakana()79 fullwidthKatakanaToHalfwidthKatakana::fullwidthKatakanaToHalfwidthKatakana()
80 {
81 func = (TransFunc) 0;
82 table = &widthfolding::getfullKana2halfKanaTable();
83 transliterationName = "fullwidthKatakanaToHalfwidthKatakana";
84 implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTHKATAKANA_HALFWIDTHKATAKANA";
85 }
86
87 /**
88 * Transliterate fullwidth katakana to halfwidth katakana.
89 */
90 OUString SAL_CALL
transliterate(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount,Sequence<sal_Int32> & offset)91 fullwidthKatakanaToHalfwidthKatakana::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
92 throw(RuntimeException)
93 {
94 // Decomposition: GA --> KA + voice-mark
95 const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
96
97 // One to One mapping
98 useOffset = sal_False;
99 const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
100 useOffset = sal_True;
101 return tmp;
102 }
103
104 sal_Unicode SAL_CALL
transliterateChar2Char(sal_Unicode inChar)105 fullwidthKatakanaToHalfwidthKatakana::transliterateChar2Char( sal_Unicode inChar )
106 throw(RuntimeException, MultipleCharsOutputException)
107 {
108 sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
109 if (newChar == 0xFFFF)
110 throw MultipleCharsOutputException();
111 return transliteration_OneToOne::transliterateChar2Char(inChar);
112 }
113
fullwidthToHalfwidthLikeASC()114 fullwidthToHalfwidthLikeASC::fullwidthToHalfwidthLikeASC()
115 {
116 func = (TransFunc) 0;
117 table = &widthfolding::getfull2halfTableForASC();
118 transliterationName = "fullwidthToHalfwidthLikeASC";
119 implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH_LIKE_ASC";
120 }
121
122 /**
123 * Transliterate fullwidth to halfwidth like Excel's ASC function.
124 */
125 OUString SAL_CALL
transliterate(const OUString & inStr,sal_Int32 startPos,sal_Int32 nCount,Sequence<sal_Int32> & offset)126 fullwidthToHalfwidthLikeASC::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
127 throw(RuntimeException)
128 {
129 // Decomposition: GA --> KA + voice-mark
130 const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
131
132 // One to One mapping
133 useOffset = sal_False;
134 const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
135 useOffset = sal_True;
136
137 return tmp;
138 }
139
140 sal_Unicode SAL_CALL
transliterateChar2Char(sal_Unicode inChar)141 fullwidthToHalfwidthLikeASC::transliterateChar2Char( sal_Unicode inChar )
142 throw(RuntimeException, MultipleCharsOutputException)
143 {
144 sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
145 if (newChar == 0xFFFF)
146 throw MultipleCharsOutputException();
147 return transliteration_OneToOne::transliterateChar2Char(inChar);
148 }
149
150 } } } }
151
152