| 4286 | } |
| 4287 | |
| 4288 | String String::dedent() const { |
| 4289 | String new_string; |
| 4290 | String indent; |
| 4291 | bool has_indent = false; |
| 4292 | bool has_text = false; |
| 4293 | int line_start = 0; |
| 4294 | int indent_stop = -1; |
| 4295 | |
| 4296 | for (int i = 0; i < length(); i++) { |
| 4297 | char32_t c = operator[](i); |
| 4298 | if (c == '\n') { |
| 4299 | if (has_text) { |
| 4300 | new_string += substr(indent_stop, i - indent_stop); |
| 4301 | } |
| 4302 | new_string += "\n"; |
| 4303 | has_text = false; |
| 4304 | line_start = i + 1; |
| 4305 | indent_stop = -1; |
| 4306 | } else if (!has_text) { |
| 4307 | if (c > 32) { |
| 4308 | has_text = true; |
| 4309 | if (!has_indent) { |
| 4310 | has_indent = true; |
| 4311 | indent = substr(line_start, i - line_start); |
| 4312 | indent_stop = i; |
| 4313 | } |
| 4314 | } |
| 4315 | if (has_indent && indent_stop < 0) { |
| 4316 | int j = i - line_start; |
| 4317 | if (j >= indent.length() || c != indent[j]) { |
| 4318 | indent_stop = i; |
| 4319 | } |
| 4320 | } |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | if (has_text) { |
| 4325 | new_string += substr(indent_stop, length() - indent_stop); |
| 4326 | } |
| 4327 | |
| 4328 | return new_string; |
| 4329 | } |
| 4330 | |
| 4331 | String String::strip_edges(bool left, bool right) const { |
| 4332 | int len = length(); |
no test coverage detected