ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Represent/Hexadecimal.cpp
(Generate patch)

Comparing Represent/Hexadecimal.cpp (file contents):
Revision 371 by douglas, 2004-12-21T23:19:54-08:00 vs.
Revision 385 by douglas, 2004-12-23T21:01:12-08:00

# Line 17 | Line 17 | Hexadecimal::Hexadecimal(const ext::Stri
17  
18          size_t index(string.GetSize() % 2), offset(index);
19  
20 <        _rmforeach (ext::Vector<byte_t>, byte, bytes) _rfor (byte_t, half, 0, 2)
21 <        {
22 < /*              byte_t hex(string[index++]);
23 <
24 <                if (hex >= '0' && hex <= '9') hex -= '0'; else*/
25 <        }
20 >        _rmforeach (ext::Vector<byte_t>, byte, bytes) _rfor (byte_t, half, 0, 2) *byte |= hex(string[index++]) << half * 4;
21  
22          if (offset != 0)
23          {
24                  bytes.InsertLast(0);
25  
26 <                //
27 <
33 <                index = 0;
34 <
35 <                //
26 >                bytes.Last() |= hex(string[0]);
27 >                bytes.Last() |= signed_ && bytes.Last() < 8 ? 0xF0 : 0;
28          }
29   }
30  
# Line 44 | Line 36 | Hexadecimal::operator ext::String() cons
36          {
37                  byte_t hex(0xF & *byte >> half * 4);
38  
39 <                switch (hex)
48 <                {
49 <                case 0xA:
50 <                        hex = 'A';
51 <
52 <                        break;
53 <                case 0xB:
54 <                        hex = 'B';
55 <
56 <                        break;
57 <                case 0xC:
58 <                        hex = 'C';
59 <
60 <                        break;
61 <                case 0xD:
62 <                        hex = 'D';
63 <
64 <                        break;
65 <                case 0xE:
66 <                        hex = 'E';
67 <
68 <                        break;
69 <                case 0xF:
70 <                        hex = 'F';
71 <
72 <                        break;
73 <                default:
74 <                        hex += '0';
75 <                }
39 >                if (hex < 0xA) hex += '0'; else hex += 'A' - 0xA;
40  
41                  string.InsertLast(hex);
42          }
43  
44          return string;
45   }
46 +
47 + inline byte_t Hexadecimal::hex(const ext::CodePoint& atom)
48 + {
49 +        if (atom >= '0' && atom <= '9') return atom - '0'; else if (atom >= 'a' && atom <= 'f') return atom - 'a' + 0xA; else if (atom >= 'A' && atom <= 'F') return atom - 'A' + 0xA; else return 0;
50 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines