RemObjects
                        Software Gears code

ShineOn

Sign in or create your account | Project List | Help

ShineOn Commit Details

Date:2009-10-24 14:10:34 (9 months 6 days ago)
Author:Roman Kassebaum
Commit:141
Message:Added new property LineBreak to TStrings and tested it
Files: trunk/Source/ShineOn.RTL/Classes.pas (5 diffs)
trunk/Source/NUnit/TestStrings.pas (1 diff)
trunk/Source/NUnit/NUnit.ShineOn.RTL.oxygene (2 diffs)

Change Details

trunk/Source/ShineOn.RTL/Classes.pas
189189    //FStringsAdapter:IStringsAdapter;
190190    FUpdateCount:Int32;
191191    FDelimiter, FQuoteChar:Char;
192    FLineBreak: String;
192193    function GetCommaText:String;
193194    procedure SetCommaText(Value:String);
194195    function GetName(Index:Integer):String;
...... 
242243    property Count: Integer read GetCount;
243244    property Delimiter: Char read FDelimiter write FDelimiter;
244245    property DelimitedText: String read GetDelimitedText write SetDelimitedText;
246    property LineBreak: String read FLineBreak write FLineBreak;
245247    property Names[Index: Integer]: String read GetName;
246248    property Objects[Index: Integer]: Object read GetObject write PutObject;
247249    property QuoteChar: Char read FQuoteChar write FQuoteChar;
...... 
11961198  for i:Int32 := 0 to Count - 1 do
11971199  begin
11981200    S.Append(Strings[i]);
1199    if i <> Count -1 then
1200      S.Append(System.Environment.NewLine);
1201    if (i <> Count -1) and not string.IsNullOrEmpty(FLineBreak) then
1202      S.Append(FLineBreak);
12011203  end;
12021204  Result := S.ToString;
12031205end;
...... 
12091211end;
12101212
12111213procedure TStrings.SetTextStr(Value: String);
1212var S:String;
1214var
1215  iPos: Integer;
1216  iStart: Integer;
1217  iLength: Integer;
12131218begin
1214  Clear;
1215  if Value <> nil then
1216    with T:System.IO.StringReader := new System.IO.StringReader(Value) do
1219  BeginUpdate;
1220  try
1221    Clear;
1222    if String.IsNullOrEmpty(Value) then
1223      Exit;
1224    if String.IsNullOrEmpty(FLineBreak) then
12171225    begin
1218      while true do
1219      begin
1220        S := T.ReadLine;
1221        if S = nil then
1222          Exit;
1223        Add(S);
1224      end;
1226      Add(Value);
1227      Exit;
12251228    end;
1229    iStart := 0;
1230    iLength := FLineBreak.Length;
1231    iPos := Value.IndexOf(FLineBreak);
1232    while iPos > -1 do
1233    begin
1234      Add(Value.Substring(iStart, iPos - iStart));
1235      iStart := iPos + iLength;
1236      iPos := Value.IndexOf(FLineBreak, iStart);
1237    end;
1238    if iStart <= Value.Length then
1239      Add(Value.Substring(iStart, Value.Length - iStart));
1240  finally
1241    EndUpdate;
1242  end;
12261243end;
12271244
12281245function TStrings.CompareStrings(S1, S2: String): Integer;
...... 
12481265  inherited Create;
12491266  FQuoteChar := '"';
12501267  FDelimiter := ',';
1268  FLineBreak := System.Environment.NewLine;
12511269end;
12521270
12531271function TStrings.Add(S: String): Integer;
trunk/Source/NUnit/TestStrings.pas
1// The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
2// you may not use this file except in compliance with the License. You may obtain a copy of the
3// License at http://www.mozilla.org/MPL/
4//
5// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
6// ANY KIND, either express or implied. See the License for the specificlanguage governing rights and
7// limitations under the License.
8
9namespace NUnit.ShineOn.RTL;
10
11interface
12
13uses
14  Nunit.Framework,
15  ShineOn.RTL;
16
17type
18  [TestFixture]
19  TestStrings = public class(Object)
20  public
21  [Test]
22      method SetTextStr;
23  end;
24
25implementation
26
27{ TestStrings }
28
29method TestStrings.SetTextStr;
30const
31  cLine1: String = 'A';
32  cLine2: String = 'B';
33  cLine3: String = cLine1 + #0 + cLine2;
34var
35  pList: TStringList;
36begin
37  //Nil Text
38  pList := new TStringList();
39  pList.Text := nil;
40  Assert.AreEqual(pList.Count, 0);
41
42  //EmptyText
43  pList := new TStringList();
44  pList.Text := '';
45  Assert.AreEqual(pList.Count, 0);
46
47  //Normal Text
48  pList := new TStringList();
49  pList.Text := cLine1 + System.Environment.NewLine + cLine2;
50  Assert.AreEqual(pList.Count, 2);
51  Assert.AreEqual(pList[0], cLine1);
52  Assert.AreEqual(pList[1], cLine2);
53
54  //Special Text
55  pList := new TStringList();
56  pList.Text := cLine3;
57  Assert.AreEqual(pList.Count, 1);
58  Assert.AreEqual(pList[0], cLine3);
59
60  //No LineBreak
61  pList := new TStringList();
62  pList.LineBreak := nil;
63  pList.Text := cLine1 + System.Environment.NewLine + cLine2;
64  Assert.AreEqual(pList.Count, 1);
65  Assert.AreEqual(pList[0], pList.Text);
66end;
67
68end.
trunk/Source/NUnit/NUnit.ShineOn.RTL.oxygene
2929    </Reference>
3030    <ProjectReference Include="..\ShineOn.RTL\ShineOn.RTL.oxygene">
3131      <Project>{EADE7853-FDBE-4770-B0B2-5FF5FDD2DBF7}</Project>
32      <HintPath>$(Project)\..\bin\ShineOn.Rtl.dll</HintPath>
32      <HintPath>..\bin\ShineOn.Rtl.dll</HintPath>
3333      <Name>ShineOn.RTL</Name>
3434    </ProjectReference>
3535    <Reference Include="System">
...... 
6565    <Compile Include="TestFileStream.pas" />
6666    <Compile Include="TestIniFiles.pas" />
6767    <Compile Include="TestStringRead.pas" />
68    <Compile Include="TestStrings.pas" />
6869    <Compile Include="TestStringWrite.pas" />
6970    <Compile Include="TestStrUtils.pas" />
7071    <Compile Include="TestSystem.pas" />
7172

Archive Download the corresponding diff file

Revision: 141