1999-11-20 00:40:50 +00:00
|
|
|
|
/*
|
1999-11-22 21:47:27 +00:00
|
|
|
|
* Copyright <EFBFBD> {1999}, 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
|
|
|
|
|
|
|
|
|
|
#include "rbt_set.h"
|
|
|
|
|
|
|
|
|
|
class UnicodeString;
|
|
|
|
|
class UnicodeSet;
|
2000-03-28 22:12:14 +00:00
|
|
|
|
class Hashtable;
|
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
|
|
|
|
*/
|
|
|
|
|
class TransliterationRuleData {
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
* UnicodeSet, in which case the character in the UnicodeString in this hash is
|
|
|
|
|
* a stand-in: it is an index for a secondary lookup in
|
|
|
|
|
* data.setVariables. The stand-in also represents the UnicodeSet in
|
|
|
|
|
* the stored rules.
|
1999-11-20 00:40:50 +00:00
|
|
|
|
*/
|
2000-03-28 22:12:14 +00:00
|
|
|
|
Hashtable* variableNames;
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2000-05-20 04:40:29 +00:00
|
|
|
|
* Map category variable (UChar) to set (UnicodeSet).
|
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
|
|
|
|
|
* actual UnicodeSet object. In addition, the stand-in is
|
|
|
|
|
* stored in the rule text to represent the set of characters.
|
|
|
|
|
* setVariables[i] represents character (setVariablesBase + i).
|
1999-11-20 00:40:50 +00:00
|
|
|
|
*/
|
2000-02-08 02:49:15 +00:00
|
|
|
|
UnicodeSet** setVariables;
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
2000-02-08 02:49:15 +00:00
|
|
|
|
/**
|
2000-05-20 04:40:29 +00:00
|
|
|
|
* The character that represents setVariables[0]. Characters
|
|
|
|
|
* setVariablesBase through setVariablesBase +
|
|
|
|
|
* setVariables.length - 1 represent UnicodeSet objects.
|
2000-02-08 02:49:15 +00:00
|
|
|
|
*/
|
|
|
|
|
UChar setVariablesBase;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The length of setVariables.
|
|
|
|
|
*/
|
|
|
|
|
int32_t setVariablesLength;
|
|
|
|
|
|
2000-05-20 04:40:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* The character that represents segment 1. Characters segmentBase
|
|
|
|
|
* through segmentBase + 8 represent segments 1 through 9.
|
|
|
|
|
*/
|
|
|
|
|
UChar segmentBase;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
|
TransliterationRuleData(UErrorCode& status);
|
|
|
|
|
|
2000-06-30 23:26:07 +00:00
|
|
|
|
TransliterationRuleData(const TransliterationRuleData&);
|
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
|
~TransliterationRuleData();
|
2000-08-11 02:08:59 +00:00
|
|
|
|
|
|
|
|
|
const UnicodeSet* lookupSet(UChar standIn) const;
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
2000-05-20 04:40:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return the zero-based index of the segment represented by the given
|
|
|
|
|
* character, or -1 if none. Repeat: This is a zero-based return value,
|
|
|
|
|
* 0..8, even though these are notated "$1".."$9".
|
|
|
|
|
*/
|
|
|
|
|
int32_t lookupSegmentReference(UChar c) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the character used to stand for the given segment reference.
|
|
|
|
|
* The reference must be in the range 1..9.
|
|
|
|
|
*/
|
|
|
|
|
UChar getSegmentStandin(int32_t ref) const {
|
2000-08-11 02:08:59 +00:00
|
|
|
|
return (UChar)(segmentBase + ref - 1);
|
2000-05-20 04:40:29 +00:00
|
|
|
|
}
|
1999-11-20 00:40:50 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|