widestr.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. {
  2. $Id$
  3. Copyright (c) 2000 by Florian Klaempfl
  4. This unit contains basic functions for unicode support in the
  5. compiler, this unit is mainly necessary to bootstrap widestring
  6. support ...
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ****************************************************************************
  19. }
  20. unit widestr;
  21. interface
  22. { uses
  23. charset;
  24. }
  25. type
  26. tcompilerwidechar = word;
  27. {$ifdef delphi}
  28. { delphi doesn't allow pointer accessing as array }
  29. tcompilerwidechararray = array[0..0] of tcompilerwidechar;
  30. pcompilerwidechar = ^tcompilerwidechararray;
  31. {$else}
  32. pcompilerwidechar = ^tcompilerwidechar;
  33. {$endif}
  34. pcompilerwidestring = ^tcompilerwidestring;
  35. tcompilerwidestring = record
  36. data : pcompilerwidechar;
  37. maxlen,len : longint;
  38. end;
  39. procedure initwidestring(var r : tcompilerwidestring);
  40. procedure donewidestring(var r : tcompilerwidestring);
  41. procedure setlengthwidestring(var r : tcompilerwidestring;l : longint);
  42. function getlengthwidestring(const r : tcompilerwidestring) : longint;
  43. procedure concatwidestringchar(var r : tcompilerwidestring;c : tcompilerwidechar);
  44. procedure concatwidestringwidestring(const s1,s2 : tcompilerwidestring;
  45. var r : tcompilerwidestring);
  46. procedure copywidestring(const s : tcompilerwidestring;var d : tcompilerwidestring);
  47. function asciichar2unicode(c : char) : tcompilerwidechar;
  48. procedure ascii2unicode(const s : string;var r : tcompilerwidestring);
  49. function getcharwidestring(const r : tcompilerwidestring;l : longint) : tcompilerwidechar;
  50. function cpavailable(const s : string) : boolean;
  51. implementation
  52. { uses
  53. i8869_1,cp850,cp437; }
  54. uses
  55. globals;
  56. procedure initwidestring(var r : tcompilerwidestring);
  57. begin
  58. r.data:=nil;
  59. r.len:=0;
  60. r.maxlen:=0;
  61. end;
  62. procedure donewidestring(var r : tcompilerwidestring);
  63. begin
  64. if assigned(r.data) then
  65. freemem(r.data);
  66. r.data:=nil;
  67. r.maxlen:=0;
  68. r.len:=0;
  69. end;
  70. function getcharwidestring(const r : tcompilerwidestring;l : longint) : tcompilerwidechar;
  71. begin
  72. getcharwidestring:=r.data[l];
  73. end;
  74. function getlengthwidestring(const r : tcompilerwidestring) : longint;
  75. begin
  76. getlengthwidestring:=r.len;
  77. end;
  78. procedure setlengthwidestring(var r : tcompilerwidestring;l : longint);
  79. begin
  80. if r.maxlen>=l then
  81. exit;
  82. if assigned(r.data) then
  83. reallocmem(r.data,sizeof(tcompilerwidechar)*l)
  84. else
  85. getmem(r.data,sizeof(tcompilerwidechar)*l);
  86. end;
  87. procedure concatwidestringchar(var r : tcompilerwidestring;c : tcompilerwidechar);
  88. begin
  89. if r.len>=r.maxlen then
  90. setlengthwidestring(r,r.len+16);
  91. r.data[r.len]:=c;
  92. inc(r.len);
  93. end;
  94. procedure concatwidestringwidestring(const s1,s2 : tcompilerwidestring;
  95. var r : tcompilerwidestring);
  96. begin
  97. setlengthwidestring(r,s1.len+s2.len);
  98. r.len:=s1.len+s2.len;
  99. move(s1.data^,r.data^,s1.len);
  100. move(s2.data^,r.data[s1.len],s2.len);
  101. end;
  102. function comparewidestringwidestring(const s1,s2 : tcompilerwidestring) : longint;
  103. begin
  104. {$ifdef fpc}{$warning todo}{$endif}
  105. comparewidestringwidestring:=0;
  106. end;
  107. procedure copywidestring(const s : tcompilerwidestring;var d : tcompilerwidestring);
  108. begin
  109. setlengthwidestring(d,s.len);
  110. d.len:=s.len;
  111. move(s.data^,d.data^,s.len);
  112. end;
  113. function asciichar2unicode(c : char) : tcompilerwidechar;
  114. {!!!!!!!!
  115. var
  116. m : punicodemap;
  117. begin
  118. m:=getmap(aktsourcecodepage);
  119. asciichar2unicode:=getunicode(c,m);
  120. end;
  121. }
  122. begin
  123. {$ifdef fpc}{$warning todo}{$endif}
  124. asciichar2unicode:=0;
  125. end;
  126. procedure ascii2unicode(const s : string;var r : tcompilerwidestring);
  127. (*
  128. var
  129. m : punicodemap;
  130. i : longint;
  131. begin
  132. m:=getmap(aktsourcecodepage);
  133. { should be a very good estimation :) }
  134. setlengthwidestring(r,length(s));
  135. // !!!! MBCS
  136. for i:=1 to length(s) do
  137. begin
  138. end;
  139. end;
  140. *)
  141. begin
  142. end;
  143. function cpavailable(const s : string) : boolean;
  144. {!!!!!!
  145. begin
  146. cpavailable:=mappingavailable(s);
  147. end;
  148. }
  149. begin
  150. cpavailable:=false;
  151. end;
  152. end.
  153. {
  154. $Log$
  155. Revision 1.3 2001-04-13 01:22:17 peter
  156. * symtable change to classes
  157. * range check generation and errors fixed, make cycle DEBUG=1 works
  158. * memory leaks fixed
  159. Revision 1.2 2001/04/02 21:20:35 peter
  160. * resulttype rewrite
  161. Revision 1.1 2000/11/29 00:30:43 florian
  162. * unused units removed from uses clause
  163. * some changes for widestrings
  164. }