diff options
Diffstat (limited to '')
| -rw-r--r-- | externals/qhexedit/xbytearray.cpp | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/externals/qhexedit/xbytearray.cpp b/externals/qhexedit/xbytearray.cpp deleted file mode 100644 index 09a04cfeb..000000000 --- a/externals/qhexedit/xbytearray.cpp +++ /dev/null | |||
| @@ -1,167 +0,0 @@ | |||
| 1 | #include "xbytearray.h" | ||
| 2 | |||
| 3 | XByteArray::XByteArray() | ||
| 4 | { | ||
| 5 | _oldSize = -99; | ||
| 6 | _addressNumbers = 4; | ||
| 7 | _addressOffset = 0; | ||
| 8 | |||
| 9 | } | ||
| 10 | |||
| 11 | int XByteArray::addressOffset() | ||
| 12 | { | ||
| 13 | return _addressOffset; | ||
| 14 | } | ||
| 15 | |||
| 16 | void XByteArray::setAddressOffset(int offset) | ||
| 17 | { | ||
| 18 | _addressOffset = offset; | ||
| 19 | } | ||
| 20 | |||
| 21 | int XByteArray::addressWidth() | ||
| 22 | { | ||
| 23 | return _addressNumbers; | ||
| 24 | } | ||
| 25 | |||
| 26 | void XByteArray::setAddressWidth(int width) | ||
| 27 | { | ||
| 28 | if ((width >= 0) && (width<=6)) | ||
| 29 | { | ||
| 30 | _addressNumbers = width; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | QByteArray & XByteArray::data() | ||
| 35 | { | ||
| 36 | return _data; | ||
| 37 | } | ||
| 38 | |||
| 39 | void XByteArray::setData(QByteArray data) | ||
| 40 | { | ||
| 41 | _data = data; | ||
| 42 | _changedData = QByteArray(data.length(), char(0)); | ||
| 43 | } | ||
| 44 | |||
| 45 | bool XByteArray::dataChanged(int i) | ||
| 46 | { | ||
| 47 | return bool(_changedData[i]); | ||
| 48 | } | ||
| 49 | |||
| 50 | QByteArray XByteArray::dataChanged(int i, int len) | ||
| 51 | { | ||
| 52 | return _changedData.mid(i, len); | ||
| 53 | } | ||
| 54 | |||
| 55 | void XByteArray::setDataChanged(int i, bool state) | ||
| 56 | { | ||
| 57 | _changedData[i] = char(state); | ||
| 58 | } | ||
| 59 | |||
| 60 | void XByteArray::setDataChanged(int i, const QByteArray & state) | ||
| 61 | { | ||
| 62 | int length = state.length(); | ||
| 63 | int len; | ||
| 64 | if ((i + length) > _changedData.length()) | ||
| 65 | len = _changedData.length() - i; | ||
| 66 | else | ||
| 67 | len = length; | ||
| 68 | _changedData.replace(i, len, state); | ||
| 69 | } | ||
| 70 | |||
| 71 | int XByteArray::realAddressNumbers() | ||
| 72 | { | ||
| 73 | if (_oldSize != _data.size()) | ||
| 74 | { | ||
| 75 | // is addressNumbers wide enought? | ||
| 76 | QString test = QString("%1") | ||
| 77 | .arg(_data.size() + _addressOffset, _addressNumbers, 16, QChar('0')); | ||
| 78 | _realAddressNumbers = test.size(); | ||
| 79 | } | ||
| 80 | return _realAddressNumbers; | ||
| 81 | } | ||
| 82 | |||
| 83 | int XByteArray::size() | ||
| 84 | { | ||
| 85 | return _data.size(); | ||
| 86 | } | ||
| 87 | |||
| 88 | QByteArray & XByteArray::insert(int i, char ch) | ||
| 89 | { | ||
| 90 | _data.insert(i, ch); | ||
| 91 | _changedData.insert(i, char(1)); | ||
| 92 | return _data; | ||
| 93 | } | ||
| 94 | |||
| 95 | QByteArray & XByteArray::insert(int i, const QByteArray & ba) | ||
| 96 | { | ||
| 97 | _data.insert(i, ba); | ||
| 98 | _changedData.insert(i, QByteArray(ba.length(), char(1))); | ||
| 99 | return _data; | ||
| 100 | } | ||
| 101 | |||
| 102 | QByteArray & XByteArray::remove(int i, int len) | ||
| 103 | { | ||
| 104 | _data.remove(i, len); | ||
| 105 | _changedData.remove(i, len); | ||
| 106 | return _data; | ||
| 107 | } | ||
| 108 | |||
| 109 | QByteArray & XByteArray::replace(int index, char ch) | ||
| 110 | { | ||
| 111 | _data[index] = ch; | ||
| 112 | _changedData[index] = char(1); | ||
| 113 | return _data; | ||
| 114 | } | ||
| 115 | |||
| 116 | QByteArray & XByteArray::replace(int index, const QByteArray & ba) | ||
| 117 | { | ||
| 118 | int len = ba.length(); | ||
| 119 | return replace(index, len, ba); | ||
| 120 | } | ||
| 121 | |||
| 122 | QByteArray & XByteArray::replace(int index, int length, const QByteArray & ba) | ||
| 123 | { | ||
| 124 | int len; | ||
| 125 | if ((index + length) > _data.length()) | ||
| 126 | len = _data.length() - index; | ||
| 127 | else | ||
| 128 | len = length; | ||
| 129 | _data.replace(index, len, ba.mid(0, len)); | ||
| 130 | _changedData.replace(index, len, QByteArray(len, char(1))); | ||
| 131 | return _data; | ||
| 132 | } | ||
| 133 | |||
| 134 | QChar XByteArray::asciiChar(int index) | ||
| 135 | { | ||
| 136 | char ch = _data[index]; | ||
| 137 | if ((ch < 0x20) || (ch > 0x7e)) | ||
| 138 | ch = '.'; | ||
| 139 | return QChar(ch); | ||
| 140 | } | ||
| 141 | |||
| 142 | QString XByteArray::toRedableString(int start, int end) | ||
| 143 | { | ||
| 144 | int adrWidth = realAddressNumbers(); | ||
| 145 | if (_addressNumbers > adrWidth) | ||
| 146 | adrWidth = _addressNumbers; | ||
| 147 | if (end < 0) | ||
| 148 | end = _data.size(); | ||
| 149 | |||
| 150 | QString result; | ||
| 151 | for (int i=start; i < end; i += 16) | ||
| 152 | { | ||
| 153 | QString adrStr = QString("%1").arg(_addressOffset + i, adrWidth, 16, QChar('0')); | ||
| 154 | QString hexStr; | ||
| 155 | QString ascStr; | ||
| 156 | for (int j=0; j<16; j++) | ||
| 157 | { | ||
| 158 | if ((i + j) < _data.size()) | ||
| 159 | { | ||
| 160 | hexStr.append(" ").append(_data.mid(i+j, 1).toHex()); | ||
| 161 | ascStr.append(asciiChar(i+j)); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | result += adrStr + " " + QString("%1").arg(hexStr, -48) + " " + QString("%1").arg(ascStr, -17) + "\n"; | ||
| 165 | } | ||
| 166 | return result; | ||
| 167 | } | ||