Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/i18npool/source/transliteration/fullwidthToHalfwidth.cxx
Line
Count
Source
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>
23
#include <i18nutil/widthfolding.hxx>
24
25
#include <transliteration_OneToOne.hxx>
26
27
using namespace com::sun::star::uno;
28
using namespace com::sun::star::i18n;
29
30
namespace i18npool {
31
32
fullwidthToHalfwidth::fullwidthToHalfwidth()
33
0
{
34
0
    func = nullptr;
35
0
    table = &i18nutil::widthfolding::getfull2halfTable();
36
0
    transliterationName = "fullwidthToHalfwidth";
37
0
    implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH";
38
0
}
39
40
/**
41
 * Transliterate fullwidth to halfwidth.
42
 * The output is a reference of OUString. You MUST delete this object when you do not need to use it any more
43
 * The output string contains a transliterated string only, not whole string.
44
 */
45
OUString
46
fullwidthToHalfwidth::transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >* pOffset )
47
0
{
48
    // Decomposition: GA --> KA + voice-mark
49
0
    const OUString newStr = i18nutil::widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, pOffset);
50
51
    // One to One mapping
52
0
    return transliteration_OneToOne::transliterateImpl( newStr, 0, newStr.getLength(), nullptr);
53
0
}
54
55
sal_Unicode SAL_CALL
56
fullwidthToHalfwidth::transliterateChar2Char( sal_Unicode inChar)
57
0
{
58
0
    sal_Unicode newChar = i18nutil::widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
59
0
    if (newChar == 0xFFFF)
60
0
        throw MultipleCharsOutputException();
61
0
    return transliteration_OneToOne::transliterateChar2Char(inChar);
62
0
}
63
64
FULLWIDTHKATAKANA_HALFWIDTHKATAKANA::FULLWIDTHKATAKANA_HALFWIDTHKATAKANA()
65
0
{
66
0
    func = nullptr;
67
0
    table = &i18nutil::widthfolding::getfullKana2halfKanaTable();
68
0
    transliterationName = "fullwidthKatakanaToHalfwidthKatakana";
69
0
    implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTHKATAKANA_HALFWIDTHKATAKANA";
70
0
}
71
72
/**
73
 * Transliterate fullwidth katakana to halfwidth katakana.
74
 */
75
OUString
76
FULLWIDTHKATAKANA_HALFWIDTHKATAKANA::transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >* pOffset )
77
0
{
78
    // Decomposition: GA --> KA + voice-mark
79
0
    const OUString newStr = i18nutil::widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, pOffset);
80
81
    // One to One mapping
82
0
    return transliteration_OneToOne::transliterateImpl( newStr, 0, newStr.getLength(), nullptr);
83
0
}
84
85
sal_Unicode SAL_CALL
86
FULLWIDTHKATAKANA_HALFWIDTHKATAKANA::transliterateChar2Char( sal_Unicode inChar )
87
0
{
88
0
    sal_Unicode newChar = i18nutil::widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
89
0
    if (newChar == 0xFFFF)
90
0
        throw MultipleCharsOutputException();
91
0
    return transliteration_OneToOne::transliterateChar2Char(inChar);
92
0
}
93
94
FULLWIDTH_HALFWIDTH_LIKE_ASC::FULLWIDTH_HALFWIDTH_LIKE_ASC()
95
0
{
96
0
    func = nullptr;
97
0
    table = &i18nutil::widthfolding::getfull2halfTableForASC();
98
0
    transliterationName = "fullwidthToHalfwidthLikeASC";
99
0
    implementationName = "com.sun.star.i18n.Transliteration.FULLWIDTH_HALFWIDTH_LIKE_ASC";
100
0
}
101
102
/**
103
 * Transliterate fullwidth to halfwidth like Excel's ASC function.
104
 */
105
OUString
106
FULLWIDTH_HALFWIDTH_LIKE_ASC::transliterateImpl( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >* pOffset )
107
0
{
108
    // Decomposition: GA --> KA + voice-mark
109
0
    const OUString newStr = i18nutil::widthfolding::decompose_ja_voiced_sound_marks (inStr, startPos, nCount, pOffset);
110
111
    // One to One mapping
112
0
    return transliteration_OneToOne::transliterateImpl( newStr, 0, newStr.getLength(), nullptr);
113
0
}
114
115
sal_Unicode SAL_CALL
116
FULLWIDTH_HALFWIDTH_LIKE_ASC::transliterateChar2Char( sal_Unicode inChar )
117
0
{
118
0
    sal_Unicode newChar = i18nutil::widthfolding::decompose_ja_voiced_sound_marksChar2Char (inChar);
119
0
    if (newChar == 0xFFFF)
120
0
        throw MultipleCharsOutputException();
121
0
    return transliteration_OneToOne::transliterateChar2Char(inChar);
122
0
}
123
124
}
125
126
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */