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