Java Code Examples for com.ibm.icu.impl.Assert#assrt()

The following examples show how to use com.ibm.icu.impl.Assert#assrt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RBBINode.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
RBBINode(int t) {
    Assert.assrt(t < nodeTypeLimit);
    fSerialNum = ++gLastSerial;
    fType = t;

    fFirstPosSet = new HashSet<RBBINode>();
    fLastPosSet = new HashSet<RBBINode>();
    fFollowPos = new HashSet<RBBINode>();
    if (t == opCat) {
        fPrecedence = precOpCat;
    } else if (t == opOr) {
        fPrecedence = precOpOr;
    } else if (t == opStart) {
        fPrecedence = precStart;
    } else if (t == opLParen) {
        fPrecedence = precLParen;
    } else {
        fPrecedence = precZero;
    }
}
 
Example 2
Source File: RuleBasedBreakIterator.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private void makeRuleStatusValid() {
    if (fLastStatusIndexValid == false) {
        //  No cached status is available.
        int curr = current();
        if (curr == BreakIterator.DONE || curr == fText.getBeginIndex()) {
            //  At start of text, or there is no text.  Status is always zero.
            fLastRuleStatusIndex = 0;
            fLastStatusIndexValid = true;
        } else {
            //  Not at start of text.  Find status the tedious way.
            int pa = fText.getIndex();
            first();
            int pb = current();
            while (fText.getIndex() < pa) {
                pb = next();
            }
            Assert.assrt(pa == pb);
        }
        Assert.assrt(fLastStatusIndexValid == true);
        Assert.assrt(fLastRuleStatusIndex >= 0  &&  fLastRuleStatusIndex < fRData.fStatusTable.length);
    }
}
 
Example 3
Source File: RBBITableBuilder.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
void bofFixup() {
    //
    //   The parse tree looks like this ...
    //         fTree root  --.       <cat>
    //                               /     \
    //                            <cat>   <#end node>
    //                           /     \
    //                     <bofNode>   rest
    //                               of tree
    //
    //    We will be adding things to the followPos set of the <bofNode>
    //
    RBBINode  bofNode = fRB.fTreeRoots[fRootIx].fLeftChild.fLeftChild;
    Assert.assrt(bofNode.fType == RBBINode.leafChar);
    Assert.assrt(bofNode.fVal == 2);

    // Get all nodes that can be the start a match of the user-written rules
    //  (excluding the fake bofNode)
    //  We want the nodes that can start a match in the
    //     part labeled "rest of tree"
    //
    Set<RBBINode> matchStartNodes = fRB.fTreeRoots[fRootIx].fLeftChild.fRightChild.fFirstPosSet;
    for (RBBINode startNode : matchStartNodes) {
        if (startNode.fType != RBBINode.leafChar) {
            continue;
        }

        if (startNode.fVal == bofNode.fVal) {
            //  We found a leaf node corresponding to a {bof} that was
            //    explicitly written into a rule.
            //  Add everything from the followPos set of this node to the
            //    followPos set of the fake bofNode at the start of the tree.
            //
            bofNode.fFollowPos.addAll(startNode.fFollowPos);
        }
    }
}
 
Example 4
Source File: RBBISetBuilder.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
void split(int where) {
    Assert.assrt(where>fStartChar && where<=fEndChar);
    RangeDescriptor nr = new RangeDescriptor(this);
 
    //  RangeDescriptor copy constructor copies all fields.
    //  Only need to update those that are different after the split.
    nr.fStartChar = where;
    this.fEndChar = where-1;
    nr.fNext      = this.fNext;
    this.fNext    = nr;
    
    // TODO:  fIncludesSets is not updated.  Check it out.
    //         Probably because they haven't been populated yet, 
    //         but still sloppy.
}
 
Example 5
Source File: RBBISetBuilder.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
int getTrieSize()  {
    int size = 0;
    try {
        // The trie serialize function returns the size of the data written.
        //    null output stream says give size only, don't actually write anything.
        size = fTrie.serialize(null, true, dm );
    } catch (IOException e) {
        Assert.assrt (false);
    }
    return size;
}
 
Example 6
Source File: BytesDictionaryMatcher.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
public BytesDictionaryMatcher(byte[] chars, int transform) {
    characters = chars;
    Assert.assrt((transform & DictionaryData.TRANSFORM_TYPE_MASK) == DictionaryData.TRANSFORM_TYPE_OFFSET);
    // while there is only one transform type so far, save the entire transform constant so that
    // if we add any others, we need only change code in transform() and the assert above rather
    // than adding a "transform type" variable
    this.transform = transform;
}
 
