Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/linguistic/source/hhconvdic.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 <unicode/uscript.h>
21
#include <i18nlangtag/lang.h>
22
#include <osl/mutex.hxx>
23
24
#include <cppuhelper/factory.hxx>
25
#include <cppuhelper/supportsservice.hxx>
26
#include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
27
#include <com/sun/star/lang/IllegalArgumentException.hpp>
28
#include <com/sun/star/i18n/UnicodeScript.hpp>
29
30
#include "hhconvdic.hxx"
31
#include <linguistic/misc.hxx>
32
33
using namespace osl;
34
using namespace com::sun::star;
35
using namespace com::sun::star::lang;
36
using namespace com::sun::star::uno;
37
using namespace com::sun::star::linguistic2;
38
using namespace linguistic;
39
40
41
constexpr OUString SN_HH_CONV_DICTIONARY = u"com.sun.star.linguistic2.HangulHanjaConversionDictionary"_ustr;
42
43
44
45
constexpr sal_Int16 SCRIPT_OTHERS = 0;
46
constexpr sal_Int16 SCRIPT_HANJA  = 1;
47
constexpr sal_Int16 SCRIPT_HANGUL = 2;
48
49
// from i18npool/source/textconversion/textconversion_ko.cxx
50
/// @throws RuntimeException
51
static sal_Int16 checkScriptType(sal_Unicode c)
52
0
{
53
0
  UErrorCode status = U_ZERO_ERROR;
54
55
0
  UScriptCode scriptCode = uscript_getScript(c, &status);
56
57
0
  if ( !U_SUCCESS(status) ) throw RuntimeException();
58
59
0
  return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL :
60
0
            scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS;
61
0
}
62
63
64
static bool TextIsAllScriptType( std::u16string_view rTxt, sal_Int16 nScriptType )
65
0
{
66
0
    for (size_t i = 0; i < rTxt.size(); ++i)
67
0
    {
68
0
        if (checkScriptType( rTxt[i]) != nScriptType)
69
0
            return false;
70
0
    }
71
0
    return true;
72
0
}
73
74
75
HHConvDic::HHConvDic( const OUString &rName, const OUString &rMainURL ) :
76
0
    ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, true, rMainURL )
77
0
{
78
0
}
79
80
81
HHConvDic::~HHConvDic()
82
0
{
83
0
}
84
85
86
void SAL_CALL HHConvDic::addEntry(
87
        const OUString& aLeftText,
88
        const OUString& aRightText )
89
0
{
90
0
    MutexGuard  aGuard( GetLinguMutex() );
91
92
0
    if ((aLeftText.getLength() != aRightText.getLength()) ||
93
0
        !TextIsAllScriptType( aLeftText,  SCRIPT_HANGUL ) ||
94
0
        !TextIsAllScriptType( aRightText, SCRIPT_HANJA ))
95
0
        throw IllegalArgumentException();
96
0
    ConvDic::addEntry( aLeftText, aRightText );
97
0
}
98
99
100
OUString SAL_CALL HHConvDic::getImplementationName(  )
101
0
{
102
0
    return u"com.sun.star.lingu2.HHConvDic"_ustr;
103
0
}
104
105
106
sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName )
107
0
{
108
0
    return cppu::supportsService(this, rServiceName);
109
0
}
110
111
112
uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames(  )
113
0
{
114
0
    return { SN_CONV_DICTIONARY, SN_HH_CONV_DICTIONARY };
115
0
}
116
117
118
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */