diff options
Diffstat (limited to 'wxstreamex.cpp')
| -rw-r--r-- | wxstreamex.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/wxstreamex.cpp b/wxstreamex.cpp new file mode 100644 index 0000000..dfbf7c7 --- /dev/null +++ b/wxstreamex.cpp | |||
| @@ -0,0 +1,108 @@ | |||
| 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 "wxstreamex.h" | ||
| 21 | |||
| 22 | //------------------------------------------------------------------------------ | ||
| 23 | // Writes a fixed string on the stream | ||
| 24 | bool wxDataOutputStreamEx::WriteFixedString(wxString const &str, wxUint8 size) | ||
| 25 | { | ||
| 26 | if((str.Length()+1) > size) | ||
| 27 | return false; | ||
| 28 | |||
| 29 | wxCSConv conv_iso(_T("iso-8859-1")); | ||
| 30 | wxCharBuffer buffer = str.mb_str(conv_iso); | ||
| 31 | |||
| 32 | strm->PutC(wxUint8(strlen(buffer))); | ||
| 33 | |||
| 34 | for(size_t i = 0; i < strlen(buffer); i++) | ||
| 35 | strm->PutC(str[i]); | ||
| 36 | |||
| 37 | for(size_t i = 0; i < (size-strlen(buffer)-1); i++) | ||
| 38 | strm->PutC('\0'); | ||
| 39 | |||
| 40 | return true; | ||
| 41 | } | ||
| 42 | |||
| 43 | //------------------------------------------------------------------------------ | ||
| 44 | // Writes zero terminated string on the stream with zero | ||
| 45 | bool wxDataOutputStreamEx::WriteZeroString(wxString const &str) | ||
| 46 | { | ||
| 47 | if(str.Length() == 0) | ||
| 48 | return false; | ||
| 49 | |||
| 50 | wxCSConv conv_iso(_T("iso-8859-1")); | ||
| 51 | wxCharBuffer buffer = str.mb_str(conv_iso); | ||
| 52 | strm->Write(buffer, strlen(buffer)); | ||
| 53 | strm->PutC('\0'); | ||
| 54 | |||
| 55 | return true; | ||
| 56 | } | ||
| 57 | |||
| 58 | //------------------------------------------------------------------------------ | ||
| 59 | |||
| 60 | // Reades a fixed string from the stream | ||
| 61 | bool wxDataInputStreamEx::ReadFixedString(wxString &str, wxUint8 size) | ||
| 62 | { | ||
| 63 | size_t strlen = 0; | ||
| 64 | char buffer[TS_MAX_LENGTH]; | ||
| 65 | int i = 0; | ||
| 66 | |||
| 67 | strlen = strm->GetC(); | ||
| 68 | for(i = 0; i < size-1; i++) | ||
| 69 | { | ||
| 70 | if(strm->Eof()) | ||
| 71 | { | ||
| 72 | buffer[i] = '\0'; | ||
| 73 | str = wxString::FromAscii(buffer); | ||
| 74 | return false; | ||
| 75 | } | ||
| 76 | |||
| 77 | buffer[i] = strm->GetC(); | ||
| 78 | } | ||
| 79 | |||
| 80 | buffer[i] = '\0'; | ||
| 81 | str = wxString::FromAscii(buffer); | ||
| 82 | wxUnusedVar(strlen); | ||
| 83 | return true; | ||
| 84 | } | ||
| 85 | |||
| 86 | //------------------------------------------------------------------------------ | ||
| 87 | // Reades a zero terminated string from the stream | ||
| 88 | bool wxDataInputStreamEx::ReadZeroString(wxString &str) | ||
| 89 | { | ||
| 90 | wxChar c; | ||
| 91 | char buffer[TS_MAX_LENGTH]; | ||
| 92 | unsigned i = 0; | ||
| 93 | |||
| 94 | c = strm->GetC(); | ||
| 95 | while((c != '\0') && (!strm->Eof())) | ||
| 96 | { | ||
| 97 | buffer[i] = c; | ||
| 98 | i++; | ||
| 99 | c = strm->GetC(); | ||
| 100 | } | ||
| 101 | buffer[i] = '\0'; | ||
| 102 | str = wxString::FromAscii(buffer); | ||
| 103 | if(strm->Eof()) | ||
| 104 | return false; | ||
| 105 | |||
| 106 | return true; | ||
| 107 | } | ||
| 108 | |||
