strings.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1998 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************}
  12. {* TStrings *}
  13. {****************************************************************************}
  14. // Function to quote text. Should move maybe to sysutils !!
  15. // Also, it is not clear at this point what exactly should be done.
  16. { //!! is used to mark unsupported things. }
  17. Function QuoteString (Const S : String; Quote : String) : String;
  18. Var I,J : Longint;
  19. begin
  20. I:=0;
  21. J:=0;
  22. Result:=S;
  23. While I<Length(S) do
  24. begin
  25. I:=I+1;
  26. J:=J+1;
  27. if S[i]=Quote then
  28. begin
  29. System.Insert(Result,Quote,J);
  30. J:=J+1;
  31. end;
  32. end;
  33. Result:=Quote+Result+Quote;
  34. end;
  35. function TStrings.GetCommaText: string;
  36. Var I : Longint;
  37. begin
  38. result:='';
  39. For i:=0 to count-1 do
  40. begin
  41. Result:=Result+QuoteString (Strings[I],'"');
  42. if I<Count-1 then Result:=Result+',';
  43. end;
  44. If Length(Result)=0 then Result:='""';
  45. end;
  46. function TStrings.GetName(Index: Integer): string;
  47. Var L : longint;
  48. begin
  49. Result:=Strings[Index];
  50. L:=Pos('=',Result);
  51. If L<>0 then
  52. Result:=Copy(Result,1,L-1)
  53. else
  54. Result:='';
  55. end;
  56. Function TStrings.GetValue(const Name: string): string;
  57. Var L : longint;
  58. begin
  59. Result:='';
  60. L:=IndexOf(Name);
  61. If L<>-1 then
  62. begin
  63. Result:=Strings[L];
  64. L:=Pos('=',Result);
  65. System.Delete (Result,1,L);
  66. end;
  67. end;
  68. Procedure TStrings.ReadData(Reader: TReader);
  69. begin
  70. end;
  71. Function GetQuotedString (Var P : Pchar) : String;
  72. Var P1,L : Pchar;
  73. begin
  74. Result:='';
  75. P1:=P+1;
  76. While P1^<>#0 do
  77. begin
  78. If (P1^='"') and (P1[1]<>'"') then
  79. break;
  80. P1:=P1+1;
  81. If P1^='"' then P1:=P1+1;
  82. end;
  83. // P1 points to last quote, or to #0;
  84. P:=P+1;
  85. If P1-P>0 then
  86. begin
  87. //!! SetLength(Result,P1-P);
  88. //!! L:=Pointer(Result);
  89. Move (P^,L^,P1-P);
  90. P:=P1+1;
  91. end;
  92. end;
  93. Function GetNextQuotedChar (P : PChar; Var S : String): Boolean;
  94. Var PS,L : PChar;
  95. begin
  96. Result:=False;
  97. If P^=#0 then exit;
  98. S:='';
  99. While (p^<>#0) and (byte(p^)<=byte(' ')) do P:=P+1;
  100. PS:=P;
  101. If P^='"' then
  102. S:=GetQuotedString(P)
  103. else
  104. begin
  105. While (p^>' ') and (P^<>',') do P:=P+1;
  106. //!! Setlength (S,P-PS);
  107. //!! L:=Pointer(S);
  108. Move (PS^,L,P-PS);
  109. end;
  110. Result:=True;
  111. end;
  112. Procedure TStrings.SetCommaText(const Value: string);
  113. Var P : Pointer;
  114. S : String;
  115. begin
  116. Self.Clear;
  117. //!! P:=Pointer(Value);
  118. While GetNextQuotedChar (P,S) do Add (S);
  119. end;
  120. Procedure TStrings.SetStringsAdapter(const Value: IStringsAdapter);
  121. begin
  122. end;
  123. Procedure TStrings.SetValue(const Name, Value: string);
  124. Var L : longint;
  125. begin
  126. L:=IndexOfName(Name);
  127. if L=-1 then
  128. Add (Name+'='+Value)
  129. else
  130. Strings[L]:=Name+'='+value;
  131. end;
  132. Procedure TStrings.WriteData(Writer: TWriter);
  133. begin
  134. end;
  135. Procedure TStrings.DefineProperties(Filer: TFiler);
  136. begin
  137. end;
  138. Procedure TStrings.Error(const Msg: string; Data: Integer);
  139. begin
  140. end;
  141. Function TStrings.GetCapacity: Integer;
  142. begin
  143. Result:=Count;
  144. end;
  145. Function TStrings.GetObject(Index: Integer): TObject;
  146. begin
  147. Result:=Nil;
  148. end;
  149. Function TStrings.GetTextStr: string;
  150. Const
  151. {$ifdef linux}
  152. NewLineSize=1;
  153. {$else}
  154. NewLineSize=2;
  155. {$endif}
  156. Var P : Pchar;
  157. I,L : Longint;
  158. S : String;
  159. PS : Pointer;
  160. begin
  161. // Determine needed place
  162. L:=0;
  163. For I:=0 to count-1 do L:=L+Length(Strings[I])+NewLineSize;
  164. //!! Setlength(Result,0);
  165. //!! P:=Pointer(Result);
  166. For i:=0 To count-1 do
  167. begin
  168. S:=Strings[I];
  169. L:=Length(S);
  170. //!! if L<>0 then
  171. //!! System.Move(Pointer(S)^,P^,L);
  172. P:=P+L;
  173. p[0]:=#10;
  174. {$ifndef linux}
  175. p[1]:=#13;
  176. {$endif}
  177. P:=P+NewLineSize;
  178. end;
  179. end;
  180. Procedure TStrings.Put(Index: Integer; const S: string);
  181. Var Obj : TObject;
  182. begin
  183. Obj:=Objects[Index];
  184. Delete(Index);
  185. InsertObject(Index,S,Obj);
  186. end;
  187. Procedure TStrings.PutObject(Index: Integer; AObject: TObject);
  188. begin
  189. // Empty.
  190. end;
  191. Procedure TStrings.SetCapacity(NewCapacity: Integer);
  192. begin
  193. // Empty.
  194. end;
  195. Procedure TStrings.SetTextStr(const Value: string);
  196. begin
  197. //!! SetText(PChar(Value));
  198. end;
  199. Procedure TStrings.SetUpdateState(Updating: Boolean);
  200. begin
  201. end;
  202. destructor TSTrings.Destroy;
  203. begin
  204. inherited destroy;
  205. end;
  206. Function TStrings.Add(const S: string): Integer;
  207. begin
  208. Result:=Count;
  209. Insert (Count,S);
  210. end;
  211. Function TStrings.AddObject(const S: string; AObject: TObject): Integer;
  212. begin
  213. Result:=Add(S);
  214. Objects[result]:=AObject;
  215. end;
  216. Procedure TStrings.Append(const S: string);
  217. begin
  218. Add (S);
  219. end;
  220. Procedure TStrings.AddStrings(TheStrings: TStrings);
  221. Var Runner : longint;
  222. begin
  223. For Runner:=0 to TheStrings.Count-1 do
  224. self.AddObject (Thestrings[Runner],TheStrings.Objects[Runner]);
  225. end;
  226. Procedure TStrings.Assign(Source: TPersistent);
  227. begin
  228. If Source is TStrings then
  229. begin
  230. clear;
  231. AddStrings(TStrings(Source));
  232. exit;
  233. end;
  234. Inherited Assign(Source);
  235. end;
  236. Procedure TStrings.BeginUpdate;
  237. begin
  238. end;
  239. Procedure TStrings.EndUpdate;
  240. begin
  241. end;
  242. Function TStrings.Equals(TheStrings: TStrings): Boolean;
  243. Var Runner,Nr : Longint;
  244. begin
  245. Result:=False;
  246. Nr:=Self.Count;
  247. if Nr<>TheStrings.Count then exit;
  248. For Runner:=0 to Nr-1 do
  249. If Strings[Runner]<>TheStrings[Runner] then exit;
  250. Result:=True;
  251. end;
  252. Procedure TStrings.Exchange(Index1, Index2: Integer);
  253. Var
  254. Obj : TObject;
  255. Str : String;
  256. begin
  257. Obj:=Objects[Index1];
  258. Str:=Strings[Index1];
  259. Objects[Index1]:=Objects[Index2];
  260. Strings[Index1]:=Strings[Index2];
  261. Objects[Index2]:=Obj;
  262. Strings[Index2]:=Str;
  263. end;
  264. Function TStrings.GetText: PChar;
  265. begin
  266. //!! Result:=StrNew(Pchar(Self.Text));
  267. end;
  268. Function TStrings.IndexOf(const S: string): Integer;
  269. begin
  270. Result:=0;
  271. While (Result<Count) and (Strings[Result]<>S) do Result:=Result+1;
  272. if Result=Count then Result:=-1;
  273. end;
  274. Function TStrings.IndexOfName(const Name: string): Integer;
  275. Var len : longint;
  276. begin
  277. Result:=0;
  278. while (Result<Count) do
  279. begin
  280. len:=pos('=',Strings[Result])-1;
  281. if (len>0) and (Name=Copy(Strings[Result],1,Len)) then exit;
  282. inc(result);
  283. end;
  284. result:=-1;
  285. end;
  286. Function TStrings.IndexOfObject(AObject: TObject): Integer;
  287. begin
  288. Result:=0;
  289. While (Result<count) and (Objects[Result]<>AObject) do Result:=Result+1;
  290. If Result=Count then Result:=-1;
  291. end;
  292. Procedure TStrings.InsertObject(Index: Integer; const S: string;
  293. AObject: TObject);
  294. begin
  295. Insert (Index,S);
  296. Objects[Index]:=AObject;
  297. end;
  298. Procedure TStrings.LoadFromFile(const FileName: string);
  299. Var TheStream : TFileStream;
  300. begin
  301. TheStream:=TFileStream.Create(FileName,fmOpenRead);
  302. LoadFromStream(TheStream);
  303. TheStream.Free;
  304. end;
  305. Procedure TStrings.LoadFromStream(Stream: TStream);
  306. begin
  307. Text:=Stream.ReadAnsiString;
  308. end;
  309. Procedure TStrings.Move(CurIndex, NewIndex: Integer);
  310. Var Obj : TObject;
  311. Str : String;
  312. begin
  313. Obj:=Objects[CurIndex];
  314. Str:=Strings[CurIndex];
  315. Delete(Curindex);
  316. InsertObject(NewIndex,Str,Obj);
  317. end;
  318. Procedure TStrings.SaveToFile(const FileName: string);
  319. Var TheStream : TFileStream;
  320. begin
  321. TheStream:=TFileStream.Create(FileName,fmCreate);
  322. SaveToStream(TheStream);
  323. TheStream.Free;
  324. end;
  325. Procedure TStrings.SaveToStream(Stream: TStream);
  326. begin
  327. Stream.WriteAnsiString(Text);
  328. end;
  329. Function GetNextLine (P : Pchar; Var S : String) : Boolean;
  330. Var PS : PChar;
  331. begin
  332. S:='';
  333. Result:=False;
  334. If P^=#0 then exit;
  335. PS:=P;
  336. While (P^<>#10) do P:=P+1;
  337. //!! SetLength (S,P-PS);
  338. //!! System.Move (PS^,Pointer(S)^,P-PS);
  339. If P[1]=#13 then P:=P+1;
  340. P:=P+1; // Point to character after #10(#13)
  341. Result:=True;
  342. end;
  343. Procedure TStrings.SetText(TheText: PChar);
  344. Var S : String;
  345. begin
  346. While GetNextLine (TheText,S) do Add(S);
  347. end;
  348. {****************************************************************************}
  349. {* TStringList *}
  350. {****************************************************************************}
  351. Procedure TStringList.ExchangeItems(Index1, Index2: Integer);
  352. begin
  353. end;
  354. Procedure TStringList.Grow;
  355. begin
  356. end;
  357. Procedure TStringList.QuickSort(L, R: Integer);
  358. begin
  359. end;
  360. Procedure TStringList.InsertItem(Index: Integer; const S: string);
  361. begin
  362. end;
  363. Procedure TStringList.SetSorted(Value: Boolean);
  364. begin
  365. end;
  366. Procedure TStringList.Changed;
  367. begin
  368. end;
  369. Procedure TStringList.Changing;
  370. begin
  371. end;
  372. Function TStringList.Get(Index: Integer): string;
  373. begin
  374. end;
  375. Function TStringList.GetCapacity: Integer;
  376. begin
  377. end;
  378. Function TStringList.GetCount: Integer;
  379. begin
  380. end;
  381. Function TStringList.GetObject(Index: Integer): TObject;
  382. begin
  383. end;
  384. Procedure TStringList.Put(Index: Integer; const S: string);
  385. begin
  386. end;
  387. Procedure TStringList.PutObject(Index: Integer; AObject: TObject);
  388. begin
  389. end;
  390. Procedure TStringList.SetCapacity(NewCapacity: Integer);
  391. begin
  392. end;
  393. Procedure TStringList.SetUpdateState(Updating: Boolean);
  394. begin
  395. end;
  396. destructor TStringList.Destroy;
  397. begin
  398. end;
  399. Function TStringList.Add(const S: string): Integer;
  400. begin
  401. end;
  402. Procedure TStringList.Clear;
  403. begin
  404. end;
  405. Procedure TStringList.Delete(Index: Integer);
  406. begin
  407. end;
  408. Procedure TStringList.Exchange(Index1, Index2: Integer);
  409. begin
  410. end;
  411. Function TStringList.Find(const S: string; var Index: Integer): Boolean;
  412. begin
  413. end;
  414. Function TStringList.IndexOf(const S: string): Integer;
  415. begin
  416. end;
  417. Procedure TStringList.Insert(Index: Integer; const S: string);
  418. begin
  419. end;
  420. Procedure TStringList.Sort;
  421. begin
  422. end;
  423. {
  424. $Log$
  425. Revision 1.3 1998-05-07 14:16:51 michael
  426. + Finished TStrings implementation.
  427. Revision 1.2 1998/05/06 12:58:53 michael
  428. + Initial implementation
  429. Revision 1.1 1998/05/04 14:30:12 michael
  430. * Split file according to Class; implemented dummys for all methods, so unit compiles.
  431. }