Ninja
Classes | Functions
elide_middle.cc File Reference
#include "elide_middle.h"
#include <assert.h>
#include <string.h>
Include dependency graph for elide_middle.cc:

Go to the source code of this file.

Classes

struct  AnsiColorSequenceIterator
 
struct  VisibleInputCharsIterator
 

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().