MCPcopy Create free account
hub / github.com/Koihik/LuaFormatter / get_line_separator

Function get_line_separator

src/lua-format.cpp:128–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128std::string get_line_separator(const std::string& input) {
129 constexpr char CR = '\r';
130 constexpr char LF = '\n';
131 size_t lf_count = 0;
132 size_t cr_count = 0;
133 size_t crlf_count = 0;
134 const auto length = input.length();
135 for (size_t i = 0; i < length; i++) {
136 const auto cur = input[i];
137 if (cur == LF) {
138 lf_count++;
139 } else if (cur == CR) {
140 const auto next = input[i + 1];
141 if (next == LF) {
142 crlf_count++;
143 i++;
144 } else {
145 cr_count++;
146 }
147 }
148 }
149
150 std::string result;
151 if (lf_count >= crlf_count && lf_count >= cr_count) {
152 result += LF;
153 } else if (crlf_count >= lf_count && crlf_count >= cr_count) {
154 result += CR;
155 result += LF;
156 } else {
157 result += CR;
158 }
159 return result;
160}
161
162std::string convert_line_separator(const std::string& input, const std::string& line_sep) {
163 constexpr char CR = '\r';

Callers 2

handleLineSeparatorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected