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 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 56 fullwidthToHalfwidth::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset ) 57 { 58 // Decomposition: GA --> KA + voice-mark 59 const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset); 60 61 // One to One mapping 62 useOffset = sal_False; 63 const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset); 64 useOffset = sal_True; 65 return tmp; 66 } 67 68 sal_Unicode SAL_CALL 69 fullwidthToHalfwidth::transliterateChar2Char( sal_Unicode inChar) 70 { 71 sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar); 72 if (newChar == 0xFFFF) 73 throw MultipleCharsOutputException(); 74 return transliteration_OneToOne::transliterateChar2Char(inChar); 75 } 76 77 fullwidthKatakanaToHalfwidthKatakana::fullwidthKatakanaToHalfwidthKatakana() 78 { 79 func = (TransFunc) 0; 80 table = &widthfolding::getfullKana2halfKanaTable(); 81 transliterationName = "fullwidthKatakanaToHalfwidthKatakana"; 82 implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTHKATAKANA_HALFWIDTHKATAKANA"; 83 } 84 85 /** 86 * Transliterate fullwidth katakana to halfwidth katakana. 87 */ 88 OUString SAL_CALL 89 fullwidthKatakanaToHalfwidthKatakana::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset ) 90 { 91 // Decomposition: GA --> KA + voice-mark 92 const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset); 93 94 // One to One mapping 95 useOffset = sal_False; 96 const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset); 97 useOffset = sal_True; 98 return tmp; 99 } 100 101 sal_Unicode SAL_CALL 102 fullwidthKatakanaToHalfwidthKatakana::transliterateChar2Char( sal_Unicode inChar ) 103 { 104 sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar); 105 if (newChar == 0xFFFF) 106 throw MultipleCharsOutputException(); 107 return transliteration_OneToOne::transliterateChar2Char(inChar); 108 } 109 110 fullwidthToHalfwidthLikeASC::fullwidthToHalfwidthLikeASC() 111 { 112 func = (TransFunc) 0; 113 table = &widthfolding::getfull2halfTableForASC(); 114 transliterationName = "fullwidthToHalfwidthLikeASC"; 115 implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH_LIKE_ASC"; 116 } 117 118 /** 119 * Transliterate fullwidth to halfwidth like Excel's ASC function. 120 */ 121 OUString SAL_CALL 122 fullwidthToHalfwidthLikeASC::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset ) 123 { 124 // Decomposition: GA --> KA + voice-mark 125 const OUString& newStr = widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, offset, useOffset); 126 127 // One to One mapping 128 useOffset = sal_False; 129 const OUString &tmp = transliteration_OneToOne::transliterate( newStr, 0, newStr.getLength(), offset); 130 useOffset = sal_True; 131 132 return tmp; 133 } 134 135 sal_Unicode SAL_CALL 136 fullwidthToHalfwidthLikeASC::transliterateChar2Char( sal_Unicode inChar ) 137 { 138 sal_Unicode newChar = widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar); 139 if (newChar == 0xFFFF) 140 throw MultipleCharsOutputException(); 141 return transliteration_OneToOne::transliterateChar2Char(inChar); 142 } 143 144 } } } } 145