diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2018-05-17 13:05:59 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2018-05-17 13:06:11 -0400 |
commit | b17992c1c02a2d8a832a887c2de23a7f3ab869f8 (patch) | |
tree | 78c68408ee759275a452fbeb5495eb708ebde406 /gdb/common/format.h | |
parent | 58f0c71853f98afe623ab89c4362682885905ebb (diff) | |
download | binutils-b17992c1c02a2d8a832a887c2de23a7f3ab869f8.zip binutils-b17992c1c02a2d8a832a887c2de23a7f3ab869f8.tar.gz binutils-b17992c1c02a2d8a832a887c2de23a7f3ab869f8.tar.bz2 |
Make format_pieces recognize the \e escape sequence
I noticed that the printf command did not recognize the \e escape
sequence, used amongst other things to use colors:
(gdb) printf "This is \e[32mgreen\e[m!\n"
Unrecognized escape character \e in format string.
This patch makes format_pieces recognize it, which makes that command
print the expected result in glorious color.
I wrote a really simple unit test for format_pieces.
format_pieces::operator[] is unused so I removed it. I added
format_piece::operator==, which is needed to compare vectors of
format_piece.
gdb/ChangeLog:
PR cli/14975
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
unittests/format_pieces-selftests.c.
* common/format.h (format_piece) <operator==>: New.
(format_pieces) <operator[]>: Remove.
* common/format.c (format_pieces::format_pieces): Handle \e.
* unittests/format_pieces-selftests.c: New.
Diffstat (limited to 'gdb/common/format.h')
-rw-r--r-- | gdb/common/format.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/gdb/common/format.h b/gdb/common/format.h index 1745517..7b053f1 100644 --- a/gdb/common/format.h +++ b/gdb/common/format.h @@ -20,6 +20,8 @@ #ifndef COMMON_FORMAT_H #define COMMON_FORMAT_H +#include "common/gdb_string_view.h" + #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG) # define USE_PRINTF_I64 1 # define PRINTF_HAS_LONG_LONG @@ -54,6 +56,12 @@ struct format_piece { } + bool operator== (const format_piece &other) const + { + return (this->argclass == other.argclass + && gdb::string_view (this->string) == other.string); + } + const char *string; enum argclass argclass; }; @@ -67,11 +75,6 @@ public: DISABLE_COPY_AND_ASSIGN (format_pieces); - format_piece &operator[] (size_t index) - { - return m_pieces[index]; - } - typedef std::vector<format_piece>::iterator iterator; iterator begin () |