MCPcopy Create free account
hub / github.com/SpartanJ/eepp / strip_ansi_scalar

Function strip_ansi_scalar

src/eepp/core/string.cpp:2587–2624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2585}
2586
2587void strip_ansi_scalar( std::string& str ) {
2588 if ( str.empty() )
2589 return;
2590
2591 char* data = &str[0];
2592 const size_t len = str.size();
2593 size_t read_idx = 0;
2594 size_t write_idx = 0;
2595
2596 while ( read_idx < len ) {
2597 // Fast scan for ESC
2598 if ( unlikely( data[read_idx] == '\x1B' ) ) {
2599 // Check for CSI sequence: ESC + [
2600 if ( read_idx + 1 < len && data[read_idx + 1] == '[' ) {
2601 size_t scan = read_idx + 2;
2602 // Scan for the terminator byte (0x40 - 0x7E)
2603 while ( scan < len ) {
2604 unsigned char c = static_cast<unsigned char>( data[scan] );
2605 if ( c >= 0x40 && c <= 0x7E ) {
2606 scan++; // Include the terminator
2607 break;
2608 }
2609 scan++;
2610 }
2611 read_idx = scan;
2612 continue;
2613 }
2614 }
2615
2616 // Copy char if indices diverged
2617 if ( read_idx != write_idx ) {
2618 data[write_idx] = data[read_idx];
2619 }
2620 write_idx++;
2621 read_idx++;
2622 }
2623 str.resize( write_idx );
2624}
2625
2626#ifdef EE_ARCH_X86
2627

Callers

nothing calls this directly

Calls 3

emptyMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected