-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathCharset.cpp
73 lines (66 loc) · 1.07 KB
/
Charset.cpp
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
#include "StdAfx.h"
#include "Charset.h"
CCharset::CCharset(void)
{
m_pTable = NULL;
m_nCount = 0;
}
CCharset::~CCharset(void)
{
}
//´ÓÎļþ¼ÓÔØ
BOOL CCharset::LoadFromFile(LPCTSTR pFileName)
{
CFile cf;
ULONG len;
if(!cf.Open(pFileName,CFile::modeRead|CFile::shareDenyNone))
{
return FALSE;
}
len = (ULONG)cf.GetLength();
m_pTable = (WCHAR*)malloc(len+2);
if(m_pTable==NULL)
{
cf.Close();
return FALSE;
}
ZeroMemory(m_pTable,len+2);
if(cf.Read(m_pTable,len)!=len)
{
cf.Close();
free(m_pTable);
m_pTable = NULL;
return FALSE;
}
cf.Close();
m_nCount = len/2;
return TRUE;
}
BOOL CCharset::Create(LPCTSTR pString)
{
m_nCount = (UINT)wcslen(pString);
m_pTable = _wcsdup(pString);
return FALSE;
}
void CCharset::Delete()
{
free(m_pTable);
m_pTable = NULL;
m_nCount = 0;
}
WCHAR CCharset::GetChar(UINT index)
{
if(m_pTable == NULL)
{
return L'?';
}
if(index < m_nCount)
{
return *(m_pTable+index);
}
return L'?';
}
UINT CCharset::GetCharCount()
{
return m_nCount;
}