Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
LineEndings.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Characters_LineEndings_h_
5#define _Stroika_Foundation_Characters_LineEndings_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <string>
10
12#include "Stroika/Foundation/Common/Common.h"
13
15
16 /**
17 * \brief null-terminated String constant for current compiled platform - Windows (CRLF) or POSIX (NL) - macos I dont think any longer uses \r??
18 */
19 template <IPossibleCharacterRepresentation T>
20 static constexpr T kEOL[] = {
21#if qStroika_Foundation_Common_Platform_Windows
22 '\r', '\n', '\0' // "\r\n"
23#elif qStroika_Foundation_Common_Platform_POSIX
24 '\n', '\0' // "\n"
25#endif
26 };
27
28 /**
29 */
30 template <typename CHAR>
31 void AssureHasLineTermination (basic_string<CHAR>* text);
32
33 /**
34 * \brief Convert the argument srcText buffer from CRLF format line endings, to NL format line endings.
35 *
36 * return #bytes in output buffer (NO nullptr TERM) - assert buffer big enough - output buf as big is input buf
37 * always big enough. OK for srcText and outBuf to be SAME PTR.
38 */
39 template <typename TCHAR>
40 size_t CRLFToNL (const TCHAR* srcText, size_t srcTextBytes, TCHAR* outBuf, size_t outBufSize);
41 template <typename TCHAR>
42 void CRLFToNL (basic_string<TCHAR>* text); // modified in-place
43 template <typename TCHAR>
44 basic_string<TCHAR> CRLFToNL (const basic_string<TCHAR>& text);
45
46 /**
47 * \brief Convert the argument srcText buffer from NL format line endings, to CRLF format line endings.
48 * Note - even if input is already CRLF, this then is a no-op, changing nothing.
49 */
50 template <typename TCHAR>
51 size_t NLToCRLF (const TCHAR* srcText, size_t srcTextBytes, TCHAR* outBuf, size_t outBufSize);
52 template <typename TCHAR>
53 basic_string<TCHAR> NLToCRLF (const basic_string<TCHAR>& text);
54
55 /**
56 */
57 template <typename TCHAR>
58 size_t NativeToNL (const TCHAR* srcText, size_t srcTextBytes, TCHAR* outBuf, size_t outBufSize);
59 template <typename TCHAR>
60 basic_string<TCHAR> NativeToNL (const basic_string<TCHAR>& text);
61
62 /**
63 */
64 template <typename TCHAR>
65 size_t NLToNative (const TCHAR* srcText, size_t srcTextBytes, TCHAR* outBuf, size_t outBufSize);
66 template <typename TCHAR>
67 basic_string<TCHAR> NLToNative (const basic_string<TCHAR>& text);
68
69 /**
70 * return #bytes in output buffer (NO nullptr TERM) - assert buffer big enough - output buf as big is input buf
71 * always big enough. OK for srcText and outBuf to be SAME PTR.
72 *
73 * \note @see String::NormalizeTextToNL
74 */
75 template <typename TCHAR>
76 size_t NormalizeTextToNL (const TCHAR* srcText, size_t srcTextBytes, TCHAR* outBuf, size_t outBufSize);
77 template <typename TCHAR>
78 void NormalizeTextToNL (basic_string<TCHAR>* text); // modified in-place
79 template <typename TCHAR>
80 basic_string<TCHAR> NormalizeTextToNL (const basic_string<TCHAR>& text);
81
82}
83
84/*
85 ********************************************************************************
86 ***************************** Implementation Details ***************************
87 ********************************************************************************
88 */
89#include "LineEndings.inl"
90
91#endif /*_Stroika_Foundation_Characters_LineEndings_h_*/
size_t NormalizeTextToNL(const TCHAR *srcText, size_t srcTextBytes, TCHAR *outBuf, size_t outBufSize)
size_t NLToCRLF(const TCHAR *srcText, size_t srcTextBytes, TCHAR *outBuf, size_t outBufSize)
Convert the argument srcText buffer from NL format line endings, to CRLF format line endings....
size_t CRLFToNL(const TCHAR *srcText, size_t srcTextBytes, TCHAR *outBuf, size_t outBufSize)
Convert the argument srcText buffer from CRLF format line endings, to NL format line endings.
static constexpr T kEOL[]
null-terminated String constant for current compiled platform - Windows (CRLF) or POSIX (NL) - macos ...
Definition LineEndings.h:20