00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "Poco/ASCIIEncoding.h"
00038 #include "Poco/String.h"
00039
00040
00041 namespace Poco {
00042
00043
00044 const char* ASCIIEncoding::_names[] =
00045 {
00046 "ASCII",
00047 NULL
00048 };
00049
00050
00051 const TextEncoding::CharacterMap ASCIIEncoding::_charMap =
00052 {
00053 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
00054 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
00055 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
00056 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
00057 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
00058 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
00059 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
00060 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
00061 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00062 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00063 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00064 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00065 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00066 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00067 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00068 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00069 };
00070
00071
00072 ASCIIEncoding::ASCIIEncoding()
00073 {
00074 }
00075
00076
00077 ASCIIEncoding::~ASCIIEncoding()
00078 {
00079 }
00080
00081
00082 const char* ASCIIEncoding::canonicalName() const
00083 {
00084 return _names[0];
00085 }
00086
00087
00088 bool ASCIIEncoding::isA(const std::string& encodingName) const
00089 {
00090 for (const char** name = _names; *name; ++name)
00091 {
00092 if (Poco::icompare(encodingName, *name) == 0)
00093 return true;
00094 }
00095 return false;
00096 }
00097
00098
00099 const TextEncoding::CharacterMap& ASCIIEncoding::characterMap() const
00100 {
00101 return _charMap;
00102 }
00103
00104
00105 int ASCIIEncoding::convert(const unsigned char* bytes) const
00106 {
00107 return *bytes;
00108 }
00109
00110
00111 int ASCIIEncoding::convert(int ch, unsigned char* bytes, int length) const
00112 {
00113 if (ch >= 0 && ch <= 127)
00114 {
00115 if (bytes && length >= 1)
00116 *bytes = (unsigned char) ch;
00117 return 1;
00118 }
00119 else return 0;
00120 }
00121
00122
00123 }