#include <ByteCharacterEncoder.h>
Inheritance diagram for Core::ByteCharacterEncoder:
Public Member Functions | |
ByteCharacterEncoder (void) | |
virtual | ~ByteCharacterEncoder (void) |
virtual String * | className (void) const |
Answer receiver class name. | |
virtual void | loadFromFile (const char *filename) |
virtual void | loadFrom (Stream *stream) |
virtual void | initializeAsciiEncoder (void) |
virtual Character * | decode (Integer *value) |
virtual Integer * | encode (Character *character) |
virtual long | integerValueFrom (String *strNumber) |
virtual void | parseLine (String *line) |
Static Public Member Functions | |
static ByteCharacterEncoder * | forASCII (void) |
Protected Attributes | |
Array * | decodeMap |
Dictionary * | encodeMap |
|
Definition at line 41 of file ByteCharacterEncoder.cc. References decodeMap, and encodeMap. 00042 { 00043 decodeMap = new Array(256); 00044 encodeMap = new Dictionary(320); // 256 * 5/4 -> pregrowed 00045 }
|
|
Definition at line 47 of file ByteCharacterEncoder.cc. References decodeMap, encodeMap, and nil. 00048 { 00049 if (decodeMap != nil) delete decodeMap; 00050 if (encodeMap != nil) delete encodeMap; 00051 }
|
|
Answer receiver class name. Because there isn't any standard way to obtain class name this method comes to place. Every class should rewrite this method but many didn't (yet). Reimplemented from Core::CharacterEncoder. Definition at line 54 of file ByteCharacterEncoder.cc. 00055 { 00056 return new String("ByteCharacterEncoder"); 00057 }
|
|
Reimplemented from Core::CharacterEncoder. Definition at line 94 of file ByteCharacterEncoder.cc. References Core::Array::at(), decodeMap, Core::Object::error(), and nil. 00095 { 00096 Object *ch = decodeMap->at(value->asLong()); 00097 if (ch == nil) 00098 error(new String("No character available"), 00099 new String(__PRETTY_FUNCTION__), value); 00100 return dynamic_cast<Character *>(ch); 00101 }
|
|
Reimplemented from Core::CharacterEncoder. Definition at line 103 of file ByteCharacterEncoder.cc. References Core::Dictionary::at(), encodeMap, Core::Object::error(), and nil. 00104 { 00105 Integer *value = dynamic_cast<Integer *>(encodeMap->at(character, nil)); 00106 if (value == nil) 00107 error(new String("No character available"), 00108 new String(__PRETTY_FUNCTION__), character); 00109 return value; 00110 }
|
|
Definition at line 77 of file ByteCharacterEncoder.cc. References initializeAsciiEncoder(). Referenced by Core::EncodedStreamFactory::initializeAsciiEncoder(). 00078 { 00079 ByteCharacterEncoder *ascii = new ByteCharacterEncoder; 00080 ascii->initializeAsciiEncoder(); 00081 return ascii; 00082 }
|
|
Definition at line 84 of file ByteCharacterEncoder.cc. References decodeMap, encodeMap, Core::Array::put(), Core::Dictionary::put(), Core::Integer::value(), and Core::Character::value(). Referenced by forASCII(). 00085 { 00086 for (int i = 0; i < 0x7F; i++) { 00087 Character *character = Character::value(i); 00088 encodeMap->put(character, Integer::value(i)); 00089 decodeMap->put(i, character); 00090 } 00091 }
|
|
Definition at line 113 of file ByteCharacterEncoder.cc. References Core::String::at(), Core::Character::digitValue(), and Core::String::startsWith(). Referenced by parseLine(). 00114 { 00115 unsigned long value = 0, index = 0, radix = 10; 00116 if (strNumber->startsWith("0x")) { 00117 index = 2; 00118 radix = 16; 00119 } 00120 00121 for (; index < strNumber->size(); index++) { 00122 Character *ch = dynamic_cast<Character *>(strNumber->at(index)); 00123 value = value * radix + ch->digitValue(); 00124 } 00125 return value; 00126 }
|
|
Definition at line 66 of file ByteCharacterEncoder.cc. References _ensure, Core::Stream::atEnd(), Core::Stream::close(), Core::Stream::nextLine(), and parseLine(). Referenced by loadFromFile(). 00067 { 00068 _ensure( 00069 while (!stream->atEnd()) { 00070 parseLine(dynamic_cast<String *>(stream->nextLine())); 00071 } 00072 , 00073 stream->close() 00074 ); 00075 }
|
|
Definition at line 60 of file ByteCharacterEncoder.cc. References loadFrom(), and Core::IOAccessor::withEncoding(). Referenced by Core::EncodedStreamFactory::createCharacterEncoder(). 00061 { 00062 FileAccessor *file = new FileAccessor(filename, O_RDONLY, 0); 00063 loadFrom(file->withEncoding("us-ascii")->readStream()); 00064 }
|
|
Definition at line 128 of file ByteCharacterEncoder.cc. References Core::Array::at(), decodeMap, encodeMap, integerValueFrom(), Core::Array::put(), Core::Dictionary::put(), Core::Array::size(), Core::Character::space(), Core::Character::tab(), Core::Integer::value(), and Core::Character::value(). Referenced by loadFrom(). 00129 { 00130 long idx; 00131 unsigned long encValue, charValue; 00132 Character *character; 00133 00134 line->replaceAll(Character::tab(), Character::space()); 00135 00136 /* Remove comments */ 00137 idx = line->indexOf('#'); 00138 if (idx > 0) line = dynamic_cast<String *>(line->copy(0, idx)); 00139 line = line->trimBlanks(); 00140 if (idx == 0 || line->isEmpty()) return; 00141 00142 Array *pair = line->asArrayOfSubstrings(); 00143 if (pair->size() >= 2) { /* At least two items are needed */ 00144 encValue = integerValueFrom(dynamic_cast<String *>(pair->at(0))); 00145 charValue = integerValueFrom(dynamic_cast<String *>(pair->at(1))); 00146 } 00147 character = Character::value(charValue); 00148 encodeMap->put(character, Integer::value(encValue)); 00149 decodeMap->put(encValue, character); 00150 }
|
|
Definition at line 41 of file ByteCharacterEncoder.h. Referenced by ByteCharacterEncoder(), decode(), initializeAsciiEncoder(), parseLine(), and ~ByteCharacterEncoder(). |
|
Definition at line 42 of file ByteCharacterEncoder.h. Referenced by ByteCharacterEncoder(), encode(), initializeAsciiEncoder(), parseLine(), and ~ByteCharacterEncoder(). |