2003-11-19 01:00:18 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2005-06-07 23:38:09 +00:00
|
|
|
* Copyright (C) 1999-2005, International Business Machines
|
2003-11-19 01:00:18 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: rbbidata.h
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* RBBI data formats Includes
|
|
|
|
*
|
|
|
|
* Structs that describes the format of the Binary RBBI data,
|
|
|
|
* as it is stored in ICU's data file.
|
|
|
|
*
|
|
|
|
* RBBIDataWrapper - Instances of this class sit between the
|
|
|
|
* raw data structs and the RulesBasedBreakIterator objects
|
|
|
|
* that are created by applications. The wrapper class
|
|
|
|
* provides reference counting for the underlying data,
|
|
|
|
* and direct pointers to data that would not otherwise
|
|
|
|
* be accessible without ugly pointer arithmetic. The
|
|
|
|
* wrapper does not attempt to provide any higher level
|
|
|
|
* abstractions for the data itself.
|
|
|
|
*
|
|
|
|
* There will be only one instance of RBBIDataWrapper for any
|
|
|
|
* set of RBBI run time data being shared by instances
|
|
|
|
* (clones) of RulesBasedBreakIterator.
|
|
|
|
*/
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
#ifndef __RBBIDATA_H__
|
|
|
|
#define __RBBIDATA_H__
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/utypes.h"
|
2003-11-19 01:00:18 +00:00
|
|
|
#include "unicode/udata.h"
|
|
|
|
#include "udataswp.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Swap RBBI data. See udataswp.h.
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ubrk_swap(const UDataSwapper *ds,
|
|
|
|
const void *inData, int32_t length, void *outData,
|
|
|
|
UErrorCode *pErrorCode);
|
|
|
|
|
|
|
|
#ifdef XP_CPLUSPLUS
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/uobject.h"
|
2002-06-25 17:23:07 +00:00
|
|
|
#include "unicode/unistr.h"
|
|
|
|
#include "utrie.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2003-12-04 02:12:42 +00:00
|
|
|
/*
|
|
|
|
* The following structs map exactly onto the raw data from ICU common data file.
|
|
|
|
*/
|
2002-06-25 17:23:07 +00:00
|
|
|
struct RBBIDataHeader {
|
2005-03-28 05:21:50 +00:00
|
|
|
uint32_t fMagic; /* == 0xbla0 */
|
|
|
|
uint8_t fFormatVersion[4]; /* Data Format. Same as the value in struct UDataInfo */
|
|
|
|
/* if there is one associated with this data. */
|
|
|
|
/* (version originates in rbbi, is copied to UDataInfo) */
|
|
|
|
/* For ICU 3.2 and earlier, this field was */
|
|
|
|
/* uint32_t fVersion */
|
|
|
|
/* with a value of 1. */
|
|
|
|
uint32_t fLength; /* Total length in bytes of this RBBI Data, */
|
|
|
|
/* including all sections, not just the header. */
|
|
|
|
uint32_t fCatCount; /* Number of character categories. */
|
2003-11-24 19:48:37 +00:00
|
|
|
|
2005-03-28 05:21:50 +00:00
|
|
|
/* */
|
|
|
|
/* Offsets and sizes of each of the subsections within the RBBI data. */
|
|
|
|
/* All offsets are bytes from the start of the RBBIDataHeader. */
|
|
|
|
/* All sizes are in bytes. */
|
|
|
|
/* */
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fFTable; /* forward state transition table. */
|
2002-06-25 17:23:07 +00:00
|
|
|
uint32_t fFTableLen;
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fRTable; /* Offset to the reverse state transition table. */
|
2002-06-25 17:23:07 +00:00
|
|
|
uint32_t fRTableLen;
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fSFTable; /* safe point forward transition table */
|
2003-11-05 02:03:44 +00:00
|
|
|
uint32_t fSFTableLen;
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fSRTable; /* safe point reverse transition table */
|
2003-11-05 02:03:44 +00:00
|
|
|
uint32_t fSRTableLen;
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fTrie; /* Offset to Trie data for character categories */
|
2002-06-25 17:23:07 +00:00
|
|
|
uint32_t fTrieLen;
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fRuleSource; /* Offset to the source for for the break */
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fRuleSourceLen; /* rules. Stored UChar *. */
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fStatusTable; /* Offset to the table of rule status values */
|
|
|
|
uint32_t fStatusTableLen;
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2004-03-05 05:04:10 +00:00
|
|
|
uint32_t fReserved[6]; /* Reserved for expansion */
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct RBBIStateTableRow {
|
2004-03-05 05:04:10 +00:00
|
|
|
int16_t fAccepting; /* Non-zero if this row is for an accepting state. */
|
|
|
|
/* Value 0: not an accepting state. */
|
|
|
|
/* -1: Unconditional Accepting state. */
|
|
|
|
/* positive: Look-ahead match has completed. */
|
|
|
|
/* Actual boundary position happened earlier */
|
|
|
|
/* Value here == fLookAhead in earlier */
|
|
|
|
/* state, at actual boundary pos. */
|
|
|
|
int16_t fLookAhead; /* Non-zero if this row is for a state that */
|
|
|
|
/* corresponds to a '/' in the rule source. */
|
|
|
|
/* Value is the same as the fAccepting */
|
|
|
|
/* value for the rule (which will appear */
|
|
|
|
/* in a different state. */
|
|
|
|
int16_t fTagIdx; /* Non-zero if this row covers a {tagged} position */
|
|
|
|
/* from a rule. Value is the index in the */
|
|
|
|
/* StatusTable of the set of matching */
|
|
|
|
/* tags (rule status values) */
|
2002-06-25 17:23:07 +00:00
|
|
|
int16_t fReserved;
|
2004-03-05 05:04:10 +00:00
|
|
|
uint16_t fNextState[2]; /* Next State, indexed by char category. */
|
|
|
|
/* Array Size is fNumCols from the */
|
|
|
|
/* state table header. */
|
|
|
|
/* CAUTION: see RBBITableBuilder::getTableSize() */
|
|
|
|
/* before changing anything here. */
|
2002-06-25 17:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct RBBIStateTable {
|
2003-12-04 02:12:42 +00:00
|
|
|
uint32_t fNumStates; /* Number of states. */
|
|
|
|
uint32_t fRowLen; /* Length of a state table row, in bytes. */
|
|
|
|
uint32_t fFlags; /* Option Flags for this state table */
|
|
|
|
uint32_t fReserved; /* reserved */
|
|
|
|
char fTableData[4]; /* First RBBIStateTableRow begins here. */
|
|
|
|
/* (making it char[] simplifies ugly address */
|
2003-11-24 19:48:37 +00:00
|
|
|
/* arithmetic for indexing variable length rows.) */
|
2002-06-25 17:23:07 +00:00
|
|
|
};
|
|
|
|
|
2003-12-04 02:12:42 +00:00
|
|
|
typedef enum {
|
2005-09-27 00:03:32 +00:00
|
|
|
RBBI_LOOKAHEAD_HARD_BREAK = 1,
|
|
|
|
RBBI_BOF_REQUIRED = 2
|
2003-12-04 02:12:42 +00:00
|
|
|
} RBBIStateTableFlags;
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2004-03-05 05:04:10 +00:00
|
|
|
/* */
|
2003-11-24 19:48:37 +00:00
|
|
|
/* The reference counting wrapper class */
|
2004-03-05 05:04:10 +00:00
|
|
|
/* */
|
2002-10-04 01:23:34 +00:00
|
|
|
class RBBIDataWrapper : public UMemory {
|
2002-06-25 17:23:07 +00:00
|
|
|
public:
|
|
|
|
RBBIDataWrapper(const RBBIDataHeader *data, UErrorCode &status);
|
|
|
|
RBBIDataWrapper(UDataMemory* udm, UErrorCode &status);
|
|
|
|
~RBBIDataWrapper();
|
|
|
|
|
|
|
|
void init(const RBBIDataHeader *data, UErrorCode &status);
|
|
|
|
RBBIDataWrapper *addReference();
|
|
|
|
void removeReference();
|
|
|
|
UBool operator ==(const RBBIDataWrapper &other) const;
|
|
|
|
int32_t hashCode();
|
2004-03-27 07:05:32 +00:00
|
|
|
const UnicodeString &getRuleSourceString() const;
|
2003-12-04 22:44:05 +00:00
|
|
|
#ifdef RBBI_DEBUG
|
2002-06-25 17:23:07 +00:00
|
|
|
void printData();
|
2003-11-05 02:03:44 +00:00
|
|
|
void printTable(const char *heading, const RBBIStateTable *table);
|
2003-12-04 22:44:05 +00:00
|
|
|
#else
|
|
|
|
#define printData()
|
|
|
|
#define printTable(heading, table)
|
|
|
|
#endif
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2004-03-05 05:04:10 +00:00
|
|
|
/* */
|
2003-11-24 19:48:37 +00:00
|
|
|
/* Pointers to items within the data */
|
2004-03-05 05:04:10 +00:00
|
|
|
/* */
|
2002-06-25 17:23:07 +00:00
|
|
|
const RBBIDataHeader *fHeader;
|
|
|
|
const RBBIStateTable *fForwardTable;
|
|
|
|
const RBBIStateTable *fReverseTable;
|
2003-11-05 02:03:44 +00:00
|
|
|
const RBBIStateTable *fSafeFwdTable;
|
|
|
|
const RBBIStateTable *fSafeRevTable;
|
2002-06-25 17:23:07 +00:00
|
|
|
const UChar *fRuleSource;
|
2004-03-05 05:04:10 +00:00
|
|
|
const int32_t *fRuleStatusTable;
|
|
|
|
|
|
|
|
/* number of int32_t values in the rule status table. Used to sanity check indexing */
|
|
|
|
int32_t fStatusMaxIdx;
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
UTrie fTrie;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t fRefCount;
|
|
|
|
UDataMemory *fUDataMem;
|
|
|
|
UnicodeString fRuleString;
|
|
|
|
|
2003-11-24 19:48:37 +00:00
|
|
|
RBBIDataWrapper(const RBBIDataWrapper &other); /* forbid copying of this class */
|
|
|
|
RBBIDataWrapper &operator=(const RBBIDataWrapper &other); /* forbid copying of this class */
|
2002-06-25 17:23:07 +00:00
|
|
|
};
|
|
|
|
|
2003-09-29 17:24:15 +00:00
|
|
|
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2003-11-19 01:00:18 +00:00
|
|
|
#endif /* C++ */
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2003-11-19 01:00:18 +00:00
|
|
|
#endif
|