LibreOffice Module i18npool (master)  1
fullwidthToHalfwidth.cxx
Go to the documentation of this file.
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 <sal/config.h>
21 
22 #include <com/sun/star/i18n/MultipleCharsOutputException.hpp>
24 
26 
27 using namespace com::sun::star::uno;
28 using namespace com::sun::star::i18n;
29 using namespace com::sun::star::lang;
30 
31 namespace i18npool {
32 
33 fullwidthToHalfwidth::fullwidthToHalfwidth()
34 {
35  func = nullptr;
36  table = &i18nutil::widthfolding::getfull2halfTable();
37  transliterationName = "fullwidthToHalfwidth";
38  implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH";
39 }
40 
46 OUString
47 fullwidthToHalfwidth::transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >* pOffset )
48 {
49  // Decomposition: GA --> KA + voice-mark
50  const OUString& newStr = i18nutil::widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, pOffset);
51 
52  // One to One mapping
53  return transliteration_OneToOne::transliterateImpl( newStr, 0, newStr.getLength(), pOffset);
54 }
55 
56 sal_Unicode SAL_CALL
57 fullwidthToHalfwidth::transliterateChar2Char( sal_Unicode inChar)
58 {
59  sal_Unicode newChar = i18nutil::widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
60  if (newChar == 0xFFFF)
61  throw MultipleCharsOutputException();
62  return transliteration_OneToOne::transliterateChar2Char(inChar);
63 }
64 
65 FULLWIDTHKATAKANA_HALFWIDTHKATAKANA::FULLWIDTHKATAKANA_HALFWIDTHKATAKANA()
66 {
67  func = nullptr;
68  table = &i18nutil::widthfolding::getfullKana2halfKanaTable();
69  transliterationName = "fullwidthKatakanaToHalfwidthKatakana";
70  implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTHKATAKANA_HALFWIDTHKATAKANA";
71 }
72 
76 OUString
77 FULLWIDTHKATAKANA_HALFWIDTHKATAKANA::transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >* pOffset )
78 {
79  // Decomposition: GA --> KA + voice-mark
80  const OUString& newStr = i18nutil::widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, pOffset);
81 
82  // One to One mapping
83  return transliteration_OneToOne::transliterateImpl( newStr, 0, newStr.getLength(), nullptr);
84 }
85 
86 sal_Unicode SAL_CALL
87 FULLWIDTHKATAKANA_HALFWIDTHKATAKANA::transliterateChar2Char( sal_Unicode inChar )
88 {
89  sal_Unicode newChar = i18nutil::widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
90  if (newChar == 0xFFFF)
91  throw MultipleCharsOutputException();
92  return transliteration_OneToOne::transliterateChar2Char(inChar);
93 }
94 
95 FULLWIDTH_HALFWIDTH_LIKE_ASC::FULLWIDTH_HALFWIDTH_LIKE_ASC()
96 {
97  func = nullptr;
98  table = &i18nutil::widthfolding::getfull2halfTableForASC();
99  transliterationName = "fullwidthToHalfwidthLikeASC";
100  implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH_LIKE_ASC";
101 }
102 
106 OUString
107 FULLWIDTH_HALFWIDTH_LIKE_ASC::transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >* pOffset )
108 {
109  // Decomposition: GA --> KA + voice-mark
110  const OUString& newStr = i18nutil::widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, pOffset);
111 
112  // One to One mapping
113  return transliteration_OneToOne::transliterateImpl( newStr, 0, newStr.getLength(), nullptr);
114 }
115 
116 sal_Unicode SAL_CALL
117 FULLWIDTH_HALFWIDTH_LIKE_ASC::transliterateChar2Char( sal_Unicode inChar )
118 {
119  sal_Unicode newChar = i18nutil::widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
120  if (newChar == 0xFFFF)
121  throw MultipleCharsOutputException();
122  return transliteration_OneToOne::transliterateChar2Char(inChar);
123 }
124 
125 }
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
exports com.sun.star. table
sal_uInt16 sal_Unicode
Constant values shared between i18npool and, for example, the number formatter.
constexpr OUStringLiteral implementationName