aboutsummaryrefslogtreecommitdiff
path: root/gdb/charset.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-09-22 21:16:53 -0600
committerTom Tromey <tom@tromey.com>2016-10-12 19:43:16 -0600
commitcda6c55bd399a8892d62178d4daeb074def909e0 (patch)
treed83fa6dba674729cc8cf978824995f03bbf8ca5e /gdb/charset.h
parent816d7b53047bca81c226990bc9248d59d80d4b8b (diff)
downloadgdb-cda6c55bd399a8892d62178d4daeb074def909e0.zip
gdb-cda6c55bd399a8892d62178d4daeb074def909e0.tar.gz
gdb-cda6c55bd399a8892d62178d4daeb074def909e0.tar.bz2
Turn wchar iterator into a class
This changes wchar_iterator from charset.c into a real C++ class, then updates the users to use the class. This lets us remove some cleanups in favor of the class' destructor. 2016-10-12 Tom Tromey <tom@tromey.com> * valprint.c (generic_emit_char, count_next_character) (generic_printstr): Update. * charset.c (struct wchar_iterator): Move to charset.h. (wchar_iterator::wchar_iterator): Rename from make_wchar_iterator, turn into a constructor. (wchar_iterator::~wchar_iterator): Rename from do_cleanup_iterator, turn into a destructor. (make_cleanup_wchar_iterator): Remove. (wchar_iterator::iterate): Rename from wchar_iterate. Remove "iter" argument. Update. * charset.h: Include <vector>. (class wchar_iterator): New class, from old struct wchar_iterator. (make_wchar_iterator, make_cleanup_wchar_iterator): Don't declare.
Diffstat (limited to 'gdb/charset.h')
-rw-r--r--gdb/charset.h95
1 files changed, 55 insertions, 40 deletions
diff --git a/gdb/charset.h b/gdb/charset.h
index 559b328..64aa58d 100644
--- a/gdb/charset.h
+++ b/gdb/charset.h
@@ -19,6 +19,8 @@
#ifndef CHARSET_H
#define CHARSET_H
+#include <vector>
+
/* If the target program uses a different character set than the host,
GDB has some support for translating between the two; GDB converts
characters and strings to the host character set before displaying
@@ -81,54 +83,67 @@ enum wchar_iterate_result
wchar_iterate_eof
};
-/* Declaration of the opaque wchar iterator type. */
-struct wchar_iterator;
+/* An iterator that returns host wchar_t's from a target string. */
+class wchar_iterator
+{
+ public:
-/* Create a new character iterator which returns wchar_t's. INPUT is
- the input buffer. BYTES is the number of bytes in the input
- buffer. CHARSET is the name of the character set in which INPUT is
- encoded. WIDTH is the number of bytes in a base character of
- CHARSET.
+ /* Create a new character iterator which returns wchar_t's. INPUT is
+ the input buffer. BYTES is the number of bytes in the input
+ buffer. CHARSET is the name of the character set in which INPUT is
+ encoded. WIDTH is the number of bytes in a base character of
+ CHARSET.
- This function either returns a new character set iterator, or calls
- error. The result can be freed using a cleanup; see
- make_cleanup_wchar_iterator. */
-struct wchar_iterator *make_wchar_iterator (const gdb_byte *input,
- size_t bytes,
- const char *charset,
- size_t width);
-
-/* Return a new cleanup suitable for destroying the wchar iterator
- ITER. */
-struct cleanup *make_cleanup_wchar_iterator (struct wchar_iterator *iter);
-
-/* Perform a single iteration of a wchar_t iterator.
+ This function either returns a new character set iterator, or calls
+ error. The result can be freed using a cleanup; see
+ make_cleanup_wchar_iterator. */
+ wchar_iterator (const gdb_byte *input, size_t bytes, const char *charset,
+ size_t width);
+
+ ~wchar_iterator ();
+
+ /* Perform a single iteration of a wchar_t iterator.
- Returns the number of characters converted. A negative result
- means that EOF has been reached. A positive result indicates the
- number of valid wchar_ts in the result; *OUT_CHARS is updated to
- point to the first valid character.
+ Returns the number of characters converted. A negative result
+ means that EOF has been reached. A positive result indicates the
+ number of valid wchar_ts in the result; *OUT_CHARS is updated to
+ point to the first valid character.
- In all cases aside from EOF, *PTR is set to point to the first
- converted target byte. *LEN is set to the number of bytes
- converted.
+ In all cases aside from EOF, *PTR is set to point to the first
+ converted target byte. *LEN is set to the number of bytes
+ converted.
- A zero result means one of several unusual results. *OUT_RESULT is
- set to indicate the type of un-ordinary return.
+ A zero result means one of several unusual results. *OUT_RESULT is
+ set to indicate the type of un-ordinary return.
- wchar_iterate_invalid means that an invalid input character was
- seen. The iterator is advanced by WIDTH (the argument to
- make_wchar_iterator) bytes.
+ wchar_iterate_invalid means that an invalid input character was
+ seen. The iterator is advanced by WIDTH (the argument to
+ the wchar_iterator constructor) bytes.
- wchar_iterate_incomplete means that an incomplete character was
- seen at the end of the input sequence.
+ wchar_iterate_incomplete means that an incomplete character was
+ seen at the end of the input sequence.
- wchar_iterate_eof means that all bytes were successfully
- converted. The other output arguments are not set. */
-int wchar_iterate (struct wchar_iterator *iter,
- enum wchar_iterate_result *out_result,
- gdb_wchar_t **out_chars,
- const gdb_byte **ptr, size_t *len);
+ wchar_iterate_eof means that all bytes were successfully
+ converted. The other output arguments are not set. */
+ int iterate (enum wchar_iterate_result *out_result, gdb_wchar_t **out_chars,
+ const gdb_byte **ptr, size_t *len);
+
+ private:
+
+ /* The underlying iconv descriptor. */
+ iconv_t m_desc;
+
+ /* The input string. This is updated as we convert characters. */
+ const gdb_byte *m_input;
+ /* The number of bytes remaining in the input. */
+ size_t m_bytes;
+
+ /* The width of an input character. */
+ size_t m_width;
+
+ /* The output buffer. */
+ std::vector<gdb_wchar_t> m_out;
+};