File: IMEConversionHelper.cpp

package info (click to toggle)
dasher 4.11%2Bgit20130508.adc653-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 40,248 kB
  • ctags: 5,158
  • sloc: xml: 185,479; cpp: 32,301; sh: 11,207; makefile: 828; ansic: 483
file content (67 lines) | stat: -rw-r--r-- 1,954 bytes parent folder | download
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
#ifdef JAPANESE

#include "../WIn32/Common/WinUTF8.h"
#include "IMEConversionHelper.h"

#define BUFSIZE 10240

#include <iostream>             //For testing 23 June 2005

CIMEConversionHelper::CIMEConversionHelper(Dasher::CNodeCreationManager *pNCManager, Dasher::const CAlphInfo *pAlphabet)
 : CConversionManager(pNCManager, pAlphabet) {
  IsInit = 0;
  hIMC = ImmCreateContext();
  IsInit = 1;
}

CIMEConversionHelper::~CIMEConversionHelper() {
  ImmDestroyContext( hIMC );
  IsInit = 0;
 }

bool CIMEConversionHelper::Convert(const std::string &strSource, std::vector<std::vector<std::string> > &vResult) {

  std::wstring strInput;
  WinUTF8::UTF8string_to_wstring(strSource, strInput);

  HKL hKL;
  DWORD dwSize;
  LPCANDIDATELIST lpCand;

  hKL = GetKeyboardLayout(0);
	const WCHAR *pQuery = strInput.c_str();
	//while( wcslen(pQuery) ){
		dwSize = ImmGetConversionList(hKL, hIMC, (LPCWSTR)pQuery, NULL, 0, GCL_CONVERSION);
    if(dwSize > 0) {
		  lpCand = (LPCANDIDATELIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
		  dwSize = ImmGetConversionList(hKL, hIMC, (LPCWSTR)pQuery, lpCand, dwSize, GCL_CONVERSION);
		  size_t MaxLen = 0;
      std::vector<std::string> new_phrase;
		  //	For all candidates
		  for (unsigned int i = 0; i< lpCand->dwCount; i++)
		  {
        std::wstring strOutput((WCHAR *)((char *)lpCand + lpCand->dwOffset[i]));
        std::string strUTF8Output;
        WinUTF8::wstring_to_UTF8string(strOutput, strUTF8Output);
		    new_phrase.push_back(strUTF8Output);
			  //sprintf( buf, "%s\n",(LPBYTE)lpCand + lpCand->dwOffset[i] );
			  // Find hiragana length

        MaxLen = strOutput.size();

			  /*if( wcslen( (WCHAR *)lpCand + lpCand->dwOffset[i] ) > MaxLen )
  				MaxLen = wcslen( (WCHAR *)lpCand + lpCand->dwOffset[i] );*/
		  }
		  vResult.push_back(new_phrase);
		  HeapFree(GetProcessHeap(), 0, lpCand);
		  pQuery += MaxLen;
    }
    else {
    //  break;
    }
	//}

  return true;
}

#endif