2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2006-03-23 00:54:12 +00:00
|
|
|
/**
|
2007-05-02 23:07:12 +00:00
|
|
|
************************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2006-2012, International Business Machines Corporation and others. *
|
2007-05-02 23:07:12 +00:00
|
|
|
* All Rights Reserved. *
|
|
|
|
************************************************************************************
|
2006-03-23 00:54:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BRKENG_H
|
|
|
|
#define BRKENG_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uobject.h"
|
2006-04-22 05:29:27 +00:00
|
|
|
#include "unicode/utext.h"
|
2007-05-02 23:07:12 +00:00
|
|
|
#include "unicode/uscript.h"
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class UnicodeSet;
|
|
|
|
class UStack;
|
2017-09-19 18:17:22 +00:00
|
|
|
class UVector32;
|
2012-08-16 23:01:49 +00:00
|
|
|
class DictionaryMatcher;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* LanguageBreakEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>LanguageBreakEngines implement language-specific knowledge for
|
|
|
|
* finding text boundaries within a run of characters belonging to a
|
|
|
|
* specific set. The boundaries will be of a specific kind, e.g. word,
|
|
|
|
* line, etc.</p>
|
|
|
|
*
|
|
|
|
* <p>LanguageBreakEngines should normally be implemented so as to
|
|
|
|
* be shared between threads without locking.</p>
|
|
|
|
*/
|
2006-04-08 08:34:52 +00:00
|
|
|
class LanguageBreakEngine : public UMemory {
|
2006-03-23 00:54:12 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
LanguageBreakEngine();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~LanguageBreakEngine();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Indicate whether this engine handles a particular character for
|
|
|
|
* a particular kind of break.</p>
|
|
|
|
*
|
|
|
|
* @param c A character which begins a run that the engine might handle
|
|
|
|
* @return TRUE if this engine handles the particular character and break
|
|
|
|
* type.
|
|
|
|
*/
|
2017-12-03 00:36:54 +00:00
|
|
|
virtual UBool handles(UChar32 c) const = 0;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Find any breaks within a run in the supplied text.</p>
|
|
|
|
*
|
2006-04-22 05:29:27 +00:00
|
|
|
* @param text A UText representing the text. The
|
2006-03-23 00:54:12 +00:00
|
|
|
* iterator is left at the end of the run of characters which the engine
|
|
|
|
* is capable of handling.
|
|
|
|
* @param startPos The start of the run within the supplied text.
|
|
|
|
* @param endPos The end of the run within the supplied text.
|
2017-09-19 18:17:22 +00:00
|
|
|
* @param foundBreaks A Vector of int32_t to receive the breaks.
|
2006-03-23 00:54:12 +00:00
|
|
|
* @return The number of breaks found.
|
|
|
|
*/
|
2006-04-22 05:29:27 +00:00
|
|
|
virtual int32_t findBreaks( UText *text,
|
2006-03-23 00:54:12 +00:00
|
|
|
int32_t startPos,
|
|
|
|
int32_t endPos,
|
2017-09-19 18:17:22 +00:00
|
|
|
UVector32 &foundBreaks ) const = 0;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* LanguageBreakFactory
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>LanguageBreakFactorys find and return a LanguageBreakEngine
|
|
|
|
* that can determine breaks for characters in a specific set, if
|
|
|
|
* such an object can be found.</p>
|
|
|
|
*
|
|
|
|
* <p>If a LanguageBreakFactory is to be shared between threads,
|
|
|
|
* appropriate synchronization must be used; there is none internal
|
|
|
|
* to the factory.</p>
|
|
|
|
*
|
|
|
|
* <p>A LanguageBreakEngine returned by a LanguageBreakFactory can
|
|
|
|
* normally be shared between threads without synchronization, unless
|
|
|
|
* the specific subclass of LanguageBreakFactory indicates otherwise.</p>
|
|
|
|
*
|
|
|
|
* <p>A LanguageBreakFactory is responsible for deleting any LanguageBreakEngine
|
|
|
|
* it returns when it itself is deleted, unless the specific subclass of
|
|
|
|
* LanguageBreakFactory indicates otherwise. Naturally, the factory should
|
|
|
|
* not be deleted until the LanguageBreakEngines it has returned are no
|
|
|
|
* longer needed.</p>
|
|
|
|
*/
|
2006-04-08 08:34:52 +00:00
|
|
|
class LanguageBreakFactory : public UMemory {
|
2006-03-23 00:54:12 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
LanguageBreakFactory();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~LanguageBreakFactory();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Find and return a LanguageBreakEngine that can find the desired
|
|
|
|
* kind of break for the set of characters to which the supplied
|
|
|
|
* character belongs. It is up to the set of available engines to
|
|
|
|
* determine what the sets of characters are.</p>
|
|
|
|
*
|
|
|
|
* @param c A character that begins a run for which a LanguageBreakEngine is
|
|
|
|
* sought.
|
|
|
|
* @return A LanguageBreakEngine with the desired characteristics, or 0.
|
|
|
|
*/
|
2017-12-03 00:36:54 +00:00
|
|
|
virtual const LanguageBreakEngine *getEngineFor(UChar32 c) = 0;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* UnhandledEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>UnhandledEngine is a special subclass of LanguageBreakEngine that
|
|
|
|
* handles characters that no other LanguageBreakEngine is available to
|
|
|
|
* handle. It is told the character and the type of break; at its
|
|
|
|
* discretion it may handle more than the specified character (e.g.,
|
|
|
|
* the entire script to which that character belongs.</p>
|
|
|
|
*
|
|
|
|
* <p>UnhandledEngines may not be shared between threads without
|
|
|
|
* external synchronization.</p>
|
|
|
|
*/
|
|
|
|
|
2006-04-08 08:34:52 +00:00
|
|
|
class UnhandledEngine : public LanguageBreakEngine {
|
2006-03-23 00:54:12 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
2017-12-03 00:36:54 +00:00
|
|
|
* The sets of characters handled.
|
2006-03-23 00:54:12 +00:00
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
2017-12-03 00:36:54 +00:00
|
|
|
UnicodeSet *fHandled;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Default constructor.</p>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
UnhandledEngine(UErrorCode &status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~UnhandledEngine();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Indicate whether this engine handles a particular character for
|
|
|
|
* a particular kind of break.</p>
|
|
|
|
*
|
|
|
|
* @param c A character which begins a run that the engine might handle
|
|
|
|
* @return TRUE if this engine handles the particular character and break
|
|
|
|
* type.
|
|
|
|
*/
|
2017-12-03 00:36:54 +00:00
|
|
|
virtual UBool handles(UChar32 c) const;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Find any breaks within a run in the supplied text.</p>
|
|
|
|
*
|
2006-04-22 05:29:27 +00:00
|
|
|
* @param text A UText representing the text (TODO: UText). The
|
2006-03-23 00:54:12 +00:00
|
|
|
* iterator is left at the end of the run of characters which the engine
|
|
|
|
* is capable of handling.
|
|
|
|
* @param startPos The start of the run within the supplied text.
|
|
|
|
* @param endPos The end of the run within the supplied text.
|
|
|
|
* @param foundBreaks An allocated C array of the breaks found, if any
|
|
|
|
* @return The number of breaks found.
|
|
|
|
*/
|
2006-04-22 05:29:27 +00:00
|
|
|
virtual int32_t findBreaks( UText *text,
|
2006-03-23 00:54:12 +00:00
|
|
|
int32_t startPos,
|
|
|
|
int32_t endPos,
|
2017-09-19 18:17:22 +00:00
|
|
|
UVector32 &foundBreaks ) const;
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Tell the engine to handle a particular character and break type.</p>
|
|
|
|
*
|
|
|
|
* @param c A character which the engine should handle
|
|
|
|
*/
|
2017-12-03 00:36:54 +00:00
|
|
|
virtual void handleCharacter(UChar32 c);
|
2006-03-23 00:54:12 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* ICULanguageBreakFactory
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>ICULanguageBreakFactory is the default LanguageBreakFactory for
|
|
|
|
* ICU. It creates dictionary-based LanguageBreakEngines from dictionary
|
|
|
|
* data in the ICU data file.</p>
|
|
|
|
*/
|
2006-04-08 08:34:52 +00:00
|
|
|
class ICULanguageBreakFactory : public LanguageBreakFactory {
|
2006-03-23 00:54:12 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The stack of break engines created by this factory
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
|
|
|
|
UStack *fEngines;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Standard constructor.</p>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ICULanguageBreakFactory(UErrorCode &status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Virtual destructor.</p>
|
|
|
|
*/
|
|
|
|
virtual ~ICULanguageBreakFactory();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Find and return a LanguageBreakEngine that can find the desired
|
|
|
|
* kind of break for the set of characters to which the supplied
|
|
|
|
* character belongs. It is up to the set of available engines to
|
|
|
|
* determine what the sets of characters are.</p>
|
|
|
|
*
|
|
|
|
* @param c A character that begins a run for which a LanguageBreakEngine is
|
|
|
|
* sought.
|
|
|
|
* @return A LanguageBreakEngine with the desired characteristics, or 0.
|
|
|
|
*/
|
2017-12-03 00:36:54 +00:00
|
|
|
virtual const LanguageBreakEngine *getEngineFor(UChar32 c);
|
2006-03-23 00:54:12 +00:00
|
|
|
|
2012-08-16 23:01:49 +00:00
|
|
|
protected:
|
2007-05-02 23:07:12 +00:00
|
|
|
/**
|
|
|
|
* <p>Create a LanguageBreakEngine for the set of characters to which
|
|
|
|
* the supplied character belongs, for the specified break type.</p>
|
|
|
|
*
|
|
|
|
* @param c A character that begins a run for which a LanguageBreakEngine is
|
|
|
|
* sought.
|
|
|
|
* @return A LanguageBreakEngine with the desired characteristics, or 0.
|
|
|
|
*/
|
2017-12-03 00:36:54 +00:00
|
|
|
virtual const LanguageBreakEngine *loadEngineFor(UChar32 c);
|
2007-05-02 23:07:12 +00:00
|
|
|
|
2012-08-16 23:01:49 +00:00
|
|
|
/**
|
|
|
|
* <p>Create a DictionaryMatcher for the specified script and break type.</p>
|
|
|
|
* @param script An ISO 15924 script code that identifies the dictionary to be
|
|
|
|
* created.
|
|
|
|
* @return A DictionaryMatcher with the desired characteristics, or NULL.
|
|
|
|
*/
|
2017-12-03 00:36:54 +00:00
|
|
|
virtual DictionaryMatcher *loadDictionaryMatcherFor(UScriptCode script);
|
2006-03-23 00:54:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
/* BRKENG_H */
|
|
|
|
#endif
|