My Project
SimpleTranslator.h
1 #pragma once
2 #include "StringHelper.h"
3 
4 namespace ParaEngine
5 {
10  {
11  public:
12  typedef std::map<WCHAR, WCHAR> CharacterWideCharMap_type;
13  CSimpleTranslater(const char* sFileName)
14  :m_nMinRange(0xffff), m_nMaxRange(0)
15  {
16  CParaFile file;
17  file.OpenAssetFile(sFileName);
18 
19  if(!file.isEof())
20  {
21  char sLineText[256];
22  while(file.GetNextLine(sLineText, 256)>0)
23  {
24  const WCHAR* swText = ParaEngine::StringHelper::MultiByteToWideChar(sLineText, DEFAULT_GUI_ENCODING);
25  if(swText)
26  {
27  WCHAR wcFrom = *swText;
28  if(wcFrom != L'\0')
29  {
30  WCHAR wcTo = *(++swText);
31  bool bBreak = false;
32  while(wcTo!=L'\0' && !bBreak)
33  {
34  if(wcTo!=L' ' && wcTo!=L'\t')
35  {
36  bBreak = true;
37  m_char_map[wcFrom] = wcTo;
38  if(wcFrom<m_nMinRange)
39  m_nMinRange = wcFrom;
40  if(wcFrom>m_nMaxRange)
41  m_nMaxRange = wcFrom;
42  }
43  wcTo = *(++swText);
44  }
45  }
46  }
47  }
48  }
49  else
50  {
51  OUTPUT_LOG("error: unable to open locale file %s\n", sFileName);
52  }
53  }
54 
55  const WCHAR* TranslateW(const WCHAR* sText)
56  {
57  if(sText == NULL)
58  return NULL;
59  static vector<WCHAR> sOutput;
60  int nSize = (int)(wcslen(sText));
61  if(nSize >= ((int)sOutput.size()))
62  {
63  sOutput.resize(nSize+2);
64  sOutput[nSize] = L'\0';
65  }
66  for(int i=0; i<nSize; ++i)
67  {
68  WCHAR c = sText[i];
69  if(m_nMinRange<=c && c<=m_nMaxRange)
70  {
71  CharacterWideCharMap_type::iterator iter = m_char_map.find(c);
72  if(iter!=m_char_map.end())
73  {
74  sOutput[i] = iter->second;
75  }
76  else
77  {
78  sOutput[i] = sText[i];
79  }
80  }
81  else
82  {
83  sOutput[i] = sText[i];
84  }
85  }
86  sOutput[nSize] = L'\0';
87  return &(sOutput[0]);
88  }
89  private:
90  CharacterWideCharMap_type m_char_map;
91  WCHAR m_nMinRange;
92  WCHAR m_nMaxRange;
93  };
94 }
95 
96 
PE_CORE_DECL int OpenAssetFile(const char *filename, bool bDownloadIfNotUpToDate=true, const char *relativePath=NULL)
This is rather similar to OpenFile() method, except that it will first look in the AssetManifest to s...
Definition: ParaFile.cpp:384
different physics engine has different winding order.
Definition: EventBinding.h:32
PE_CORE_DECL int GetNextLine(char *buf, int sizeBuf)
return the next line of text string from the current file position.
Definition: ParaFile.cpp:1226
it presents a real or virtual file in ParaEngine.
Definition: ParaFile.h:31
this is usually used for translating from simplified Chinese to traditional Chinese character...
Definition: SimpleTranslator.h:9