diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/hex.cpp | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to '')
-rw-r--r-- | src/stable/hex.cpp | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/stable/hex.cpp b/src/stable/hex.cpp index 3e6a22e..45679b5 100644 --- a/src/stable/hex.cpp +++ b/src/stable/hex.cpp | |||
@@ -8,11 +8,11 @@ | |||
8 | #include "bu/hex.h" | 8 | #include "bu/hex.h" |
9 | 9 | ||
10 | Bu::Hex::Hex( Bu::Stream &rNext, bool bUpperCase, int iChunk ) : | 10 | Bu::Hex::Hex( Bu::Stream &rNext, bool bUpperCase, int iChunk ) : |
11 | Bu::Filter( rNext ), | 11 | Bu::Filter( rNext ), |
12 | iChunk( iChunk ), | 12 | iChunk( iChunk ), |
13 | iPos( 0 ), | 13 | iPos( 0 ), |
14 | iIn( 0 ), | 14 | iIn( 0 ), |
15 | sChrs(bUpperCase?"0123456789ABCDEF":"0123456789abcdef") | 15 | sChrs(bUpperCase?"0123456789ABCDEF":"0123456789abcdef") |
16 | { | 16 | { |
17 | } | 17 | } |
18 | 18 | ||
@@ -22,48 +22,48 @@ Bu::Hex::~Hex() | |||
22 | 22 | ||
23 | void Bu::Hex::start() | 23 | void Bu::Hex::start() |
24 | { | 24 | { |
25 | iPos = iIn = 0; | 25 | iPos = iIn = 0; |
26 | } | 26 | } |
27 | 27 | ||
28 | Bu::size Bu::Hex::stop() | 28 | Bu::size Bu::Hex::stop() |
29 | { | 29 | { |
30 | return iPos; | 30 | return iPos; |
31 | } | 31 | } |
32 | 32 | ||
33 | Bu::size Bu::Hex::read( void *pBuf, Bu::size iBytes ) | 33 | Bu::size Bu::Hex::read( void *pBuf, Bu::size iBytes ) |
34 | { | 34 | { |
35 | Bu::size j; | 35 | Bu::size j; |
36 | uint8_t *puBuf = (uint8_t *)pBuf; | 36 | uint8_t *puBuf = (uint8_t *)pBuf; |
37 | for( j = 0; j < iBytes; j++ ) | 37 | for( j = 0; j < iBytes; j++ ) |
38 | { | 38 | { |
39 | for(; iIn < 2; iIn++ ) | 39 | for(; iIn < 2; iIn++ ) |
40 | { | 40 | { |
41 | if( rNext.read( &cIn[iIn], 1 ) == 0 ) | 41 | if( rNext.read( &cIn[iIn], 1 ) == 0 ) |
42 | return j; | 42 | return j; |
43 | if( cIn[iIn] == ' ' || cIn[iIn] == '\t' || | 43 | if( cIn[iIn] == ' ' || cIn[iIn] == '\t' || |
44 | cIn[iIn] == '\n' || cIn[iIn] == '\r' ) | 44 | cIn[iIn] == '\n' || cIn[iIn] == '\r' ) |
45 | iIn--; | 45 | iIn--; |
46 | } | 46 | } |
47 | #define chr2nibble( c ) ((c>='0'&&c<='9')?(c-'0'):((c|0x60)-'a'+10)) | 47 | #define chr2nibble( c ) ((c>='0'&&c<='9')?(c-'0'):((c|0x60)-'a'+10)) |
48 | puBuf[j] = ((chr2nibble(cIn[0])<<4)|chr2nibble(cIn[1])); | 48 | puBuf[j] = ((chr2nibble(cIn[0])<<4)|chr2nibble(cIn[1])); |
49 | iIn = 0; | 49 | iIn = 0; |
50 | } | 50 | } |
51 | return j; | 51 | return j; |
52 | } | 52 | } |
53 | 53 | ||
54 | Bu::size Bu::Hex::write( const void *pBuf, Bu::size iBytes ) | 54 | Bu::size Bu::Hex::write( const void *pBuf, Bu::size iBytes ) |
55 | { | 55 | { |
56 | char cOut[2]; | 56 | char cOut[2]; |
57 | uint8_t *puBuf = (uint8_t *)pBuf; | 57 | uint8_t *puBuf = (uint8_t *)pBuf; |
58 | for( Bu::size j = 0; j < iBytes; j++ ) | 58 | for( Bu::size j = 0; j < iBytes; j++ ) |
59 | { | 59 | { |
60 | cOut[0] = sChrs[(puBuf[j]&0xf0)>>4]; | 60 | cOut[0] = sChrs[(puBuf[j]&0xf0)>>4]; |
61 | cOut[1] = sChrs[(puBuf[j]&0x0f)]; | 61 | cOut[1] = sChrs[(puBuf[j]&0x0f)]; |
62 | if( iChunk > 0 && iPos%iChunk == 0 && iPos>0 ) | 62 | if( iChunk > 0 && iPos%iChunk == 0 && iPos>0 ) |
63 | rNext.write(" ", 1 ); | 63 | rNext.write(" ", 1 ); |
64 | rNext.write( cOut, 2 ); | 64 | rNext.write( cOut, 2 ); |
65 | iPos++; | 65 | iPos++; |
66 | } | 66 | } |
67 | return iBytes; | 67 | return iBytes; |
68 | } | 68 | } |
69 | 69 | ||