MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / dedent

Method dedent

core/string/ustring.cpp:4288–4329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4286}
4287
4288String 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
4331String String::strip_edges(bool left, bool right) const {
4332 int len = length();

Callers 7

fix_doc_descriptionFunction · 0.80
DTRFunction · 0.80
DTRNFunction · 0.80
fix_doc_descriptionFunction · 0.80
_translate_doc_stringFunction · 0.80
_add_text_to_rtFunction · 0.80
test_string.hFile · 0.80

Calls 1

lengthMethod · 0.45

Tested by

no test coverage detected