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

thoni56 / c-xrefactory / 1617

19 Nov 2025 11:56PM UTC coverage: 81.092% (+54.7%) from 26.404%
1617

push

travis-ci

thoni56
[tests] Trying to get C11 test more platform independent

The output is the references but they vary depending on the standard include design.

12836 of 15829 relevant lines covered (81.09%)

1769773.98 hits per line

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

78.13
src/encoding.c
1
#include "encoding.h"
2

3
#include "options.h"
4

5

6
#define EDITOR_ENCODING_WALK_THROUGH_BUFFER(buffer, command) {          \
7
        unsigned char *s, *d, *max;                                     \
8
        unsigned char *text = (unsigned char *)getTextInEditorBuffer(buffer); \
9
        max = text + getSizeOfEditorBuffer(buffer);                     \
10
        for (s=d=text; s<max; s++) {                                    \
11
            command;                                                    \
12
            d++;                                                        \
13
        }                                                               \
14
        setSizeOfEditorBuffer(buffer, d - text);                        \
15
    }
16

17
#define EDITOR_ENCODING_CR_LF_OR_CR_TO_LF_CONVERSION(s,d)   \
18
    if (*s == '\r') {                                       \
19
        if (s+1<max && *(s+1)=='\n') {                      \
20
            s++;                                            \
21
            *d = *s;                                        \
22
        } else {                                            \
23
            *d = '\n';                                      \
24
        }                                                   \
25
    }
26
#define EDITOR_ENCODING_CR_LF_TO_LF_CONVERSION(s,d) \
27
    if (*s == '\r' && s+1<max && *(s+1)=='\n') {    \
28
        s++;                                        \
29
        *d = *s;                                    \
30
    }
31
#define EDITOR_ENCODING_CR_TO_LF_CONVERSION(s,d)      \
32
    if (*s == '\r') {                                 \
33
        *d = '\n';                                    \
34
    }
35

36
static bool convertUtf8(unsigned char **srcP, unsigned char **dstP) {
421,843,747✔
37
    if (**(srcP)&0x80) {
421,843,747✔
38
        unsigned z = **srcP;
1,767✔
39
        if (z >= 0xC2 && z <= 0xDF) {
1,767✔
40
            *srcP += 1;  // 2-byte sequence (U+0080 - U+07FF)
1,084✔
41
        } else if (z >= 0xE0 && z <= 0xEF) {
683✔
42
            *srcP += 2;  // 3-byte sequence (U+0800 - U+FFFF)
595✔
43
        } else if (z >= 0xF0 && z <= 0xF4) {
88✔
44
            *srcP += 3;  // 4-byte sequence (U+10000 - U+10FFFF)
88✔
45
        } else {
46
            // Illegal UTF-8, just skip one byte for minimal damage
47
            *srcP += 1;
×
48
        }
49

50
        **dstP = ' '; // Replace the sequence with a single space
1,767✔
51
        return true;
1,767✔
52
    }
53
    return false;
421,841,980✔
54
}
55

56

57
static void applyUtf8CrLfCrConversion(EditorBuffer *buffer) {
435✔
58
    EDITOR_ENCODING_WALK_THROUGH_BUFFER(buffer, {
59
            if (convertUtf8(&s, &d)) ;
60
            else EDITOR_ENCODING_CR_LF_OR_CR_TO_LF_CONVERSION(s,d)
61
                else
62
                    *d = *s;
63
        });
435✔
64
}
65

×
66
static void applyUtf8CrLfConversion(EditorBuffer *buffer) {
×
67
    EDITOR_ENCODING_WALK_THROUGH_BUFFER(buffer, {
68
            if (convertUtf8(&s, &d)) ;
69
            else EDITOR_ENCODING_CR_LF_TO_LF_CONVERSION(s,d)
70
                else
71
                    *d = *s;
72
        });
73
}
74

×
75
static void applyUtf8CrConversion(EditorBuffer *buffer) {
×
76
    EDITOR_ENCODING_WALK_THROUGH_BUFFER(buffer, {
77
            if (convertUtf8(&s, &d)) ;
78
            else EDITOR_ENCODING_CR_TO_LF_CONVERSION(s,d)
79
                else
80
                    *d = *s;
81
        });
82
}
83

20,038✔
84
static void applyUtf8Conversion(EditorBuffer *buffer) {
419,358,523✔
85
    EDITOR_ENCODING_WALK_THROUGH_BUFFER(buffer, {
86
            if (convertUtf8(&s, &d)) ;
87
            else
88
                *d = *s;
89
                });
20,038✔
90
}
91

92

20,473✔
93
void performEncodingAdjustments(EditorBuffer *buffer) {
94
    // utf-8
20,473✔
95
    if ((options.eolConversion&CR_LF_EOL_CONVERSION)
435✔
96
        && (options.eolConversion & CR_EOL_CONVERSION)) {
435✔
97
        applyUtf8CrLfCrConversion(buffer);
20,038✔
98
    } else if (options.eolConversion & CR_LF_EOL_CONVERSION) {
×
99
        applyUtf8CrLfConversion(buffer);
20,038✔
100
    } else if (options.eolConversion & CR_EOL_CONVERSION) {
×
101
        applyUtf8CrConversion(buffer);
102
    } else {
20,038✔
103
        applyUtf8Conversion(buffer);
104
    }
20,473✔
105
}
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