You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.0 KiB
C++
71 lines
1.0 KiB
C++
//
|
|
// GBKÎı¾±àÂëÆ÷
|
|
//
|
|
|
|
#include "TextEncoder.h"
|
|
|
|
TextEncoder::TextEncoder()
|
|
{
|
|
size = 0;
|
|
data = nullptr;
|
|
current_index = 0;
|
|
}
|
|
|
|
TextEncoder::TextEncoder(String text)
|
|
{
|
|
current_index = 0;
|
|
size = text.length();
|
|
data = new byte[size];
|
|
for (int i = 0; i < size; i++)
|
|
data[i] = text[i];
|
|
}
|
|
|
|
TextEncoder::~TextEncoder()
|
|
{
|
|
if (data != nullptr)
|
|
{
|
|
delete[] data;
|
|
data = nullptr;
|
|
}
|
|
}
|
|
|
|
void TextEncoder::EncodeText(String text)
|
|
{
|
|
if (data != nullptr)
|
|
{
|
|
delete[] data;
|
|
data = nullptr;
|
|
}
|
|
current_index = 0;
|
|
size = text.length();
|
|
data = new byte[size];
|
|
for (int i = 0; i < size; i++)
|
|
data[i] = text[i];
|
|
}
|
|
|
|
bool TextEncoder::HasNextChar()
|
|
{
|
|
return (current_index < size);
|
|
}
|
|
|
|
bool TextEncoder::IsLastChar()
|
|
{
|
|
return ((current_index + 1) >= size);
|
|
}
|
|
|
|
void TextEncoder::GetNextChar(byte& bit1, byte& bit2)
|
|
{
|
|
if (data[current_index] >= 0x7F) //ÖÐÎÄ
|
|
{
|
|
bit1 = data[current_index];
|
|
bit2 = data[current_index + 1];
|
|
current_index += 2;
|
|
}
|
|
else
|
|
{
|
|
bit1 = data[current_index];
|
|
bit2 = 0x00;
|
|
current_index++;
|
|
}
|
|
}
|