Ninja
Functions
elide_middle.h File Reference
#include <cstddef>
#include <string>
Include dependency graph for elide_middle.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ElideMiddleInPlace (std::string &str, size_t max_width)
 Elide the given string str with '...' in the middle if the length exceeds max_width. More...
 

Function Documentation

◆ ElideMiddleInPlace()

void ElideMiddleInPlace ( std::string &  str,
size_t  max_width 
)

Elide the given string str with '...' in the middle if the length exceeds max_width.

Note that this handles ANSI color sequences properly (non-color related sequences are ignored, but using them would wreak the cursor position or terminal state anyway).

Definition at line 185 of file elide_middle.cc.

References VisibleInputCharsIterator::HasChar(), AnsiColorSequenceIterator::HasSequence(), VisibleInputCharsIterator::InputIndex(), VisibleInputCharsIterator::IsVisible(), VisibleInputCharsIterator::NextChar(), and VisibleInputCharsIterator::VisiblePosition().

Referenced by main(), and LinePrinter::Print().