2003-11-19 01:00:18 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2003, International Business Machines
|
|
|
|
* 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 {
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fMagic; /* == 0xbla0 */
|
|
|
|
uint32_t fVersion; /* == 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. */
|
|
|
|
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
uint32_t fFTable; /* forward state transition table. */
|
2002-06-25 17:23:07 +00:00
|
|
|
uint32_t fFTableLen;
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fRTable; /* Offset to the reverse state transition table. */
|
2002-06-25 17:23:07 +00:00
|
|
|
uint32_t fRTableLen;
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fSFTable; /* safe point forward transition table */
|
2003-11-05 02:03:44 +00:00
|
|
|
uint32_t fSFTableLen;
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fSRTable; /* safe point reverse transition table */
|
2003-11-05 02:03:44 +00:00
|
|
|
uint32_t fSRTableLen;
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fTrie; /* Offset to Trie data for character categories */
|
2002-06-25 17:23:07 +00:00
|
|
|
uint32_t fTrieLen;
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fRuleSource; /* Offset to the source for for the break */
|
|
|
|
uint32_t fRuleSourceLen; /* rules. Stored UChar *. */
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2003-11-24 19:48:37 +00:00
|
|
|
uint32_t fReserved[8]; /* Reserved for expansion */
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct RBBIStateTableRow {
|
2003-11-24 19:48:37 +00:00
|
|
|
int16_t fAccepting; /* Non-zero if this row is for an accepting state. */
|
|
|
|
/* Value is the {nnn} value to return to calling */
|
|
|
|
/* application. */
|
|
|
|
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 fTag; /* Non-zero if this row covers a {tagged} position */
|
|
|
|
/* from a rule. value is the tag number. */
|
2002-06-25 17:23:07 +00:00
|
|
|
int16_t fReserved;
|
2003-11-24 19:48:37 +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 {
|
|
|
|
RBBI_LOOKAHEAD_HARD_BREAK = 1
|
|
|
|
} RBBIStateTableFlags;
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2003-11-24 19:48:37 +00:00
|
|
|
/* */
|
|
|
|
/* The reference counting wrapper class */
|
|
|
|
/* */
|
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();
|
|
|
|
const UnicodeString &getRuleSourceString();
|
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
|
|
|
|
2003-11-24 19:48:37 +00:00
|
|
|
/* */
|
|
|
|
/* Pointers to items within the data */
|
|
|
|
/* */
|
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;
|
|
|
|
|
|
|
|
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
|