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
|
1999-11-20 00:40:50 +00:00
|
|
|
/*
|
2006-04-14 21:09:42 +00:00
|
|
|
**********************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 1999-2007, International Business Machines Corporation
|
|
|
|
* and others. All Rights Reserved.
|
1999-11-20 00:40:50 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 11/17/99 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
#ifndef RBT_DATA_H
|
|
|
|
#define RBT_DATA_H
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/utypes.h"
|
2003-12-10 01:52:39 +00:00
|
|
|
#include "unicode/uclean.h"
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/uobject.h"
|
1999-11-20 00:40:50 +00:00
|
|
|
#include "rbt_set.h"
|
2006-04-14 21:09:42 +00:00
|
|
|
#include "hash.h"
|
1999-11-20 00:40:50 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
class UnicodeFunctor;
|
2001-07-27 00:18:53 +00:00
|
|
|
class UnicodeMatcher;
|
2002-02-07 01:07:55 +00:00
|
|
|
class UnicodeReplacer;
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The rule data for a RuleBasedTransliterators. RBT objects hold
|
|
|
|
* a const pointer to a TRD object that they do not own. TRD objects
|
|
|
|
* are essentially the parsed rules in compact, usable form. The
|
|
|
|
* TRD objects themselves are held for the life of the process in
|
|
|
|
* a static cache owned by Transliterator.
|
2000-02-08 02:49:15 +00:00
|
|
|
*
|
|
|
|
* This class' API is a little asymmetric. There is a method to
|
|
|
|
* define a variable, but no way to define a set. This is because the
|
|
|
|
* sets are defined by the parser in a UVector, and the vector is
|
|
|
|
* copied into a fixed-size array here. Once this is done, no new
|
|
|
|
* sets may be defined. In practice, there is no need to do so, since
|
|
|
|
* generating the data and using it are discrete phases. When there
|
|
|
|
* is a need to access the set data during the parse phase, another
|
|
|
|
* data structure handles this. See the parsing code for more
|
|
|
|
* details.
|
1999-11-20 00:40:50 +00:00
|
|
|
*/
|
2007-06-03 06:08:46 +00:00
|
|
|
class TransliterationRuleData : public UMemory {
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2000-05-20 04:40:29 +00:00
|
|
|
// PUBLIC DATA MEMBERS
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
/**
|
|
|
|
* Rule table. May be empty.
|
|
|
|
*/
|
|
|
|
TransliterationRuleSet ruleSet;
|
|
|
|
|
|
|
|
/**
|
2000-05-20 04:40:29 +00:00
|
|
|
* Map variable name (String) to variable (UnicodeString). A variable name
|
|
|
|
* corresponds to zero or more characters, stored in a UnicodeString in
|
|
|
|
* this hash. One or more of these chars may also correspond to a
|
2001-07-27 00:18:53 +00:00
|
|
|
* UnicodeMatcher, in which case the character in the UnicodeString in this hash is
|
2000-05-20 04:40:29 +00:00
|
|
|
* a stand-in: it is an index for a secondary lookup in
|
2001-07-27 00:18:53 +00:00
|
|
|
* data.variables. The stand-in also represents the UnicodeMatcher in
|
2000-05-20 04:40:29 +00:00
|
|
|
* the stored rules.
|
1999-11-20 00:40:50 +00:00
|
|
|
*/
|
2006-04-14 21:09:42 +00:00
|
|
|
Hashtable variableNames;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
/**
|
2002-02-07 01:07:55 +00:00
|
|
|
* Map category variable (UChar) to set (UnicodeFunctor).
|
1999-11-20 00:40:50 +00:00
|
|
|
* Variables that correspond to a set of characters are mapped
|
2000-02-08 02:49:15 +00:00
|
|
|
* from variable name to a stand-in character in data.variableNames.
|
|
|
|
* The stand-in then serves as a key in this hash to lookup the
|
2002-02-07 01:07:55 +00:00
|
|
|
* actual UnicodeFunctor object. In addition, the stand-in is
|
2000-02-08 02:49:15 +00:00
|
|
|
* stored in the rule text to represent the set of characters.
|
2001-07-27 00:18:53 +00:00
|
|
|
* variables[i] represents character (variablesBase + i).
|
1999-11-20 00:40:50 +00:00
|
|
|
*/
|
2002-02-07 01:07:55 +00:00
|
|
|
UnicodeFunctor** variables;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
2005-06-09 17:30:48 +00:00
|
|
|
/**
|
|
|
|
* Flag that indicates whether the variables are owned (if a single
|
|
|
|
* call to Transliterator::createFromRules() produces a CompoundTransliterator
|
|
|
|
* with more than one RuleBasedTransliterator as children, they all share
|
|
|
|
* the same variables list, so only the first one is considered to own
|
|
|
|
* the variables)
|
|
|
|
*/
|
2005-06-09 23:54:30 +00:00
|
|
|
UBool variablesAreOwned;
|
2005-06-09 17:30:48 +00:00
|
|
|
|
2000-02-08 02:49:15 +00:00
|
|
|
/**
|
2001-07-27 00:18:53 +00:00
|
|
|
* The character that represents variables[0]. Characters
|
|
|
|
* variablesBase through variablesBase +
|
2002-02-07 01:07:55 +00:00
|
|
|
* variablesLength - 1 represent UnicodeFunctor objects.
|
2000-02-08 02:49:15 +00:00
|
|
|
*/
|
2001-07-27 00:18:53 +00:00
|
|
|
UChar variablesBase;
|
2000-02-08 02:49:15 +00:00
|
|
|
|
|
|
|
/**
|
2001-07-27 00:18:53 +00:00
|
|
|
* The length of variables.
|
2000-02-08 02:49:15 +00:00
|
|
|
*/
|
2001-07-27 00:18:53 +00:00
|
|
|
int32_t variablesLength;
|
2000-02-08 02:49:15 +00:00
|
|
|
|
2000-05-20 04:40:29 +00:00
|
|
|
public:
|
|
|
|
|
2002-07-01 11:04:45 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param status Output param set to success/failure code on exit.
|
|
|
|
*/
|
1999-11-20 00:40:50 +00:00
|
|
|
TransliterationRuleData(UErrorCode& status);
|
|
|
|
|
2002-07-01 11:04:45 +00:00
|
|
|
/**
|
|
|
|
* Copy Constructor
|
|
|
|
*/
|
2000-06-30 23:26:07 +00:00
|
|
|
TransliterationRuleData(const TransliterationRuleData&);
|
|
|
|
|
2002-07-01 11:04:45 +00:00
|
|
|
/**
|
|
|
|
* destructor
|
|
|
|
*/
|
1999-11-20 00:40:50 +00:00
|
|
|
~TransliterationRuleData();
|
2000-08-11 02:08:59 +00:00
|
|
|
|
2002-03-20 00:42:02 +00:00
|
|
|
/**
|
|
|
|
* Given a stand-in character, return the UnicodeFunctor that it
|
|
|
|
* represents, or NULL if it doesn't represent anything.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param standIn the given stand-in character.
|
|
|
|
* @return the UnicodeFunctor that 'standIn' represents
|
2002-03-20 00:42:02 +00:00
|
|
|
*/
|
|
|
|
UnicodeFunctor* lookup(UChar32 standIn) const;
|
|
|
|
|
2001-07-27 00:18:53 +00:00
|
|
|
/**
|
|
|
|
* Given a stand-in character, return the UnicodeMatcher that it
|
2002-03-20 00:42:02 +00:00
|
|
|
* represents, or NULL if it doesn't represent anything or if it
|
|
|
|
* represents something that is not a matcher.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param standIn the given stand-in character.
|
|
|
|
* @return return the UnicodeMatcher that 'standIn' represents
|
2001-07-27 00:18:53 +00:00
|
|
|
*/
|
2002-02-07 01:07:55 +00:00
|
|
|
UnicodeMatcher* lookupMatcher(UChar32 standIn) const;
|
1999-11-20 00:40:50 +00:00
|
|
|
|
2000-05-20 04:40:29 +00:00
|
|
|
/**
|
2002-02-07 01:07:55 +00:00
|
|
|
* Given a stand-in character, return the UnicodeReplacer that it
|
2002-03-20 00:42:02 +00:00
|
|
|
* represents, or NULL if it doesn't represent anything or if it
|
|
|
|
* represents something that is not a replacer.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param standIn the given stand-in character.
|
|
|
|
* @return return the UnicodeReplacer that 'standIn' represents
|
2000-05-20 04:40:29 +00:00
|
|
|
*/
|
2002-02-07 01:07:55 +00:00
|
|
|
UnicodeReplacer* lookupReplacer(UChar32 standIn) const;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2003-12-10 01:52:39 +00:00
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
private:
|
2002-10-04 18:06:33 +00:00
|
|
|
TransliterationRuleData &operator=(const TransliterationRuleData &other); // forbid copying of this class
|
1999-11-20 00:40:50 +00:00
|
|
|
};
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
#endif
|