/*
IoBind Library License:
--------------------------
The zlib/libpng License Copyright (c) 2003 Jonathan de Halleux, http://iobind.sourceforge.net/
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution
*/
#ifdef byte
#undef byte
#endif
#include <string>
namespace iobind{
namespace detail{
typedef unsigned char byte;
/* ASCII character table */
static byte ASCII_Table[256] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 199, 252, 233, 226, 228, 224, 229,
231, 234, 235, 232, 239, 238, 236, 196, 197, 201, 230, 198, 244, 246, 242,
251, 249, 255, 214, 220, 248, 163, 216, 215, 131, 225, 237, 243, 250, 241,
209, 170, 186, 191, 174, 172, 189, 188, 161, 171, 187, 176, 177, 178, 179,
180, 193, 194, 192, 169, 185, 186, 187, 188, 162, 165, 191, 192, 193, 194,
195, 196, 134, 227, 195, 200, 201, 202, 203, 204, 205, 135, 164, 240, 208,
202, 203, 200, 213, 205, 206, 207, 217, 218, 219, 220, 166, 204, 223, 211,
223, 212, 210, 245, 213, 181, 254, 222, 218, 219, 217, 253, 221, 175, 180,
173, 177, 242, 190, 182, 167, 247, 184, 176, 168, 183, 185, 179, 178, 254,
160
};
/* ANSI character table */
static byte ANSI_Table[256] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 63, 63, 39, 159, 34, 46, 197,
206, 94, 37, 83, 60, 79, 63, 90, 63, 63, 39, 39, 34, 34, 7,
45, 45, 126, 84, 115, 62, 111, 63, 122, 89, 255, 173, 189, 156, 207,
190, 221, 245, 249, 184, 166, 174, 170, 240, 169, 238, 248, 241, 253, 252,
239, 230, 244, 250, 247, 251, 167, 175, 172, 171, 243, 168, 183, 181, 182,
199, 142, 143, 146, 128, 212, 144, 210, 211, 222, 214, 215, 216, 209, 165,
227, 224, 226, 229, 153, 158, 157, 235, 233, 234, 154, 237, 232, 225, 133,
160, 131, 198, 132, 134, 145, 135, 138, 130, 136, 137, 141, 161, 140, 139,
208, 164, 149, 162, 147, 228, 148, 246, 155, 151, 163, 150, 129, 236, 231,
152,
};
/*
* ASCII2ANSI (byte *s)
*
* Converts an ASCII string to an ANSI string.
*/
std::string ascii2ansi(const std::string& ascii)
{
std::string s;
s.resize( ascii.size());
for (size_t i=0;i<ascii.size();++i)
{
s[i] = static_cast<unsigned char>( ASCII_Table[ ascii[i]%256 ]);
};
s.push_back('\0');
return s;
}
/*
* ANSI2ASCII (byte *s)
*
* Converts an ANSI string to an ASCII string.
*/
std::string ansi2ascii(const std::string& ansi)
{
std::string s;
s.resize( ansi.size());
for (size_t i=0;i<ansi.size();++i)
{
s[i] = static_cast<unsigned char>(ANSI_Table[ ansi[i]%256 ]);
};
s.push_back('\0');
return s;
}
}; // detail
};// iobind