private void ResolveAvailableBracketPairs()
        {
            CharType embeddingDirection = Level.MakeEmbeddingType(_level);
            CharType oppositeDirection  = Level.MakeOppositeType(_level);

            while (!_bracketQueue.IsEmpty)
            {
                BracketPair pair = _bracketQueue.Peek();

                if (pair.IsComplete)
                {
                    CharType innerStrongType = pair.innerStrongType;
                    CharType pairType;

                    // Rule: N0.b
                    if (innerStrongType == embeddingDirection)
                    {
                        pairType = innerStrongType;
                    }
                    // Rule: N0.c
                    else if (innerStrongType == oppositeDirection)
                    {
                        BidiLink priorStrongLink;
                        CharType priorStrongType;

                        priorStrongLink = pair.priorStrongLink;

                        if (priorStrongLink != null)
                        {
                            priorStrongType = priorStrongLink.type;
                            if (priorStrongType == CharType.EN || priorStrongType == CharType.AN)
                            {
                                priorStrongType = CharType.R;
                            }

                            BidiLink link  = priorStrongLink.Next;
                            BidiLink start = pair.openingLink;

                            while (link != start)
                            {
                                CharType type = link.type;
                                if (type == CharType.L || type == CharType.R)
                                {
                                    priorStrongType = type;
                                }

                                link = link.Next;
                            }
                        }
                        else
                        {
                            priorStrongType = _sos;
                        }

                        // Rule: N0.c.1
                        if (priorStrongType == oppositeDirection)
                        {
                            pairType = oppositeDirection;
                        }
                        // Rule: N0.c.2
                        else
                        {
                            pairType = embeddingDirection;
                        }
                    }
                    // Rule: N0.d
                    else
                    {
                        pairType = CharType.Nil;
                    }

                    if (pairType != CharType.Nil)
                    {
                        // Do the substitution
                        pair.openingLink.type = pairType;
                        pair.closingLink.type = pairType;
                    }
                }

                _bracketQueue.Dequeue();
            }
        }
        private void ResolveBrackets()
        {
            BidiLink strongLink = null;

            _bracketQueue.Clear(Level.MakeEmbeddingType(_level));

            for (BidiLink link = _roller.Next; link != _roller; link = link.Next)
            {
                CharType type = link.type;

                switch (type)
                {
                case CharType.ON:
                    BracketType bracketType;

                    char ch           = Text[link.offset];
                    int  bracketValue = PairingLookup.DetermineBracketPair((int)ch, out bracketType);

                    switch (bracketType)
                    {
                    case BracketType.Open:
                        BracketPair bracketPair = new BracketPair()
                        {
                            bracketUnicode  = ch,
                            openingLink     = link,
                            priorStrongLink = strongLink
                        };
                        _bracketQueue.Enqueue(bracketPair);
                        break;

                    case BracketType.Close:
                        if (!_bracketQueue.IsEmpty)
                        {
                            _bracketQueue.ClosePair(link, bracketValue);

                            if (_bracketQueue.ShouldDequeue)
                            {
                                ResolveAvailableBracketPairs();
                            }
                        }
                        break;
                    }
                    break;

                case CharType.L:
                case CharType.R:
                case CharType.AL:
                case CharType.EN:
                case CharType.AN:
                    if (!_bracketQueue.IsEmpty)
                    {
                        if (type == CharType.EN || type == CharType.AN)
                        {
                            type = CharType.R;
                        }

                        _bracketQueue.SetStrongType(type);
                    }
                    strongLink = link;
                    break;
                }
            }

            ResolveAvailableBracketPairs();
        }