Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.8 KiB

  1. // =================================================================================
  2. // Internet Character Set Conversion: Output to HZ-GB-2312
  3. // =================================================================================
  4. #include "pch.hxx"
  5. #include "HzGbOut.h"
  6. #include "FEChrCnv.h"
  7. int GB2312_to_HZGB (CONV_CONTEXT *pcontext, UCHAR *pGB2312, int GB2312_len, UCHAR *pHZGB, int HZGB_len)
  8. {
  9. long lConvertedSize;
  10. if (!HZGB_len) {
  11. // Wanted the converted size
  12. if (!pcontext->pIncc0)
  13. pcontext->pIncc0 = new CInccHzGbOut;
  14. if (FAILED(((CInccHzGbOut*)pcontext->pIncc0)->GetStringSizeA(pGB2312, GB2312_len, &lConvertedSize)))
  15. return -1;
  16. } else {
  17. if (!pcontext->pIncc)
  18. pcontext->pIncc = new CInccHzGbOut;
  19. if (FAILED(((CInccHzGbOut*)pcontext->pIncc)->ConvertStringA(pGB2312, GB2312_len, pHZGB, HZGB_len, &lConvertedSize)))
  20. return -1;
  21. }
  22. if (!pGB2312) {
  23. // Let's clean up our context here.
  24. if (pcontext->pIncc0) {
  25. delete pcontext->pIncc0;
  26. pcontext->pIncc0 = NULL;
  27. }
  28. if (pcontext->pIncc) {
  29. delete pcontext->pIncc;
  30. pcontext->pIncc = NULL;
  31. }
  32. return 0;
  33. }
  34. return (int)lConvertedSize;
  35. }
  36. CInccHzGbOut::CInccHzGbOut()
  37. {
  38. fDoubleByte = FALSE;
  39. fGBMode = FALSE;
  40. }
  41. HRESULT CInccHzGbOut::ConvertByte(BYTE by)
  42. {
  43. HRESULT hr = S_OK;
  44. if (!fDoubleByte) {
  45. if (by & 0x80) {
  46. fDoubleByte = TRUE;
  47. byLead = by;
  48. } else {
  49. if (fGBMode) {
  50. (void)Output('~');
  51. hr = Output('}');
  52. fGBMode = FALSE;
  53. }
  54. hr = Output(by);
  55. }
  56. } else {
  57. fDoubleByte = FALSE;
  58. if (!fGBMode) {
  59. (void)Output('~');
  60. (void)Output('{');
  61. fGBMode = TRUE;
  62. }
  63. (void)Output(byLead & 0x7f);
  64. hr = Output(by & 0x7f);
  65. }
  66. return hr;
  67. }
  68. HRESULT CInccHzGbOut::CleanUp()
  69. {
  70. HRESULT hr = S_OK;
  71. if (fGBMode) {
  72. (void)Output('~');
  73. hr = Output('}');
  74. }
  75. return hr;
  76. }