Skip to content

Commit 40d3c9f

Browse files
author
jvon1904
committed
add multiline support
1 parent 31a06a9 commit 40d3c9f

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

main.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,28 @@ void getLines(Document *doc) {
4747
Line line;
4848
initLine(&line);
4949

50-
int go = 1;
50+
int nl = 0; // Newline flag
5151

5252
for (int i = 0; i < doc->body->len; i++) {
5353
char c = doc->body->text[i];
5454
char next = doc->body->text[i + 1];
55-
char nextnext;
56-
if (i + 2 < doc->body->len) {
57-
nextnext = doc->body->text[i + 2];
58-
} else {
59-
nextnext = '\0';
60-
}
6155

62-
if (c == '\\' && next == CR && nextnext == SP) {
63-
go = 0;
64-
} else if (c == CR && next == SP) {
65-
go = 0;
56+
if (c == CR && next == SP) {
57+
nl = 1;
58+
}
59+
60+
if (nl && (c != SP && c != CR)) {
61+
nl = 0;
6662
}
6763

68-
69-
if (go) {
64+
if (!nl) {
7065
if (c == CR) {
7166
appendDocumentLine(doc, cloneLine(&line));
7267
freeLine(&line);
7368
initLine(&line);
7469
} else {
7570
appendLine(&line, c);
7671
}
77-
} else {
78-
if (c != '\\' && c != CR && c != SP) {
79-
appendLine(&line, c);
80-
go = 1;
81-
}
8272
}
8373
}
8474

t/example.2.ldif

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ givenName: John
1212
uid: jdoe
1313
mail: jdoe@example.com
1414
telephoneNumber: +1 555 123 4567
15-
description: This is a long description that \
15+
description: This is a long description that
1616
wraps onto another line for clarity.
1717
title: Senior Engineer
1818
employeeNumber: 123456

t/example.3.json.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"sn": "Jensen",
1515
"uid": "bjensen",
1616
"telephonenumber": "+1 408 555 1212",
17-
"description": "Babs is a big sailing fan, and travels extensively in sea rch of perfect sailing conditions.",
17+
"description": "Babs is a big sailing fan, and travels extensively in search of perfect sailing conditions.",
18+
"field1": "foo bar baz",
1819
"title": "Product Manager, Rod and Reel Division"
1920
}
2021
]

t/example.3.ldif

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ uid:bjensen
1010
telephonenumber:+1 408 555 1212
1111
description:Babs is a big sailing fan, and travels extensively in sea
1212
rch of perfect sailing conditions.
13+
field1:foo
14+
bar baz
1315
title:Product Manager, Rod and Reel Division

0 commit comments

Comments
 (0)