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.

83 lines
2.8 KiB

  1. // File Name: detjpncs.c
  2. // Owner: Tetsuhide Akaishi
  3. // Revision: 1.00 02/21/'93 Tetsuhide Akaishi
  4. //
  5. #include "pch_c.h"
  6. #include "fechrcnv.h"
  7. // The DetectJapaneseCode function find out what kind of code set is there in
  8. // a character string.
  9. //
  10. //
  11. // UCHAR *string Points to the character string to be checked.
  12. //
  13. // int count Specifies the size in bytes of the string pointed
  14. // to by the string parameter.
  15. //
  16. // Return Value
  17. // The function return the followings values.
  18. //
  19. // Value Meaning
  20. // CODE_ONLY_SBCS There are no Japanese character in the
  21. // string.
  22. // CODE_JPN_JIS JIS Code Set. There are JIS Code Set
  23. // character in the string.
  24. // CODE_JPN_EUC EUC Code Set. There are EUC Code Set
  25. // character in the string.
  26. // CODE_JPN_SJIS Shift JIS Code Set. There are Shift JIS
  27. // Code Set character in the string.
  28. //
  29. //
  30. int DetectJPNCode ( UCHAR *string, int count )
  31. {
  32. int i;
  33. BOOL fEUC = FALSE;
  34. int detcount=0;
  35. for ( i = 0 ; i < count ; i++, string++ ) {
  36. if ( *string == ESC ) {
  37. if ( *(string+1) == KANJI_IN_1ST_CHAR &&
  38. ( *(string+2) == KANJI_IN_2ND_CHAR1 || // ESC $ B
  39. *(string+2) == KANJI_IN_2ND_CHAR2 )) { // ESC $ @
  40. return CODE_JPN_JIS;
  41. }
  42. if ( *(string+1) == KANJI_OUT_1ST_CHAR &&
  43. ( *(string+2) == KANJI_OUT_2ND_CHAR1 || // ESC ( B
  44. *(string+2) == KANJI_OUT_2ND_CHAR2 )) { // ESC ( J
  45. return CODE_JPN_JIS;
  46. }
  47. } else if ( *(string) >= 0x0081) {
  48. // Count the length of string for the detection reliability
  49. if (fEUC) detcount++;
  50. if ( *string > 0x00a0 && *string < 0x00e0 || *string == 0x008e ){
  51. if (!fEUC)
  52. detcount++;
  53. fEUC = TRUE;
  54. continue;
  55. }
  56. if ( *(string) < 0x00a0 ) {
  57. return CODE_JPN_SJIS;
  58. }
  59. else if ( *(string) > 0x00fc) {
  60. return CODE_JPN_EUC;
  61. }
  62. }
  63. }
  64. if(fEUC)
  65. {
  66. // If the given string is not long enough, we should rather choose SJIS
  67. // This helps fix the bug when we are just given Window Title
  68. // at Shell HyperText view.
  69. if (detcount > MIN_JPN_DETECTLEN)
  70. return CODE_JPN_EUC;
  71. else
  72. return CODE_JPN_SJIS;
  73. }
  74. return CODE_ONLY_SBCS;
  75. }