diff options
Diffstat (limited to 'wxbufferex.cpp')
| -rw-r--r-- | wxbufferex.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/wxbufferex.cpp b/wxbufferex.cpp new file mode 100644 index 0000000..78bd167 --- /dev/null +++ b/wxbufferex.cpp | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | /* | ||
| 2 | * This program is free software; you can redistribute it and/or modify | ||
| 3 | * it under the terms of the GNU General Public License as published by | ||
| 4 | * the Free Software Foundation; version 2 of the License. | ||
| 5 | * | ||
| 6 | * This program is distributed in the hope that it will be useful, | ||
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 9 | * GNU General Public License for more details. | ||
| 10 | * | ||
| 11 | * You should have received a copy of the GNU General Public License | ||
| 12 | * along with this program; if not, write to the Free Software | ||
| 13 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 14 | * | ||
| 15 | * Authors: Manuel Mausz (manuel@mausz.at) | ||
| 16 | * Christian Raschko (c.raschko@netcore.at) | ||
| 17 | */ | ||
| 18 | |||
| 19 | // Header | ||
| 20 | #include "wxbufferex.h" | ||
| 21 | |||
| 22 | //Libraries | ||
| 23 | #include <wx/txtstrm.h> | ||
| 24 | |||
| 25 | //------------------------------------------------------------------------------ | ||
| 26 | // Hex dump on the stream. | ||
| 27 | void wxMemoryBufferEx::HexDump(wxOutputStream &strm) | ||
| 28 | { | ||
| 29 | wxTextOutputStream out(strm); | ||
| 30 | const size_t colums = 16; | ||
| 31 | size_t size = GetDataLen(); | ||
| 32 | |||
| 33 | //print all data | ||
| 34 | for(size_t i = 0; i < ((size % colums == 0) ? (size / colums) : (size / colums) + 1); i++) | ||
| 35 | { | ||
| 36 | //address | ||
| 37 | out << wxString::Format(_T("%.4x "), i * colums); | ||
| 38 | |||
| 39 | //print hex table | ||
| 40 | for(size_t j = 0; j < colums; j++) | ||
| 41 | { | ||
| 42 | if(j == colums/2) | ||
| 43 | out << _T(" "); | ||
| 44 | |||
| 45 | if(j + i*colums >= size) | ||
| 46 | { | ||
| 47 | out << _T(" "); | ||
| 48 | } | ||
| 49 | else | ||
| 50 | { | ||
| 51 | wxByte *pos = static_cast<wxByte *>(GetData()); | ||
| 52 | pos += (j + i * colums); | ||
| 53 | out << wxString::Format(_T(" %.2x"), *pos); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | //seperator | ||
| 58 | out << _T(" "); | ||
| 59 | |||
| 60 | //print ascii | ||
| 61 | for(size_t j = 0; j < colums; j++) | ||
| 62 | { | ||
| 63 | if(j == colums/2) | ||
| 64 | out << _T(" "); | ||
| 65 | if(j + i*colums >= size) | ||
| 66 | { | ||
| 67 | out << _T(" "); | ||
| 68 | } | ||
| 69 | else | ||
| 70 | { | ||
| 71 | wxByte *pos = static_cast<wxByte *>(GetData()); | ||
| 72 | pos += ( j + i * colums); | ||
| 73 | out << wxString::Format(_T("%c"), (wxIsprint(*pos) ? *pos : '.')); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | out << endl; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
