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

Tehreer / SheenBidi / 21298031641

23 Jan 2026 07:10PM UTC coverage: 95.567% (-0.8%) from 96.403%
21298031641

push

github

mta452
Make text editing and analysis API optional

2393 of 2504 relevant lines covered (95.57%)

743160.63 hits per line

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

97.44
/Source/API/SBCodepointSequence.c
1
/*
2
 * Copyright (C) 2016-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 <API/SBBase.h>
18
#include <API/SBCodepoint.h>
19
#include <Data/BidiTypeLookup.h>
20

21
#include "SBCodepointSequence.h"
22

23
SB_INTERNAL SBBoolean SBCodepointSequenceIsValid(const SBCodepointSequence *sequence)
861,951✔
24
{
25
    if (sequence) {
861,951✔
26
        SBBoolean encodingValid = SBFalse;
861,951✔
27

28
        switch (sequence->stringEncoding) {
861,951✔
29
        case SBStringEncodingUTF8:
861,951✔
30
        case SBStringEncodingUTF16:
31
        case SBStringEncodingUTF32:
32
            encodingValid = SBTrue;
861,951✔
33
            break;
861,951✔
34
        }
35

36
        return (encodingValid && sequence->stringBuffer && sequence->stringLength > 0);
861,951✔
37
    }
38

39
    return SBFalse;
×
40
}
41

42
SB_INTERNAL SBUInteger SBCodepointSequenceGetSeparatorLength(
33,482✔
43
    const SBCodepointSequence *sequence, SBUInteger separatorIndex)
44
{
45
    SBUInteger stringIndex = separatorIndex;
33,482✔
46
    SBCodepoint codepoint;
47
    SBUInteger separatorLength;
48

49
    codepoint = SBCodepointSequenceGetCodepointAt(sequence, &stringIndex);
33,482✔
50
    separatorLength = stringIndex - separatorIndex;
33,482✔
51

52
    if (codepoint == '\r') {
33,482✔
53
        /* Don't break in between 'CR' and 'LF'. */
54
        if (stringIndex < sequence->stringLength) {
17✔
55
            codepoint = SBCodepointSequenceGetCodepointAt(sequence, &stringIndex);
17✔
56

57
            if (codepoint == '\n') {
17✔
58
                separatorLength = stringIndex - separatorIndex;
17✔
59
            }
60
        }
61
    }
62

63
    return separatorLength;
33,482✔
64
}
65

66
SB_INTERNAL void SBCodepointSequenceDetermineBidiTypes(
861,951✔
67
    const SBCodepointSequence *sequence, SBBidiType *bidiTypes)
68
{
69
    SBUInteger stringIndex = 0;
861,951✔
70
    SBUInteger firstIndex = 0;
861,951✔
71
    SBCodepoint codepoint;
72

73
    while ((codepoint = SBCodepointSequenceGetCodepointAt(sequence, &stringIndex)) != SBCodepointInvalid) {
4,629,110✔
74
        bidiTypes[firstIndex] = LookupBidiType(codepoint);
3,767,159✔
75

76
        /* Subsequent code units get 'BN' type. */
77
        while (++firstIndex < stringIndex) {
3,767,159✔
78
            bidiTypes[firstIndex] = SBBidiTypeBN;
×
79
        }
80
    }
81
}
861,951✔
82

83
SB_INTERNAL void SBCodepointSequenceGetParagraphBoundary(
19✔
84
    const SBCodepointSequence *sequence, const SBBidiType *bidiTypes,
85
    SBUInteger paragraphOffset, SBUInteger suggestedLength,
86
    SBUInteger *actualLength, SBUInteger *separatorLength)
87
{
88
    SBUInteger limit = paragraphOffset + suggestedLength;
19✔
89
    SBUInteger index;
90

91
    if (separatorLength) {
19✔
92
        *separatorLength = 0;
18✔
93
    }
94

95
    for (index = paragraphOffset; index < limit; index++) {
79✔
96
        SBBidiType currentType = bidiTypes[index];
69✔
97

98
        if (currentType == SBBidiTypeB) {
69✔
99
            SBUInteger codeUnitCount = SBCodepointSequenceGetSeparatorLength(sequence, index);
9✔
100

101
            index += codeUnitCount;
9✔
102

103
            if (separatorLength) {
9✔
104
                *separatorLength = codeUnitCount;
8✔
105
            }
106
            break;
9✔
107
        }
108
    }
109

110
    if (actualLength) {
19✔
111
        *actualLength = index - paragraphOffset;
18✔
112
    }
113
}
19✔
114

115
SBCodepoint SBCodepointSequenceGetCodepointBefore(const SBCodepointSequence *codepointSequence, SBUInteger *stringIndex)
647✔
116
{
117
    SBCodepoint codepoint = SBCodepointInvalid;
647✔
118

119
    switch (codepointSequence->stringEncoding) {
647✔
120
    case SBStringEncodingUTF8:
537✔
121
        codepoint = SBCodepointDecodePreviousFromUTF8(codepointSequence->stringBuffer, codepointSequence->stringLength, stringIndex);
537✔
122
        break;
537✔
123

124
    case SBStringEncodingUTF16:
85✔
125
        codepoint = SBCodepointDecodePreviousFromUTF16(codepointSequence->stringBuffer, codepointSequence->stringLength, stringIndex);
85✔
126
        break;
85✔
127

128
    case SBStringEncodingUTF32:
25✔
129
        if ((*stringIndex - 1) < codepointSequence->stringLength) {
25✔
130
            const SBUInt32 *buffer = codepointSequence->stringBuffer;
14✔
131

132
            *stringIndex -= 1;
14✔
133
            codepoint = buffer[*stringIndex];
14✔
134

135
            if (!SBCodepointIsValid(codepoint)) {
14✔
136
                codepoint = SBCodepointFaulty;
5✔
137
            }
138
        }
139
        break;
25✔
140
    }
141

142
    return codepoint;
647✔
143
}
144

145
SBCodepoint SBCodepointSequenceGetCodepointAt(const SBCodepointSequence *codepointSequence, SBUInteger *stringIndex)
7,219,709✔
146
{
147
    SBCodepoint codepoint = SBCodepointInvalid;
7,219,709✔
148

149
    switch (codepointSequence->stringEncoding) {
7,219,709✔
150
    case SBStringEncodingUTF8:
563✔
151
        codepoint = SBCodepointDecodeNextFromUTF8(codepointSequence->stringBuffer, codepointSequence->stringLength, stringIndex);
563✔
152
        break;
563✔
153

154
    case SBStringEncodingUTF16:
114✔
155
        codepoint = SBCodepointDecodeNextFromUTF16(codepointSequence->stringBuffer, codepointSequence->stringLength, stringIndex);
114✔
156
        break;
114✔
157

158
    case SBStringEncodingUTF32:
7,219,032✔
159
        if (*stringIndex < codepointSequence->stringLength) {
7,219,032✔
160
            const SBUInt32 *buffer = codepointSequence->stringBuffer;
6,357,064✔
161

162
            codepoint = buffer[*stringIndex];
6,357,064✔
163
            *stringIndex += 1;
6,357,064✔
164

165
            if (!SBCodepointIsValid(codepoint)) {
6,357,064✔
166
                codepoint = SBCodepointFaulty;
5✔
167
            }
168
        }
169
        break;
7,219,032✔
170
    }
171

172
    return codepoint;
7,219,709✔
173
}
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