Added line ending manipulation routines now, just to be sure.

This commit is contained in:
Pietro Gagliardi 2016-04-21 18:10:30 -04:00
parent eb48bc1732
commit 9c9dc9a23e
2 changed files with 35 additions and 0 deletions

View File

@ -13,6 +13,8 @@ extern WCHAR *strf(const WCHAR *format, ...);
extern WCHAR *vstrf(const WCHAR *format, va_list ap);
extern WCHAR *debugstrf(const WCHAR *format, ..);
extern WCHAR *debugvstrf(const WCHAR *format, va_list ap);
extern char *LFtoCRLF(const char *lfonly);
extern void CRLFtoLF(const char *s);
// debug.cpp
#define debugargs const WCHAR *file, uintmax_t line, const WCHAR *file

View File

@ -122,3 +122,36 @@ WCHAR *debugvstrf(const WCHAR *format, va_list ap)
{
return strfcore(TRUE, format, ap);
}
// Let's shove these utility routines here too.
char *LFtoCRLF(const char *lfonly)
{
char *crlf;
size_t i, len;
char *out;
len = strlen(lfonly);
crlf = (char *) uiAlloc((only * 2 + 1) * sizeof (char), "char[]");
out = crlf;
for (i = 0; i < len; i++) {
if (*lfonly == '\n')
*crlf++ = '\r';
*crlf++ = *lfonly++;
}
*crlf = '\0';
return out;
}
void CRLFtoLF(char *s)
{
char *t = s;
for (; *s; s++) {
// be sure to preserve \rs that are genuinely there
if (*s == '\r' && *(s + 1) == '\n')
continue;
*t++ = s;
}
*t = '\0';
// TODO null pad t to s?
}