LibreOffice Module i18npool (master)  1
breakiterator_unicode.hxx
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 #pragma once
20 
21 #include "breakiteratorImpl.hxx"
22 
23 #include <unicode/brkiter.h>
24 #include <unicode/utext.h>
25 #include <memory>
26 #include <unordered_map>
27 
28 namespace i18npool {
29 
30 #define LOAD_CHARACTER_BREAKITERATOR 0
31 #define LOAD_WORD_BREAKITERATOR 1
32 #define LOAD_SENTENCE_BREAKITERATOR 2
33 #define LOAD_LINE_BREAKITERATOR 3
34 
35 
36 
38 {
39 public:
41  virtual ~BreakIterator_Unicode() override;
42 
43  virtual sal_Int32 SAL_CALL previousCharacters( const OUString& Text, sal_Int32 nStartPos,
44  const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
45  sal_Int32& nDone ) override;
46  virtual sal_Int32 SAL_CALL nextCharacters( const OUString& Text, sal_Int32 nStartPos,
47  const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
48  sal_Int32& nDone ) override;
49 
50  virtual css::i18n::Boundary SAL_CALL previousWord( const OUString& Text, sal_Int32 nStartPos,
51  const css::lang::Locale& nLocale, sal_Int16 WordType) override;
52  virtual css::i18n::Boundary SAL_CALL nextWord( const OUString& Text, sal_Int32 nStartPos,
53  const css::lang::Locale& nLocale, sal_Int16 WordType) override;
54  virtual css::i18n::Boundary SAL_CALL getWordBoundary( const OUString& Text, sal_Int32 nPos,
55  const css::lang::Locale& nLocale, sal_Int16 WordType, sal_Bool bDirection ) override;
56 
57  virtual sal_Int32 SAL_CALL beginOfSentence( const OUString& Text, sal_Int32 nStartPos,
58  const css::lang::Locale& nLocale ) override;
59  virtual sal_Int32 SAL_CALL endOfSentence( const OUString& Text, sal_Int32 nStartPos,
60  const css::lang::Locale& nLocale ) override;
61 
62  virtual css::i18n::LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos,
63  const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos,
64  const css::i18n::LineBreakHyphenationOptions& hOptions,
65  const css::i18n::LineBreakUserOptions& bOptions ) override;
66 
67  //XServiceInfo
68  virtual OUString SAL_CALL getImplementationName() override;
69  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
70  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
71 
72 protected:
73  const char *cBreakIterator, *lineRule;
74 
76  struct BI_ValueData
77  {
78  OUString maICUText;
79  UText* mpUt;
80  std::shared_ptr< icu::BreakIterator > mpBreakIterator;
81 
82  BI_ValueData() : mpUt(nullptr)
83  {
84  }
86  {
87  utext_close(mpUt);
88  }
89  };
90 
91  struct BI_Data
92  {
93  std::shared_ptr< BI_ValueData > mpValue;
94  OString maBIMapKey;
96  BI_Data words[4]; // 4 is css::i18n::WordType enumeration size
97 
99  void loadICUBreakIterator(const css::lang::Locale& rLocale,
100  sal_Int16 rBreakType, sal_Int16 rWordType, const char* name, const OUString& rText);
101 
102 public:
103  typedef std::unordered_map< OString, std::shared_ptr< BI_ValueData > > BIMap;
104 };
105 
106 }
107 
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Int32 SAL_CALL nextCharacters(const OUString &Text, sal_Int32 nStartPos, const css::lang::Locale &rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32 &nDone) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual sal_Int32 SAL_CALL endOfSentence(const OUString &Text, sal_Int32 nStartPos, const css::lang::Locale &nLocale) override
virtual sal_Int32 SAL_CALL beginOfSentence(const OUString &Text, sal_Int32 nStartPos, const css::lang::Locale &nLocale) override
struct i18npool::BreakIterator_Unicode::BI_Data * icuBI
int nCount
struct i18npool::BreakIterator_Unicode::BI_Data sentence
virtual css::i18n::Boundary SAL_CALL nextWord(const OUString &Text, sal_Int32 nStartPos, const css::lang::Locale &nLocale, sal_Int16 WordType) override
void loadICUBreakIterator(const css::lang::Locale &rLocale, sal_Int16 rBreakType, sal_Int16 rWordType, const char *name, const OUString &rText)
unsigned char sal_Bool
Constant values shared between i18npool and, for example, the number formatter.
virtual css::i18n::Boundary SAL_CALL getWordBoundary(const OUString &Text, sal_Int32 nPos, const css::lang::Locale &nLocale, sal_Int16 WordType, sal_Bool bDirection) override
struct i18npool::BreakIterator_Unicode::BI_Data character
std::unordered_map< OString, std::shared_ptr< BI_ValueData > > BIMap
virtual css::i18n::Boundary SAL_CALL previousWord(const OUString &Text, sal_Int32 nStartPos, const css::lang::Locale &nLocale, sal_Int16 WordType) override
virtual css::i18n::LineBreakResults SAL_CALL getLineBreak(const OUString &Text, sal_Int32 nStartPos, const css::lang::Locale &nLocale, sal_Int32 nMinBreakPos, const css::i18n::LineBreakHyphenationOptions &hOptions, const css::i18n::LineBreakUserOptions &bOptions) override
std::shared_ptr< icu::BreakIterator > mpBreakIterator
virtual sal_Int32 SAL_CALL previousCharacters(const OUString &Text, sal_Int32 nStartPos, const css::lang::Locale &nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32 &nDone) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
struct i18npool::BreakIterator_Unicode::BI_Data line
sal_uInt16 nPos