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
|
2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
// rbbisetb.h
|
|
|
|
/*
|
|
|
|
**********************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 2001-2005, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2002-06-25 17:23:07 +00:00
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RBBISETB_H
|
|
|
|
#define RBBISETB_H
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/utypes.h"
|
2017-09-12 20:29:14 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
|
|
|
|
2020-05-19 20:44:14 +00:00
|
|
|
#include "unicode/ucptrie.h"
|
|
|
|
#include "unicode/umutablecptrie.h"
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/uobject.h"
|
2002-06-25 17:23:07 +00:00
|
|
|
#include "rbbirb.h"
|
|
|
|
#include "uvector.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
//
|
|
|
|
// RBBISetBuilder Derives the character categories used by the runtime RBBI engine
|
|
|
|
// from the Unicode Sets appearing in the source RBBI rules, and
|
|
|
|
// creates the TRIE table used to map from Unicode to the
|
|
|
|
// character categories.
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// RangeDescriptor
|
|
|
|
//
|
|
|
|
// Each of the non-overlapping character ranges gets one of these descriptors.
|
|
|
|
// All of them are strung together in a linked list, which is kept in order
|
|
|
|
// (by character)
|
|
|
|
//
|
2002-10-04 01:23:34 +00:00
|
|
|
class RangeDescriptor : public UMemory {
|
2002-08-08 00:39:13 +00:00
|
|
|
public:
|
2020-06-09 20:19:17 +00:00
|
|
|
UChar32 fStartChar {}; // Start of range, unicode 32 bit value.
|
|
|
|
UChar32 fEndChar {}; // End of range, unicode 32 bit value.
|
|
|
|
int32_t fNum {0}; // runtime-mapped input value for this range.
|
|
|
|
bool fIncludesDict {false}; // True if the range includes $dictionary.
|
|
|
|
bool fFirstInGroup {false}; // True if first range in a group with the same fNum.
|
|
|
|
UVector *fIncludesSets {nullptr}; // vector of the the original
|
|
|
|
// Unicode sets that include this range.
|
|
|
|
// (Contains ptrs to uset nodes)
|
|
|
|
RangeDescriptor *fNext {nullptr}; // Next RangeDescriptor in the linked list.
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
RangeDescriptor(UErrorCode &status);
|
|
|
|
RangeDescriptor(const RangeDescriptor &other, UErrorCode &status);
|
|
|
|
~RangeDescriptor();
|
|
|
|
void split(UChar32 where, UErrorCode &status); // Spit this range in two at "where", with
|
|
|
|
// where appearing in the second (higher) part.
|
2020-06-09 20:19:17 +00:00
|
|
|
bool isDictionaryRange(); // Check whether this range appears as part of
|
2002-06-25 17:23:07 +00:00
|
|
|
// the Unicode set named "dictionary"
|
2002-07-16 01:55:55 +00:00
|
|
|
|
2020-06-09 20:19:17 +00:00
|
|
|
RangeDescriptor(const RangeDescriptor &other) = delete; // forbid default copying of this class
|
|
|
|
RangeDescriptor &operator=(const RangeDescriptor &other) = delete; // forbid assigning of this class
|
2002-06-25 17:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// RBBISetBuilder Handles processing of Unicode Sets from RBBI rules.
|
|
|
|
//
|
|
|
|
// Starting with the rules parse tree from the scanner,
|
|
|
|
//
|
|
|
|
// - Enumerate the set of UnicodeSets that are referenced
|
|
|
|
// by the RBBI rules.
|
|
|
|
// - compute a derived set of non-overlapping UnicodeSets
|
|
|
|
// that will correspond to columns in the state table for
|
|
|
|
// the RBBI execution engine.
|
|
|
|
// - construct the trie table that maps input characters
|
|
|
|
// to set numbers in the non-overlapping set of sets.
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2002-10-04 01:23:34 +00:00
|
|
|
class RBBISetBuilder : public UMemory {
|
2002-06-25 17:23:07 +00:00
|
|
|
public:
|
|
|
|
RBBISetBuilder(RBBIRuleBuilder *rb);
|
|
|
|
~RBBISetBuilder();
|
|
|
|
|
2018-02-08 01:42:04 +00:00
|
|
|
void buildRanges();
|
|
|
|
void buildTrie();
|
2005-03-23 02:13:53 +00:00
|
|
|
void addValToSets(UVector *sets, uint32_t val);
|
|
|
|
void addValToSet (RBBINode *usetNode, uint32_t val);
|
2004-03-27 07:05:32 +00:00
|
|
|
int32_t getNumCharCategories() const; // CharCategories are the same as input symbol set to the
|
2005-09-27 00:03:32 +00:00
|
|
|
// runtime state machine, which are the same as
|
|
|
|
// columns in the DFA state table
|
2020-06-09 20:19:17 +00:00
|
|
|
int32_t getDictCategoriesStart() const; // First char category that includes $dictionary, or
|
|
|
|
// last category + 1 if there are no dictionary categories.
|
2004-03-27 07:05:32 +00:00
|
|
|
int32_t getTrieSize() /*const*/; // Size in bytes of the serialized Trie.
|
2002-06-25 17:23:07 +00:00
|
|
|
void serializeTrie(uint8_t *where); // write out the serialized Trie.
|
2004-03-27 07:05:32 +00:00
|
|
|
UChar32 getFirstChar(int32_t val) const;
|
2005-09-27 00:03:32 +00:00
|
|
|
UBool sawBOF() const; // Indicate whether any references to the {bof} pseudo
|
|
|
|
// character were encountered.
|
2018-04-06 00:19:32 +00:00
|
|
|
/**
|
|
|
|
* Merge two character categories that have been identified as having equivalent behavior.
|
|
|
|
* The ranges belonging to the second category (table column) will be added to the first.
|
|
|
|
* @param categories the pair of categories to be merged.
|
2018-02-08 01:42:04 +00:00
|
|
|
*/
|
2018-04-06 00:19:32 +00:00
|
|
|
void mergeCategories(IntPair categories);
|
2018-02-08 01:42:04 +00:00
|
|
|
|
2003-12-04 22:44:05 +00:00
|
|
|
#ifdef RBBI_DEBUG
|
2002-06-25 17:23:07 +00:00
|
|
|
void printSets();
|
|
|
|
void printRanges();
|
|
|
|
void printRangeGroups();
|
2003-12-04 22:44:05 +00:00
|
|
|
#else
|
|
|
|
#define printSets()
|
|
|
|
#define printRanges()
|
|
|
|
#define printRangeGroups()
|
|
|
|
#endif
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
RBBIRuleBuilder *fRB; // The RBBI Rule Compiler that owns us.
|
|
|
|
UErrorCode *fStatus;
|
|
|
|
|
|
|
|
RangeDescriptor *fRangeList; // Head of the linked list of RangeDescriptors
|
|
|
|
|
2020-05-19 20:44:14 +00:00
|
|
|
UMutableCPTrie *fMutableTrie; // The mapping TRIE that is the end result of processing
|
|
|
|
UCPTrie *fTrie; // the Unicode Sets.
|
|
|
|
uint32_t fTrieSize;
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2020-06-09 20:19:17 +00:00
|
|
|
// Number of range groups, which are groups of ranges that are in the same original UnicodeSets.
|
2002-06-25 17:23:07 +00:00
|
|
|
int32_t fGroupCount;
|
|
|
|
|
2020-06-09 20:19:17 +00:00
|
|
|
// The number of the first dictionary char category.
|
|
|
|
// If there are no Dictionary categories, set to the last category + 1.
|
|
|
|
int32_t fDictCategoriesStart;
|
|
|
|
|
2005-09-27 00:03:32 +00:00
|
|
|
UBool fSawBOF;
|
|
|
|
|
2022-09-08 21:15:13 +00:00
|
|
|
RBBISetBuilder(const RBBISetBuilder &other) = delete; // forbid copying of this class
|
|
|
|
RBBISetBuilder &operator=(const RBBISetBuilder &other) = delete; // forbid copying of this class
|
2002-06-25 17:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
2017-09-12 20:29:14 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
#endif
|