\class cmProcessOutput * \brief Decode text data to internal encoding. * * cmProcessOutput is used to decode text output from external process * using external encoding to our internal encoding. */
| 17 | * using external encoding to our internal encoding. |
| 18 | */ |
| 19 | class cmProcessOutput |
| 20 | { |
| 21 | public: |
| 22 | enum Encoding |
| 23 | { |
| 24 | None, |
| 25 | Auto, |
| 26 | UTF8, |
| 27 | ANSI, |
| 28 | OEM |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * Find encoding enum value for given encoding \a name. |
| 33 | * \param name a encoding name. |
| 34 | * \return encoding enum value or Auto if \a name was not found. |
| 35 | */ |
| 36 | static cm::optional<Encoding> FindEncoding(std::string const& name); |
| 37 | |
| 38 | /// The code page that is used as internal encoding to which we will encode. |
| 39 | static unsigned int defaultCodepage; |
| 40 | |
| 41 | /** |
| 42 | * A class constructor. |
| 43 | * \param encoding external process encoding from which we will decode. |
| 44 | * \param maxSize a maximal size for process output buffer. It should match |
| 45 | * to KWSYSPE_PIPE_BUFFER_SIZE. If text we decode is same size as \a maxSize |
| 46 | * then we will check for incomplete character at end of buffer and |
| 47 | * we will not return last incomplete character. This character will be |
| 48 | * returned with next DecodeText() call. To disable this behavior specify |
| 49 | * 0 as \a maxSize. |
| 50 | */ |
| 51 | cmProcessOutput(Encoding encoding = Auto, unsigned int maxSize = 1024); |
| 52 | ~cmProcessOutput() = default; |
| 53 | /** |
| 54 | * Decode \a raw string using external encoding to internal |
| 55 | * encoding in \a decoded. |
| 56 | * \a id specifies which internal buffer to use. This is important when we |
| 57 | * are decoding both stdout and stderr from process output and we need to |
| 58 | * keep incomplete characters in separate buffers for each stream. |
| 59 | * \return true if successfully decoded \a raw to \a decoded or false if not. |
| 60 | */ |
| 61 | bool DecodeText(std::string raw, std::string& decoded, size_t id = 0); |
| 62 | /** |
| 63 | * Decode \a data with \a length from external encoding to internal |
| 64 | * encoding in \a decoded. |
| 65 | * \param data a pointer to process output text data. |
| 66 | * \param length a size of data buffer. |
| 67 | * \param decoded a string which will contain decoded text. |
| 68 | * \param id an internal buffer id to use. |
| 69 | * \return true if successfully decoded \a data to \a decoded or false if |
| 70 | * not. |
| 71 | */ |
| 72 | bool DecodeText(char const* data, size_t length, std::string& decoded, |
| 73 | size_t id = 0); |
| 74 | /** |
| 75 | * \overload |
| 76 | */ |
no outgoing calls
no test coverage detected
searching dependent graphs…