Jsupport.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // JSUPPORT.CPP
  19. // DBCS Support Codes
  20. #include <windows.h>
  21. #include "jsupport.h"
  22. // 前置禁則文字
  23. // Can't set these characters on top of line
  24. static BOOL IsDBCSInvalidAtTop(unsigned int c)
  25. {
  26. static BYTE * dtbl = (BYTE *)"¢°’”‰′″℃、。々〉》」』】〕ぁぃぅぇぉっゃゅょゎ゛゜ゝゞァィゥェォッャュョヮヵヶ・ーヽヾ!%),.:;?]}";
  27. static BYTE * stbl = (BYTE *)"!%),.:;?]}。」、・゙゚";
  28. if(c<0x100)
  29. {
  30. if(strchr((char *)stbl,(char)c))
  31. return TRUE;
  32. }
  33. else
  34. {
  35. BYTE c1,c2,*p;
  36. c1 = (BYTE)(c >> 8);
  37. c2 = (BYTE)(c & 0xff);
  38. p = dtbl;
  39. while(*p)
  40. {
  41. if((*p==c1)&&(*(p+1)==c2))
  42. return TRUE;
  43. p+=2;
  44. }
  45. }
  46. return FALSE;
  47. }
  48. // 後置禁則文字
  49. // Can't set these characters on end of line
  50. static BOOL IsDBCSInvalidAtEnd( unsigned int c )
  51. {
  52. static BYTE * dtbl = (BYTE *)"‘“〈《「『【〔([{$£¥";
  53. static BYTE * stbl = (BYTE *)"「({[";
  54. if(c<0x100)
  55. {
  56. if(strchr((char *)stbl,(char)c))
  57. return TRUE;
  58. }
  59. else
  60. {
  61. BYTE c1,c2,*p;
  62. c1 = (BYTE)(c >> 8);
  63. c2 = (BYTE)(c & 0xff);
  64. p = dtbl;
  65. while(*p)
  66. {
  67. if((*p==c1)&&(*(p+1)==c2))
  68. return TRUE;
  69. p+=2;
  70. }
  71. }
  72. return FALSE;
  73. }
  74. int nGetWord( char *string, int fdbcs )
  75. {
  76. BOOL bCiae0, bCiat1, bDbcs0, bDbcs1;
  77. BYTE *p = (BYTE *)string;
  78. UINT c0, c1, c;
  79. //--------------------------------------------------------------------------
  80. // If no string was passed in, exit.
  81. //--------------------------------------------------------------------------
  82. if( !p || !( c0 = *p++ )) {
  83. // if(( p == NULL ) || ( *p == '\0' )) {
  84. return 0;
  85. }
  86. // c0 = *p;
  87. //--------------------------------------------------------------------------
  88. // If we are NOT a double-byte language, then just parse first word.
  89. //--------------------------------------------------------------------------
  90. if( !fdbcs ) {
  91. int n = 0;
  92. while( *p >' ' ) {
  93. n++;
  94. p++;
  95. }
  96. if( *p ) {
  97. n++;
  98. }
  99. return n;
  100. }
  101. //--------------------------------------------------------------------------
  102. // If we are a double-byte language...
  103. //--------------------------------------------------------------------------
  104. bDbcs0 = IsDBCSLeadByte( c0 ) && *p;
  105. if( bDbcs0 ) {
  106. c0 = ( c0 << 8 ) | *p++;
  107. }
  108. bCiae0 = IsDBCSInvalidAtEnd( c0 );
  109. while( c1 = *p ) {
  110. bDbcs1 = ( IsDBCSLeadByte( c1 ) && ( c = *( p + 1 )));
  111. if( bDbcs1 ) {
  112. c1 = ( c1<<8 ) | c;
  113. }
  114. if(( bDbcs0 || bDbcs1 ) && !( bDbcs0 && bDbcs1 )) { // XOR
  115. break;
  116. }
  117. if( bDbcs1 ) {
  118. bCiat1 = IsDBCSInvalidAtTop( c1 );
  119. if( !( bCiae0 || bCiat1 )) {
  120. break;
  121. }
  122. bCiae0 = IsDBCSInvalidAtEnd( c1 );
  123. p+=2;
  124. } else {
  125. if( c0<=' ' ) {
  126. break;
  127. }
  128. p++;
  129. }
  130. bDbcs0 = bDbcs1;
  131. c0 = c1;
  132. }
  133. return( p - (BYTE *)string );
  134. }