• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Tehreer / SheenBidi / 15449978665

04 Jun 2025 06:32PM UTC coverage: 96.745% (+0.01%) from 96.733%
15449978665

push

github

mta452
[test] Add failures assertion in all test classes

2110 of 2181 relevant lines covered (96.74%)

703527.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.35
/Source/BracketQueue.c
1
/*
2
 * Copyright (C) 2014-2025 Muhammad Tayyab Akram
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
#include <stddef.h>
18

19
#include <SheenBidi/SBConfig.h>
20

21
#include "BidiChain.h"
22
#include "Object.h"
23
#include "SBAssert.h"
24
#include "SBBase.h"
25
#include "SBCodepoint.h"
26
#include "BracketQueue.h"
27

28
static SBBoolean BracketQueueInsertElement(BracketQueueRef queue)
329,475✔
29
{
30
    if (queue->_rearTop != BracketQueueList_MaxIndex) {
329,475✔
31
        queue->_rearTop += 1;
329,454✔
32
    } else {
33
        BracketQueueListRef previousList = queue->_rearList;
21✔
34
        BracketQueueListRef rearList = previousList->next;
21✔
35

36
        if (!rearList) {
21✔
37
            rearList = ObjectAddMemory(&queue->_object, sizeof(BracketQueueList));
21✔
38
            if (!rearList) {
21✔
39
                return SBFalse;
×
40
            }
41

42
            rearList->previous = previousList;
21✔
43
            rearList->next = NULL;
21✔
44

45
            previousList->next = rearList;
21✔
46
        }
47

48
        queue->_rearList = rearList;
21✔
49
        queue->_rearTop = 0;
21✔
50
    }
51
    queue->count += 1;
329,475✔
52

53
    return SBTrue;
329,475✔
54
}
55

56
static void BracketQueueFinalizePairs(BracketQueueRef queue, BracketQueueListRef list, SBInteger top)
139,723✔
57
{
58
    do {
59
        SBInteger limit = (list == queue->_rearList ? queue->_rearTop : BracketQueueList_MaxIndex);
140,171✔
60

61
        while (++top <= limit) {
188,195✔
62
            if (list->openingLink[top] != BidiLinkNone
48,024✔
63
                && list->closingLink[top] == BidiLinkNone) {
48,016✔
64
                list->openingLink[top] = BidiLinkNone;
20,528✔
65
            }
66
        }
67

68
        list = list->next;
140,171✔
69
        top = 0;
140,171✔
70
    } while (list);
140,171✔
71
}
139,723✔
72

73
SB_INTERNAL void BracketQueueInitialize(BracketQueueRef queue)
861,949✔
74
{
75
    ObjectInitialize(&queue->_object);
861,949✔
76

77
    queue->_firstList.previous = NULL;
861,949✔
78
    queue->_firstList.next = NULL;
861,949✔
79
    queue->_frontList = NULL;
861,949✔
80
    queue->_rearList = NULL;
861,949✔
81
    queue->count = 0;
861,949✔
82
    queue->shouldDequeue = SBFalse;
861,949✔
83
}
861,949✔
84

85
SB_INTERNAL void BracketQueueReset(BracketQueueRef queue, SBBidiType direction)
1,257,049✔
86
{
87
    queue->_frontList = &queue->_firstList;
1,257,049✔
88
    queue->_rearList = &queue->_firstList;
1,257,049✔
89
    queue->_frontTop = 0;
1,257,049✔
90
    queue->_rearTop = -1;
1,257,049✔
91
    queue->count = 0;
1,257,049✔
92
    queue->shouldDequeue = SBFalse;
1,257,049✔
93
    queue->_direction = direction;
1,257,049✔
94
}
1,257,049✔
95

96
SB_INTERNAL SBBoolean BracketQueueEnqueue(BracketQueueRef queue,
329,475✔
97
   BidiLink priorStrongLink, BidiLink openingLink, SBCodepoint bracket)
98
{
99
    /* The queue can only take a maximum of 63 elements. */
100
    SBAssert(queue->count < BracketQueueGetMaxCapacity());
329,475✔
101

102
    if (BracketQueueInsertElement(queue)) {
329,475✔
103
        BracketQueueListRef list = queue->_rearList;
329,475✔
104
        SBInteger top = queue->_rearTop;
329,475✔
105

106
        list->priorStrongLink[top] = priorStrongLink;
329,475✔
107
        list->openingLink[top] = openingLink;
329,475✔
108
        list->closingLink[top] = BidiLinkNone;
329,475✔
109
        list->bracket[top] = bracket;
329,475✔
110
        list->strongType[top] = SBBidiTypeNil;
329,475✔
111

112
        return SBTrue;
329,475✔
113
    }
