/* Parse a printf-style format string.
- Copyright (C) 1986-2017 Free Software Foundation, Inc.
+ Copyright (C) 1986-2018 Free Software Foundation, Inc.
This file is part of GDB.
#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
struct format_piece
{
- char *string;
+ format_piece (const char *str, enum argclass argc)
+ : string (str),
+ argclass (argc)
+ {
+ }
+
+ 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;
};
-/* Return an array of printf fragments found at the given string, and
- rewrite ARG with a pointer to the end of the format string. */
+class format_pieces
+{
+public:
-extern struct format_piece *parse_format_string (const char **arg);
+ format_pieces (const char **arg);
+ ~format_pieces () = default;
-/* Given a pointer to an array of format pieces, free any memory that
- would have been allocated by parse_format_string. */
+ DISABLE_COPY_AND_ASSIGN (format_pieces);
-extern void free_format_pieces (struct format_piece *frags);
+ typedef std::vector<format_piece>::iterator iterator;
-/* Freeing, cast as a cleanup. */
+ iterator begin ()
+ {
+ return m_pieces.begin ();
+ }
+
+ iterator end ()
+ {
+ return m_pieces.end ();
+ }
-extern void free_format_pieces_cleanup (void *);
+private:
+
+ std::vector<format_piece> m_pieces;
+ gdb::unique_xmalloc_ptr<char> m_storage;
+};
#endif /* COMMON_FORMAT_H */