1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_i18npool.hxx"
30 
31 // prevent internal compiler error with MSVC6SP3
32 #include <utility>
33 
34 #include <i18nutil/widthfolding.hxx>
35 #define TRANSLITERATION_fullwidthToHalfwidth
36 #define TRANSLITERATION_fullwidthKatakanaToHalfwidthKatakana
37 #define TRANSLITERATION_fullwidthToHalfwidthLikeASC
38 #include <transliteration_OneToOne.hxx>
39 
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace rtl;
43 
44 namespace com { namespace sun { namespace star { namespace i18n {
45 
46 fullwidthToHalfwidth::fullwidthToHalfwidth()
47 {
48     func = (TransFunc) 0;
49     table = &widthfolding::getfull2halfTable();
50     transliterationName = "fullwidthToHalfwidth";
51     implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH";
52 }
53 
54 /**
55  * Transliterate fullwidth to halfwidth.
56  * The output is a reference of OUString. You MUST delete this object when you do not need to use it any more
57  * The output string contains a transliterated string only, not whole string.
58  */
59 OUString SAL_CALL
60 fullwidthToHalfwidth::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
61   throw(RuntimeException)
62 {
63     // Decomposition: GA --> KA + voice-mark
64     const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
65 
66     // One to One mapping
67     useOffset = sal_False;
68     const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
69     useOffset = sal_True;
70     return tmp;
71 }
72 
73 sal_Unicode SAL_CALL
74 fullwidthToHalfwidth::transliterateChar2Char( sal_Unicode inChar)
75   throw(RuntimeException, MultipleCharsOutputException)
76 {
77     sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
78     if (newChar == 0xFFFF)
79         throw MultipleCharsOutputException();
80     return transliteration_OneToOne::transliterateChar2Char(inChar);
81 }
82 
83 fullwidthKatakanaToHalfwidthKatakana::fullwidthKatakanaToHalfwidthKatakana()
84 {
85     func = (TransFunc) 0;
86     table = &widthfolding::getfullKana2halfKanaTable();
87     transliterationName = "fullwidthKatakanaToHalfwidthKatakana";
88     implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTHKATAKANA_HALFWIDTHKATAKANA";
89 }
90 
91 /**
92  * Transliterate fullwidth katakana to halfwidth katakana.
93  */
94 OUString SAL_CALL
95 fullwidthKatakanaToHalfwidthKatakana::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
96   throw(RuntimeException)
97 {
98     // Decomposition: GA --> KA + voice-mark
99     const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
100 
101     // One to One mapping
102     useOffset = sal_False;
103     const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
104     useOffset = sal_True;
105     return tmp;
106 }
107 
108 sal_Unicode SAL_CALL
109 fullwidthKatakanaToHalfwidthKatakana::transliterateChar2Char( sal_Unicode inChar )
110   throw(RuntimeException, MultipleCharsOutputException)
111 {
112     sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
113     if (newChar == 0xFFFF)
114         throw MultipleCharsOutputException();
115     return transliteration_OneToOne::transliterateChar2Char(inChar);
116 }
117 
118 fullwidthToHalfwidthLikeASC::fullwidthToHalfwidthLikeASC()
119 {
120     func = (TransFunc) 0;
121     table = &widthfolding::getfull2halfTableForASC();
122     transliterationName = "fullwidthToHalfwidthLikeASC";
123     implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH_LIKE_ASC";
124 }
125 
126 /**
127  * Transliterate fullwidth to halfwidth like Excel's ASC function.
128  */
129 OUString SAL_CALL
130 fullwidthToHalfwidthLikeASC::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
131   throw(RuntimeException)
132 {
133     // Decomposition: GA --> KA + voice-mark
134     const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset);
135 
136     // One to One mapping
137     useOffset = sal_False;
138     const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset);
139     useOffset = sal_True;
140 
141     return tmp;
142 }
143 
144 sal_Unicode SAL_CALL
145 fullwidthToHalfwidthLikeASC::transliterateChar2Char( sal_Unicode inChar )
146   throw(RuntimeException, MultipleCharsOutputException)
147 {
148     sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
149     if (newChar == 0xFFFF)
150         throw MultipleCharsOutputException();
151     return transliteration_OneToOne::transliterateChar2Char(inChar);
152 }
153 
154 } } } }
155 
156