| 126 | } |
| 127 | |
| 128 | std::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 | |
| 162 | std::string convert_line_separator(const std::string& input, const std::string& line_sep) { |
| 163 | constexpr char CR = '\r'; |
no outgoing calls
no test coverage detected