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

Tehreer / SheenBidi / 15618549131

12 Jun 2025 06:45PM UTC coverage: 97.027% (+0.4%) from 96.656%
15618549131

push

github

mta452
[lib] Mark SBLine as immutable

3 of 3 new or added lines in 1 file covered. (100.0%)

31 existing lines in 5 files now uncovered.

2121 of 2186 relevant lines covered (97.03%)

754359.57 hits per line

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

96.05
/Source/SBScriptLocator.c
1
/*
2
 * Copyright (C) 2018-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 "GeneralCategoryLookup.h"
20
#include "Object.h"
21
#include "PairingLookup.h"
22
#include "SBBase.h"
23
#include "SBCodepoint.h"
24
#include "SBCodepointSequence.h"
25
#include "ScriptLookup.h"
26
#include "ScriptStack.h"
27
#include "SBScriptLocator.h"
28

29
static SBBoolean IsSimilarScript(SBScript lhs, SBScript rhs)
162✔
30
{
31
    return SBScriptIsCommonOrInherited(lhs)
32
        || SBScriptIsCommonOrInherited(rhs)
144✔
33
        || lhs == rhs;
306✔
34
}
35

36
SBScriptLocatorRef SBScriptLocatorCreate(void)
9✔
37
{
38
    const SBUInteger size = sizeof(SBScriptLocator);
9✔
39
    void *pointer = NULL;
9✔
40
    SBScriptLocatorRef locator;
41

42
    locator = ObjectCreate(&size, 1, &pointer, NULL);
9✔
43

44
    if (locator) {
9✔
45
        locator->_codepointSequence.stringEncoding = SBStringEncodingUTF8;
9✔
46
        locator->_codepointSequence.stringBuffer = NULL;
9✔
47
        locator->_codepointSequence.stringLength = 0;
9✔
48

49
        SBScriptLocatorReset(locator);
9✔
50
    }
51

52
    return locator;
9✔
53
}
54

55
void SBScriptLocatorLoadCodepoints(SBScriptLocatorRef locator, const SBCodepointSequence *codepointSequence)
9✔
56
{
57
    locator->_codepointSequence = *codepointSequence;
9✔
58
    SBScriptLocatorReset(locator);
9✔
59
}
9✔
60

61
const SBScriptAgent *SBScriptLocatorGetAgent(SBScriptLocatorRef locator)
9✔
62
{
63
    return &locator->agent;
9✔
64
}
65

66
static void ResolveScriptRun(SBScriptLocatorRef locator, SBUInteger offset)
17✔
67
{
68
    const SBCodepointSequence *sequence = &locator->_codepointSequence;
17✔
69
    ScriptStackRef stack = &locator->_scriptStack;
17✔
70
    SBScript result = SBScriptZYYY;
17✔
71
    SBUInteger current = offset;
17✔
72
    SBUInteger next = offset;
17✔
73
    SBCodepoint codepoint;
74

75
    /* Iterate over the code points of specified string buffer. */
76
    while ((codepoint = SBCodepointSequenceGetCodepointAt(sequence, &next)) != SBCodepointInvalid) {
170✔
77
        SBBoolean isStacked = SBFalse;
162✔
78
        SBScript script;
79

80
        script = LookupScript(codepoint);
162✔
81

82
        /* Handle paired punctuations in case of a common script. */
83
        if (script == SBScriptZYYY) {
162✔
84
            SBGeneralCategory generalCategory = LookupGeneralCategory(codepoint);
35✔
85

86
            /* Check if current code point is an open punctuation. */
87
            if (generalCategory == SBGeneralCategoryPS) {
35✔
88
                SBCodepoint mirror = LookupMirror(codepoint);
4✔
89
                if (mirror) {
4✔
90
                    /* A closing pair exists for this punctuation, so push it onto the stack. */
91
                    ScriptStackPush(stack, result, mirror);
4✔
92
                }
93
            }
94
            /* Check if current code point is a close punctuation. */
95
            else if (generalCategory == SBGeneralCategoryPE) {
31✔
96
                SBBoolean isMirrored = (LookupMirror(codepoint) != 0);
7✔
97
                if (isMirrored) {
7✔
98
                    /* Find the matching entry in the stack, while popping the unmatched ones. */
99
                    while (!ScriptStackIsEmpty(stack)) {
7✔
100
                        SBCodepoint mirror = ScriptStackGetMirror(stack);
7✔
101
                        if (mirror != codepoint) {
7✔
UNCOV
102
                            ScriptStackPop(stack);
×
103
                        } else {
104
                            break;
7✔
105
                        }
106
                    }
107

108
                    if (!ScriptStackIsEmpty(stack)) {
7✔
109
                        isStacked = SBTrue;
7✔
110
                        /* Paired punctuation match the script of enclosing text. */
111
                        script = ScriptStackGetScript(stack);
7✔
112
                    }
113
                }
114
            }
115
        }
116

117
        if (IsSimilarScript(result, script)) {
162✔
118
            if (SBScriptIsCommonOrInherited(result) && !SBScriptIsCommonOrInherited(script)) {
153✔
119
                /* Set the concrete script of this code point as the result. */
120
                result = script;
17✔
121
                /* Seal the pending punctuations with the result. */
122
                ScriptStackSealPairs(stack, result);
17✔
123
            }
124

125
            if (isStacked) {
153✔
126
                /* Pop the paired punctuation from the stack. */
127
                ScriptStackPop(stack);
4✔
128
            }
129
        } else {
130
            /* The current code point has a different script, so finish the run. */
131
            break;
9✔
132
        }
133

134
        current = next;
153✔
135
    }
136

137
    ScriptStackLeavePairs(stack);
17✔
138

139
    /* Set the run info in agent. */
140
    locator->agent.offset = offset;
17✔
141
    locator->agent.length = current - offset;
17✔
142
    locator->agent.script = result;
17✔
143
}
17✔
144

145
SBBoolean SBScriptLocatorMoveNext(SBScriptLocatorRef locator)
26✔
146
{
147
    SBUInteger offset = locator->agent.offset + locator->agent.length;
26✔
148

149
    if (offset < locator->_codepointSequence.stringLength) {
26✔
150
        ResolveScriptRun(locator, offset);
17✔
151
        return SBTrue;
17✔
152
    }
153

154
    SBScriptLocatorReset(locator);
9✔
155
    return SBFalse;
9✔
156
}
157

158
void SBScriptLocatorReset(SBScriptLocatorRef locator)
27✔
159
{
160
    ScriptStackReset(&locator->_scriptStack);
27✔
161
    locator->agent.offset = 0;
27✔
162
    locator->agent.length = 0;
27✔
163
    locator->agent.script = SBScriptNil;
27✔
164
}
27✔
165

UNCOV
166
SBScriptLocatorRef SBScriptLocatorRetain(SBScriptLocatorRef locator)
×
167
{
168
    return ObjectRetain((ObjectRef)locator);
×
169
}
170

171
void SBScriptLocatorRelease(SBScriptLocatorRef locator)
9✔
172
{
173
    ObjectRelease((ObjectRef)locator);
9✔
174
}
9✔
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