Coverage Report

Created: 2026-11-10 14:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
src/stringy.c
Line
Count
Source
1
#include "prism/internal/stringy.h"
2
3
#include "prism/internal/assert.h"
4
5
#include <string.h>
6
7
/**
8
 * Initialize a shared string that is based on initial input.
9
 */
10
void
11
2.57k
pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end) {
12
2.57k
    PRISM_ASSERT(start <= end);
  Branch (12:5): [True: 0, False: 2.57k]
  Branch (12:5): [True: 2.57k, False: 0]
13
14
2.57k
    *string = (pm_string_t) {
15
2.57k
        .source = start,
16
2.57k
        .length = (size_t) (end - start)
17
2.57k
    };
18
2.57k
}
19
20
/**
21
 * Initialize a string that views the given bytes.
22
 */
23
void
24
458
pm_string_init(pm_string_t *string, const uint8_t *source, size_t length) {
25
458
    *string = (pm_string_t) { .source = source, .length = length };
26
458
}
27
28
/**
29
 * Compare the underlying lengths and bytes of two strings. Returns 0 if the
30
 * strings are equal, a negative number if the left string is less than the
31
 * right string, and a positive number if the left string is greater than the
32
 * right string.
33
 */
34
int
35
64
pm_string_compare(const pm_string_t *left, const pm_string_t *right) {
36
64
    size_t left_length = pm_string_length(left);
37
64
    size_t right_length = pm_string_length(right);
38
39
64
    if (left_length < right_length) {
  Branch (39:9): [True: 11, False: 53]
40
11
        return -1;
41
53
    } else if (left_length > right_length) {
  Branch (41:16): [True: 0, False: 53]
42
0
        return 1;
43
0
    }
44
45
53
    return memcmp(pm_string_source(left), pm_string_source(right), left_length);
46
64
}
47
48
/**
49
 * Returns the length associated with the string.
50
 */
51
size_t
52
11.4k
pm_string_length(const pm_string_t *string) {
53
11.4k
    return string->length;
54
11.4k
}
55
56
/**
57
 * Returns the start pointer associated with the string.
58
 */
59
const uint8_t *
60
9.99k
pm_string_source(const pm_string_t *string) {
61
9.99k
    return string->source;
62
9.99k
}