MCPcopy Create free account
hub / github.com/NetHack/NetHack / strbuf_nl_to_crlf

Function strbuf_nl_to_crlf

src/strutil.c:57–77  ·  view source on GitHub ↗

strbuf_nl_to_crlf() converts all occurrences of \n to \r\n */

Source from the content-addressed store, hash-verified

55
56/* strbuf_nl_to_crlf() converts all occurrences of \n to \r\n */
57void
58strbuf_nl_to_crlf(strbuf_t *strbuf)
59{
60 if (strbuf->str) {
61 int len = (int) strlen(strbuf->str);
62 int count = 0;
63 char *cp = strbuf->str;
64
65 while (*cp)
66 if (*cp++ == '\n')
67 count++;
68 if (count) {
69 strbuf_reserve(strbuf, len + count + 1);
70 for (cp = strbuf->str + len + count; count; --cp)
71 if ((*cp = cp[-count]) == '\n') {
72 *--cp = '\r';
73 --count;
74 }
75 }
76 }
77}
78
79/* strlen() but returns unsigned and panics if string is unreasonably long;
80 used by dlb as well as by nethack */

Callers 1

Calls 1

strbuf_reserveFunction · 0.85

Tested by

no test coverage detected