MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / dedent

Method dedent

modules/gui/gui/src/backend/text_server/ustring.cpp:4276–4328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

DTRFunction · 0.80
DTRNFunction · 0.80

Calls 3

substrFunction · 0.85
lengthFunction · 0.50
lengthMethod · 0.45

Tested by

no test coverage detected