114

115
    return SBFalse;
×
116
}
117

118
SB_INTERNAL void BracketQueueDequeue(BracketQueueRef queue)
329,475✔
119
{
120
    /* The queue must NOT be empty. */
121
    SBAssert(queue->count != 0);
329,475✔
122

123
    if (queue->_frontTop != BracketQueueList_MaxIndex) {
329,475✔
124
        queue->_frontTop += 1;
329,454✔
125
    } else {
126
        BracketQueueListRef frontList = queue->_frontList;
21✔
127

128
        if (frontList == queue->_rearList) {
21✔
129
            queue->_rearTop = -1;
×
130
        } else {
131
            queue->_frontList = frontList->next;
21✔
132
        }
133

134
        queue->_frontTop = 0;
21✔
135
    }
136

137
    queue->count -= 1;
329,475✔
138
}
329,475✔
139

140
SB_INTERNAL void BracketQueueSetStrongType(BracketQueueRef queue, SBBidiType strongType)
186,688✔
141
{
142
    BracketQueueListRef list = queue->_rearList;
186,688✔
143
    SBInteger top = queue->_rearTop;
186,688✔
144

145
    while (1) {
14✔
146
        SBInteger limit = (list == queue->_frontList ? queue->_frontTop : 0);
186,702✔
147

148
        do {
149
            if (list->closingLink[top] == BidiLinkNone
315,203✔
150
                && list->strongType[top] != queue->_direction) {
265,403✔
151
                list->strongType[top] = strongType;
206,184✔
152
            }
153
        } while (top-- > limit);
315,203✔
154

155
        if (list == queue->_frontList) {
186,702✔
156
            break;
186,688✔
157
        }
158

159
        list = list->previous;
14✔
160
        top = BracketQueueList_MaxIndex;
14✔
161
    }
162
}
186,688✔
163

164
SB_INTERNAL void BracketQueueClosePair(BracketQueueRef queue, BidiLink closingLink, SBCodepoint bracket)
154,290✔
165
{
166
    BracketQueueListRef list = queue->_rearList;
154,290✔
167
    SBInteger top = queue->_rearTop;
154,290✔
168

169
    while (1) {
448✔
170
        SBBoolean isFrontList = (list == queue->_frontList);
154,738✔
171
        SBInteger limit = (isFrontList ? queue->_frontTop : 0);
154,738✔
172

173
        do {
174
            if (list->openingLink[top] != BidiLinkNone
227,002✔
175
                && list->closingLink[top] == BidiLinkNone
214,876✔
176
                && SBCodepointIsCanonicalEquivalentBracket(list->bracket[top], bracket)) {
174,818✔
177
                list->closingLink[top] = closingLink;
139,723✔
178
                BracketQueueFinalizePairs(queue, list, top);
139,723✔
179

180
                if (isFrontList && top == queue->_frontTop) {
139,723✔
181
                    queue->shouldDequeue = SBTrue;
62,172✔
182
                }
183

184
                return;
139,723✔
185
            }
186
        } while (top-- > limit);
87,279✔
187

188
        if (isFrontList) {
15,015✔
189
            break;
14,567✔
190
        }
191

192
        list = list->previous;
448✔
193
        top = BracketQueueList_MaxIndex;
448✔
194
    }
195
}
196

197
SB_INTERNAL SBBoolean BracketQueueShouldDequeue(BracketQueueRef queue)
154,290✔
198
{
199
    return queue->shouldDequeue;
154,290✔
200
}
201

202
SB_INTERNAL BidiLink BracketQueueGetPriorStrongLink(BracketQueueRef queue)
28,864✔
203
{
204
    return queue->_frontList->priorStrongLink[queue->_frontTop];
28,864✔
205
}
206

207
SB_INTERNAL BidiLink BracketQueueGetOpeningLink(BracketQueueRef queue)
329,475✔
208
{
209
    return queue->_frontList->openingLink[queue->_frontTop];
329,475✔
210
}
211

212
SB_INTERNAL BidiLink BracketQueueGetClosingLink(BracketQueueRef queue)
329,475✔
213
{
214
    return queue->_frontList->closingLink[queue->_frontTop];
329,475✔
215
}
216

217
SB_INTERNAL SBBidiType BracketQueueGetStrongType(BracketQueueRef queue)
139,723✔
218
{
219
    return queue->_frontList->strongType[queue->_frontTop];
139,723✔
220
}
221

222
SB_INTERNAL void BracketQueueFinalize(BracketQueueRef queue)
861,949✔
223
{
224
    ObjectFinalize(&queue->_object);
861,949✔
225
}
861,949✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc