Kaydet (Commit) 98908d79 authored tarafından Khaled Hosny's avatar Khaled Hosny Kaydeden (comit) Eike Rathke

Fold BreakIterator_CTL into BreakIterator_th

The split is pointless and misleading, there are no other subclasses of
BreakIterator_CTL.

Change-Id: I66e66834e6e064cea29f543434a35682ee7cd35d
Reviewed-on: https://gerrit.libreoffice.org/54638Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
üst 69245868
......@@ -42,7 +42,6 @@ endif
$(eval $(call gb_Library_add_exception_objects,i18npool,\
i18npool/source/breakiterator/breakiterator_cjk \
i18npool/source/breakiterator/breakiterator_ctl \
i18npool/source/breakiterator/breakiteratorImpl \
i18npool/source/breakiterator/breakiterator_th \
i18npool/source/breakiterator/breakiterator_unicode \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_I18NPOOL_INC_BREAKITERATOR_CTL_HXX
#define INCLUDED_I18NPOOL_INC_BREAKITERATOR_CTL_HXX
#include "breakiterator_unicode.hxx"
#include "xdictionary.hxx"
namespace i18npool {
// class BreakIterator_CTL
class BreakIterator_CTL : public BreakIterator_Unicode
{
public:
BreakIterator_CTL();
virtual ~BreakIterator_CTL() override;
virtual sal_Int32 SAL_CALL previousCharacters(const OUString& text, sal_Int32 start,
const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 count,
sal_Int32& nDone) override;
virtual sal_Int32 SAL_CALL nextCharacters(const OUString& text, sal_Int32 start,
const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 count,
sal_Int32& nDone) 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;
protected:
OUString cachedText; // for cell index
sal_Int32* nextCellIndex;
sal_Int32* previousCellIndex;
sal_Int32 cellIndexSize;
/// @throws css::uno::RuntimeException
virtual void makeIndex(const OUString& text, sal_Int32 pos);
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -18,25 +18,42 @@
*/
#ifndef INCLUDED_I18NPOOL_INC_BREAKITERATOR_TH_HXX
#define INCLUDED_I18NPOOL_INC_BREAKITERATOR_TH_HXX
#include "breakiterator_ctl.hxx"
#include "breakiterator_unicode.hxx"
#include "xdictionary.hxx"
namespace i18npool {
// class BreakIterator_th
class BreakIterator_th : public BreakIterator_CTL
class BreakIterator_th : public BreakIterator_Unicode
{
public:
BreakIterator_th();
virtual ~BreakIterator_th() override;
protected:
void makeIndex(const OUString& text, sal_Int32 pos) override;
virtual sal_Int32 SAL_CALL previousCharacters(const OUString& text, sal_Int32 start,
const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 count,
sal_Int32& nDone) override;
virtual sal_Int32 SAL_CALL nextCharacters(const OUString& text, sal_Int32 start,
const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 count,
sal_Int32& nDone) 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;
private:
OUString cachedText; // for cell index
sal_Int32* nextCellIndex;
sal_Int32* previousCellIndex;
sal_Int32 cellIndexSize;
void makeIndex(const OUString& text, sal_Int32 pos);
};
}
#endif // INCLUDED_I18NPOOL_INC_BREAKITERATOR_TH_HXX
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
#include <breakiterator_ctl.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
namespace i18npool {
/**
* Constructor.
*/
BreakIterator_CTL::BreakIterator_CTL() :
cachedText(),
nextCellIndex( nullptr ),
previousCellIndex( nullptr ),
cellIndexSize( 512 )
{
cBreakIterator = "com.sun.star.i18n.BreakIterator_CTL";
// to improve performance, alloc big enough memory in construct.
nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
}
/**
* Deconstructor.
*/
BreakIterator_CTL::~BreakIterator_CTL()
{
free(nextCellIndex);
free(previousCellIndex);
}
sal_Int32 SAL_CALL BreakIterator_CTL::previousCharacters( const OUString& Text,
sal_Int32 nStartPos, const lang::Locale& rLocale,
sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32& nDone )
{
if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
nDone = 0;
if (nStartPos > 0) { // for others to skip cell.
makeIndex(Text, nStartPos);
if (nextCellIndex[nStartPos-1] == 0) // not a CTL character
return BreakIterator_Unicode::previousCharacters(Text, nStartPos, rLocale,
nCharacterIteratorMode, nCount, nDone);
else while (nCount > 0 && nextCellIndex[nStartPos - 1] > 0) {
nCount--; nDone++;
nStartPos = previousCellIndex[nStartPos - 1];
}
} else
nStartPos = 0;
} else { // for BS to delete one char.
for (nDone = 0; nDone < nCount && nStartPos > 0; nDone++)
Text.iterateCodePoints(&nStartPos, -1);
}
return nStartPos;
}
sal_Int32 SAL_CALL BreakIterator_CTL::nextCharacters(const OUString& Text,
sal_Int32 nStartPos, const lang::Locale& rLocale,
sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32& nDone)
{
sal_Int32 len = Text.getLength();
if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
nDone = 0;
if (nStartPos < len) {
makeIndex(Text, nStartPos);
if (nextCellIndex[nStartPos] == 0) // not a CTL character
return BreakIterator_Unicode::nextCharacters(Text, nStartPos, rLocale,
nCharacterIteratorMode, nCount, nDone);
else while (nCount > 0 && nextCellIndex[nStartPos] > 0) {
nCount--; nDone++;
nStartPos = nextCellIndex[nStartPos];
}
} else
nStartPos = len;
} else {
for (nDone = 0; nDone < nCount && nStartPos < Text.getLength(); nDone++)
Text.iterateCodePoints(&nStartPos);
}
return nStartPos;
}
// This method should be overwritten by derived language specific class.
void BreakIterator_CTL::makeIndex(const OUString& /*text*/, sal_Int32 /*pos*/)
{
throw RuntimeException();
}
// Make sure line is broken on cell boundary if we implement cell iterator.
LineBreakResults SAL_CALL BreakIterator_CTL::getLineBreak(
const OUString& Text, sal_Int32 nStartPos,
const lang::Locale& rLocale, sal_Int32 nMinBreakPos,
const LineBreakHyphenationOptions& hOptions,
const LineBreakUserOptions& bOptions )
{
LineBreakResults lbr = BreakIterator_Unicode::getLineBreak(Text, nStartPos,
rLocale, nMinBreakPos, hOptions, bOptions );
if (lbr.breakIndex < Text.getLength()) {
makeIndex(Text, lbr.breakIndex);
lbr.breakIndex = previousCellIndex[ lbr.breakIndex ];
}
return lbr;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -17,28 +17,113 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
#include <breakiterator_th.hxx>
#include <wtt.h>
#include <string.h>
#include <algorithm>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
namespace i18npool {
// class Breakiterator_th
// ----------------------------------------------------;
BreakIterator_th::BreakIterator_th()
/**
* Constructor.
*/
BreakIterator_th::BreakIterator_th() :
cachedText(),
nextCellIndex( nullptr ),
previousCellIndex( nullptr ),
cellIndexSize( 512 )
{
cBreakIterator = "com.sun.star.i18n.BreakIterator_th";
// to improve performance, alloc big enough memory in construct.
nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
lineRule=nullptr;
}
/**
* Deconstructor.
*/
BreakIterator_th::~BreakIterator_th()
{
free(nextCellIndex);
free(previousCellIndex);
}
sal_Int32 SAL_CALL BreakIterator_th::previousCharacters( const OUString& Text,
sal_Int32 nStartPos, const lang::Locale& rLocale,
sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32& nDone )
{
if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
nDone = 0;
if (nStartPos > 0) { // for others to skip cell.
makeIndex(Text, nStartPos);
if (nextCellIndex[nStartPos-1] == 0) // not a CTL character
return BreakIterator_Unicode::previousCharacters(Text, nStartPos, rLocale,
nCharacterIteratorMode, nCount, nDone);
else while (nCount > 0 && nextCellIndex[nStartPos - 1] > 0) {
nCount--; nDone++;
nStartPos = previousCellIndex[nStartPos - 1];
}
} else
nStartPos = 0;
} else { // for BS to delete one char.
for (nDone = 0; nDone < nCount && nStartPos > 0; nDone++)
Text.iterateCodePoints(&nStartPos, -1);
}
return nStartPos;
}
sal_Int32 SAL_CALL BreakIterator_th::nextCharacters(const OUString& Text,
sal_Int32 nStartPos, const lang::Locale& rLocale,
sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32& nDone)
{
sal_Int32 len = Text.getLength();
if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
nDone = 0;
if (nStartPos < len) {
makeIndex(Text, nStartPos);
if (nextCellIndex[nStartPos] == 0) // not a CTL character
return BreakIterator_Unicode::nextCharacters(Text, nStartPos, rLocale,
nCharacterIteratorMode, nCount, nDone);
else while (nCount > 0 && nextCellIndex[nStartPos] > 0) {
nCount--; nDone++;
nStartPos = nextCellIndex[nStartPos];
}
} else
nStartPos = len;
} else {
for (nDone = 0; nDone < nCount && nStartPos < Text.getLength(); nDone++)
Text.iterateCodePoints(&nStartPos);
}
return nStartPos;
}
// Make sure line is broken on cell boundary if we implement cell iterator.
LineBreakResults SAL_CALL BreakIterator_th::getLineBreak(
const OUString& Text, sal_Int32 nStartPos,
const lang::Locale& rLocale, sal_Int32 nMinBreakPos,
const LineBreakHyphenationOptions& hOptions,
const LineBreakUserOptions& bOptions )
{
LineBreakResults lbr = BreakIterator_Unicode::getLineBreak(Text, nStartPos,
rLocale, nMinBreakPos, hOptions, bOptions );
if (lbr.breakIndex < Text.getLength()) {
makeIndex(Text, lbr.breakIndex);
lbr.breakIndex = previousCellIndex[ lbr.breakIndex ];
}
return lbr;
}
#define SARA_AM 0x0E33
......
......@@ -5590,7 +5590,6 @@ i18nlangtag/source/languagetag/languagetag.cxx
i18nlangtag/source/languagetag/languagetagicu.cxx
i18npool/inc/breakiteratorImpl.hxx
i18npool/inc/breakiterator_cjk.hxx
i18npool/inc/breakiterator_ctl.hxx
i18npool/inc/breakiterator_th.hxx
i18npool/inc/breakiterator_unicode.hxx
i18npool/inc/bullet.h
......@@ -5640,7 +5639,6 @@ i18npool/qa/cppunit/test_ordinalsuffix.cxx
i18npool/qa/cppunit/test_textsearch.cxx
i18npool/source/breakiterator/breakiteratorImpl.cxx
i18npool/source/breakiterator/breakiterator_cjk.cxx
i18npool/source/breakiterator/breakiterator_ctl.cxx
i18npool/source/breakiterator/breakiterator_th.cxx
i18npool/source/breakiterator/breakiterator_unicode.cxx
i18npool/source/breakiterator/gendict.cxx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment