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

thoni56 / c-xrefactory / 1779

16 Apr 2026 02:51PM UTC coverage: 85.037% (+1.7%) from 83.31%
1779

push

travis-ci

thoni56
[snapshot][version] Ignore snapshots with mismatching version, they will be recreated

16282 of 19147 relevant lines covered (85.04%)

15994227.93 hits per line

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

74.29
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) {
2,147,483,647✔
37
    if (**(srcP)&0x80) {
2,147,483,647✔
38
        unsigned z = **srcP;
16,109✔
39
        if (z >= 0xC2 && z <= 0xDF) {
16,109✔
40
            *srcP += 1;  // 2-byte sequence (U+0080 - U+07FF)
9,530✔
41
        } else if (z >= 0xE0 && z <= 0xEF) {
6,579✔
42
            *srcP += 2;  // 3-byte sequence (U+0800 - U+FFFF)
6,491✔
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
16,109✔
51
        return true;
16,109✔
52
    }
53
    return false;
54
}
55

56

57
static void applyUtf8CrLfCrConversion(EditorBuffer *buffer) {
825✔
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;
825✔
63
        });
825✔
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

461,221✔
84
static void applyUtf8Conversion(EditorBuffer *buffer) {
2,147,483,647✔
85
    EDITOR_ENCODING_WALK_THROUGH_BUFFER(buffer, {
86
            if (convertUtf8(&s, &d)) ;
87
            else
88
                *d = *s;
461,221✔
89
                });
461,221✔
90
}
91

92

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