HANDLE PiTranslate(__in TCHAR* szSrc, __in SSN_OBJECT_ID TranslaterId)

HANDLE PiTranslate(__in TCHAR* szSrc, __in SSN_OBJECT_ID TranslaterId)
{
 tstrSectionBuffer = _T("");
 tstrBuffer = _T("");
 dBufferSectionLength = 0;
 CTranslate* pTranslate = new CTranslate;
 tstring strInSrc = szSrc;
 tstring strSub;
 Trim(strInSrc);
 if ((strInSrc==_T("i"))||(strInSrc==_T("I")))
 {
  pTranslate->m_strBuffer = strInSrc;
  return (HANDLE)pTranslate;
 }

 BOOL bFlagTxt = FALSE;
 BOOL bFlagList = FALSE;

 int nCount;
 int j =0;
 BOOL bFlagFind = FALSE;
 while(strInSrc.length()>0)
 {
  TCHAR szInSrc[MAX_PATH]={0};
  _tcscpy_s(szInSrc, _countof(szInSrc),strInSrc.c_str());
  strSub = _T(" ");
  nCount = 0;
  for (size_t i=0;i   {

   int ntimes  = 0;
   int npos    = 0;
   int nSpace = strInSrc.find(_T(" "));
   if ( nSpace == -1 )
   {
    strSub = strInSrc;
   }
   else
   {
    while(bFlagFind)
    {
     npos = strInSrc.find_first_of(_T(" "),npos);
     if(npos == -1)
     {
      break;
     }
     ++ntimes;
     ++npos;
    }
    if ((ntimes>5)||(ntimes==0))
    {
     ntimes=5;
     tstring m =_T("");
     m.insert( m.begin(), (szInSrc[i]));
     if ( m == _T(" "))
     {
      nCount++;
      if (nCount>=ntimes-j)  
      {    
       strSub = strInSrc.substr(0,i);
       break;
      }
     }
    }
    else
    {
     if(j==0)
     {
      strSub = strInSrc;
     }
     else
     {
      tstring m =_T("");
      m.insert( m.begin(), (szInSrc[i]));
      if ( m == _T(" "))
      {
       nCount++;
       if (nCount>=ntimes-j+1)  
       {    
        strSub = strInSrc.substr(0,i);
        break;
       }
      }
     }
    }
   }
  }
 
  map::iterator  iter;
  for(iter = m_mapQuickUser.begin(); iter != m_mapQuickUser.end(); iter++)
  {
   if (_tcsicmp(iter->first.c_str(),strSub.c_str())==0)
   {
    tstrSectionBuffer = iter->second;
    dBufferSectionLength = iter->second.size();
    bFlagTxt = TRUE;
    strInSrc = strInSrc.substr(strSub.length(),strInSrc.length());
    Trim(strInSrc);
   } 
  }
  if (bFlagTxt == FALSE) 
  {
   string strInDict = "";
   strOutDict = "";

   int i = 0 ;
   strInDict = (SSN::CT2A)(strSub.c_str());

   int nIndex =-1;
   nIndex = vTranslate.Search(pEnglish[strInDict.c_str()]);
   if(nIndex< 0 || nIndex>=vTranslate.GetSize())
   {
    nIndex =0;
   }
   if(_stricmp(string(pEnglish (vTranslate[nIndex])).c_str(),strInDict.c_str())==0)
   {
    strOutDict = string(pChinese (vTranslate[nIndex]));
    if (strOutDict.length()>0)
    {
     dBufferSectionLength = strOutDict.length();
     tstrSectionBuffer = (SSN::CA2T)strOutDict.c_str();
     bFlagList = TRUE;
     strInSrc = strInSrc.substr(strInDict.length(),strInSrc.length());
     Trim(strInSrc);
    }
    else
    {
     if (j==5)
     {
      tstrSectionBuffer = strSub;
      TCHAR szSectionBuffer[MAX_PATH];
       _tcscpy_s(szSectionBuffer,_countof(szSectionBuffer),tstrSectionBuffer.c_str());
      if (szSectionBuffer[tstrSectionBuffer.length()-2] <= 0x0080)
      {
       tstrSectionBuffer= tstrSectionBuffer+_T(" ");
      }
      dBufferSectionLength = strSub.length();
      if (strSub != _T(""))
      {
       bFlagList = TRUE;
      }
      strInSrc = strInSrc.substr(strSub.length(),strInSrc.length());
      Trim(strInSrc);
     } 
    } 
   }
   else
   {
     if (j==5)
     {
      tstrSectionBuffer = strSub;
      TCHAR szSectionBuffer[MAX_PATH];
      _tcscpy_s(szSectionBuffer,_countof(szSectionBuffer),tstrSectionBuffer.c_str());
      if (szSectionBuffer[tstrSectionBuffer.length()-2] <= 0x0080)
      {
       tstrSectionBuffer= tstrSectionBuffer+_T(" ");
      }
      dBufferSectionLength = strSub.length();
      if (strSub != _T(""))
      {
       bFlagList = TRUE;
      }
      strInSrc = strInSrc.substr(strSub.length(),strInSrc.length());
      Trim(strInSrc); 
     }   
   }
  }
  if ((bFlagTxt==FALSE)&&(bFlagList==FALSE))
  {
   if (strInSrc!=_T(""))
   {
     j++;
   }
  
  }
  else
  {  
   tstrBuffer = tstrBuffer + tstrSectionBuffer;
   pTranslate->dBufferLength = pTranslate->dBufferLength + dBufferSectionLength;
   tstrSectionBuffer = _T("");
   dBufferSectionLength = 0;
   bFlagFind=TRUE;
   bFlagTxt=FALSE;
   bFlagList=FALSE;
   j=0;
  } 
 }
 pTranslate->m_strBuffer = tstrBuffer;
 return (HANDLE)pTranslate;
}

你可能感兴趣的:(C++)