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