wxMaxima
StreamUtils.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2020 Kuba Ober <kuba@mareimbrium.org>
4 //
5 // Everyone is permitted to copy and distribute verbatim copies
6 // of this licence document, but changing it is not allowed.
7 //
8 // WXWINDOWS LIBRARY LICENCE
9 // TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
10 //
11 // This library is free software; you can redistribute it and/or modify it
12 // under the terms of the GNU Library General Public Licence as published by
13 // the Free Software Foundation; either version 2 of the Licence, or (at your
14 // option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful, but WITHOUT
17 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
19 // Licence for more details.
20 //
21 // You should have received a copy of the GNU Library General Public Licence
22 // along with this software, usually in a file named COPYING.LIB. If not,
23 // write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
24 // Floor, Boston, MA 02110-1301 USA.
25 //
26 // EXCEPTION NOTICE
27 //
28 // 1. As a special exception, the copyright holders of this library give
29 // permission for additional uses of the text contained in this release of the
30 // library as licenced under the wxWindows Library Licence, applying either
31 // version 3.1 of the Licence, or (at your option) any later version of the
32 // Licence as published by the copyright holders of version 3.1 of the Licence
33 // document.
34 //
35 // 2. The exception is that you may use, copy, link, modify and distribute
36 // under your own terms, binary object code versions of works based on the
37 // Library.
38 //
39 // 3. If you copy code from files distributed under the terms of the GNU
40 // General Public Licence or the GNU Library General Public Licence into a
41 // copy of this library, as this licence permits, the exception does not apply
42 // to the code that you add in this way. To avoid misleading anyone as to the
43 // status of such modified files, you must delete this exception notice from
44 // such code and/or adjust the licensing conditions notice accordingly.
45 //
46 // 4. If you write modifications of your own for this library, it is your
47 // choice whether to permit this exception to apply to your modifications. If
48 // you do not wish that, you must delete the exception notice from such code
49 // and/or adjust the licensing conditions notice accordingly.
50 //
51 // SPDX-License-Identifier: wxWindows
52 
53 #ifndef WXMAXIMA_STREAMUTILS_H
54 #define WXMAXIMA_STREAMUTILS_H
55 
61 #include <wx/stream.h>
62 #include <wx/string.h>
63 #include <vector>
64 
69 {
70 public:
71  struct DecodeResult
72  {
73  size_t bytesRead = {};
74  size_t outputSize = {};
75  const wxStringCharType *output = {};
76  const wxStringCharType *outputEnd = {};
77  bool ok = false;
78  };
79 
80  class State
81  {
82  std::vector<char> m_inBuf;
83  size_t m_inBufCount = {};
84  std::vector<wxStringCharType> m_outBuf;
85  public:
86  DecodeResult Decode(wxInputStream &in, size_t maxRead, size_t maxWrite);
87  };
88 
89  static DecodeResult Decode(State &state, wxInputStream &in, size_t maxRead,
90  size_t maxWrite)
91  {
92  return state.Decode(in, maxRead, maxWrite);
93  }
94 };
95 
96 #endif
UTF8Decoder::DecodeResult
Definition: StreamUtils.h:71
UTF8Decoder
Definition: StreamUtils.h:68
UTF8Decoder::State
Definition: StreamUtils.h:80