Example 7
Source File: RBBITableBuilder.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
void buildStateTable() {
    //
    // Add a dummy state 0 - the stop state.  Not from Aho.
    int      lastInputSymbol = fRB.fSetBuilder.getNumCharCategories() - 1;
    RBBIStateDescriptor failState = new RBBIStateDescriptor(lastInputSymbol);
    fDStates.add(failState);

    // initially, the only unmarked state in Dstates is firstpos(root),
    //       where toot is the root of the syntax tree for (r)#;
    RBBIStateDescriptor initialState = new RBBIStateDescriptor(lastInputSymbol);
    initialState.fPositions.addAll(fRB.fTreeRoots[fRootIx].fFirstPosSet);
    fDStates.add(initialState);

    // while there is an unmarked state T in Dstates do begin
    for (;;) {
        RBBIStateDescriptor T = null;
        int              tx;
        for (tx=1; tx<fDStates.size(); tx++) {
            RBBIStateDescriptor temp  = fDStates.get(tx);
            if (temp.fMarked == false) {
                T = temp;
                break;
            }
        }
        if (T == null) {
            break;
        }

        // mark T;
        T.fMarked = true;

        // for each input symbol a do begin
        int  a;
        for (a = 1; a<=lastInputSymbol; a++) {
            // let U be the set of positions that are in followpos(p)
            //    for some position p in T
            //    such that the symbol at position p is a;
            Set<RBBINode> U = null;
            for (RBBINode p : T.fPositions) {
                if ((p.fType == RBBINode.leafChar) &&  (p.fVal == a)) {
                    if (U == null) {
                        U = new HashSet<RBBINode>();
                    }
                    U.addAll(p.fFollowPos);
                }
            }

            // if U is not empty and not in DStates then
            int  ux = 0;
            boolean    UinDstates = false;
            if (U != null) {
                Assert.assrt(U.size() > 0);
                int  ix;
                for (ix=0; ix<fDStates.size(); ix++) {
                    RBBIStateDescriptor temp2;
                    temp2 = fDStates.get(ix);
                    if (U.equals(temp2.fPositions)) {
                        U  = temp2.fPositions;
                        ux = ix;
                        UinDstates = true;
                        break;
                    }
                }

                // Add U as an unmarked state to Dstates
                if (!UinDstates)
                {
                    RBBIStateDescriptor newState = new RBBIStateDescriptor(lastInputSymbol);
                    newState.fPositions = U;
                    fDStates.add(newState);
                    ux = fDStates.size()-1;
                }

                // Dtran[T, a] := U;
                T.fDtran[a] = ux;
            }
        }
    }
}
 
Example 8
Source File: RBBITableBuilder.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
short [] exportTable() {
    int                state;
    int                col;

    if (fRB.fTreeRoots[fRootIx] == null) {
        return new short[0];
    }

    Assert.assrt(fRB.fSetBuilder.getNumCharCategories() < 0x7fff &&
        fDStates.size() < 0x7fff);

    int numStates = fDStates.size();

    // Size of table size in shorts.
    //  the "4" is the size of struct RBBIStateTableRow, the row header part only.
    int rowLen = 4 + fRB.fSetBuilder.getNumCharCategories();
    int tableSize = getTableSize() / 2;


    short [] table = new short[tableSize];

    //
    // Fill in the header fields.
    //      Annoying because they really want to be ints, not shorts.
    //
    // RBBIStateTable.fNumStates
    table[RBBIDataWrapper.NUMSTATES]   = (short)(numStates >>> 16);
    table[RBBIDataWrapper.NUMSTATES+1] = (short)(numStates & 0x0000ffff);

    // RBBIStateTable.fRowLen
    table[RBBIDataWrapper.ROWLEN]   = (short)(rowLen >>> 16);
    table[RBBIDataWrapper.ROWLEN+1] = (short)(rowLen & 0x0000ffff);

    // RBBIStateTable.fFlags
    int flags = 0;
    if (fRB.fLookAheadHardBreak) {
        flags  |= RBBIDataWrapper.RBBI_LOOKAHEAD_HARD_BREAK;
    }
    if (fRB.fSetBuilder.sawBOF()) {
        flags  |= RBBIDataWrapper.RBBI_BOF_REQUIRED;
    }
    table[RBBIDataWrapper.FLAGS]   = (short)(flags >>> 16);
    table[RBBIDataWrapper.FLAGS+1] = (short)(flags & 0x0000ffff);

    int numCharCategories = fRB.fSetBuilder.getNumCharCategories();
    for (state=0; state<numStates; state++) {
        RBBIStateDescriptor sd = fDStates.get(state);
        int                row = 8 + state*rowLen;
        Assert.assrt (-32768 < sd.fAccepting && sd.fAccepting <= 32767);
        Assert.assrt (-32768 < sd.fLookAhead && sd.fLookAhead <= 32767);
        table[row + RBBIDataWrapper.ACCEPTING] = (short)sd.fAccepting;
        table[row + RBBIDataWrapper.LOOKAHEAD] = (short)sd.fLookAhead;
        table[row + RBBIDataWrapper.TAGIDX]    = (short)sd.fTagsIdx;
        for (col=0; col<numCharCategories; col++) {
            table[row + RBBIDataWrapper.NEXTSTATES + col] = (short)sd.fDtran[col];
        }
    }
    return table;
}
 
Example 9
Source File: RBBIRuleScanner.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
void findSetFor(String s, RBBINode node, UnicodeSet setToAdopt) {

        RBBISetTableEl el;

        // First check whether we've already cached a set for this string.
        // If so, just use the cached set in the new node.
        //   delete any set provided by the caller, since we own it.
        el = fSetTable.get(s);
        if (el != null) {
            node.fLeftChild = el.val;
            Assert.assrt(node.fLeftChild.fType == RBBINode.uset);
            return;
        }

        // Haven't seen this set before.
        // If the caller didn't provide us with a prebuilt set,
        //   create a new UnicodeSet now.
        if (setToAdopt == null) {
            if (s.equals(kAny)) {
                setToAdopt = new UnicodeSet(0x000000, 0x10ffff);
            } else {
                int c;
                c = UTF16.charAt(s, 0);
                setToAdopt = new UnicodeSet(c, c);
            }
        }

        //
        // Make a new uset node to refer to this UnicodeSet
        // This new uset node becomes the child of the caller's setReference
        // node.
        //
        RBBINode usetNode = new RBBINode(RBBINode.uset);
        usetNode.fInputSet = setToAdopt;
        usetNode.fParent = node;
        node.fLeftChild = usetNode;
        usetNode.fText = s;

        //
        // Add the new uset node to the list of all uset nodes.
        //
        fRB.fUSetNodes.add(usetNode);

        //
        // Add the new set to the set hash table.
        //
        el = new RBBISetTableEl();
        el.key = s;
        el.val = usetNode;
        fSetTable.put(el.key, el);

        return;
    }