From: Warren P. <wp...@us...> - 2003-07-29 21:55:09
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1:/tmp/cvs-serv12166/JVCL3/run Modified Files: JvCsvData.pas JvCsvParse.pas Log Message: Nasty string overflow crash fixed, new Sort, Indexing and user data, user tag (pointer, integer of user data per each Record in csv data set). Changes to JvCsvParse.pas to allow better parsing of strings with enquoting Index: JvCsvData.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvCsvData.pas,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JvCsvData.pas 23 Jun 2003 12:33:03 -0000 1.4 --- JvCsvData.pas 29 Jul 2003 19:03:43 -0000 1.5 *************** *** 1,3 **** - {$I JVCL.INC} unit JvCsvData; --- 1,2 ---- *************** *** 12,20 **** the specific language governing rights and limitations under the License. ! The Original Code is by Warren Postma. [...5805 lines suppressed...] *************** *** 3137,3144 **** // extension number to use. if FileExists(RemoveFile) then ! DeleteFile(RemoveFile); ! Windows.CopyFile(PChar(filename), PChar(BackupFilename), false); ! Result := true; end; --- 3316,3323 ---- // extension number to use. if FileExists(RemoveFile) then ! DeleteFile(RemoveFile); ! CopyFile(PChar(filename),PChar(BackupFilename),false); ! result := true; end; Index: JvCsvParse.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvCsvParse.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JvCsvParse.pas 19 Jun 2003 03:38:34 -0000 1.1 --- JvCsvParse.pas 29 Jul 2003 19:03:43 -0000 1.2 *************** *** 19,23 **** Contributor(s): Warren Postma (war...@ho...) ! Last Modified: 2003-04-26 You may retrieve the latest version of this file at the Project JEDI's JVCL home page, --- 19,24 ---- Contributor(s): Warren Postma (war...@ho...) ! Last Modified: 2003-07-29 by Warren Postma - New features (Sorting, Indexing, UserData) ! Changed StrSplit Function (has one new parameter). You may retrieve the latest version of this file at the Project JEDI's JVCL home page, *************** *** 58,62 **** {new 2003} ! function StrSplit( const inString:String; const splitChar:Char; var OutStrings:Array of String;MaxSplit:Integer):Integer; // New function! Split a string into an array of strings. { circa 1998-2001 classic functions } --- 59,64 ---- {new 2003} ! function StrSplit( const inString:String; const splitChar,quoteChar:Char; var OutStrings:Array of String;MaxSplit:Integer):Integer; ! { circa 1998-2001 classic functions } *************** *** 69,72 **** --- 71,75 ---- function HexToAscii(s:string):string; function AsciiToHex(s:string):string; + function StripQuotes( s1:String) : String; { TStringList helper functions } *************** *** 82,86 **** function HexPcharToInt(s1 : PChar) : Integer; function ValidStringLiteral(s1:PChar) : Boolean; ! function StripQuotes( s1:PChar ) : String; function ValidIdentifier( s1: PChar ) : Boolean; function EndChar( x : char ) : Boolean; --- 85,90 ---- function HexPcharToInt(s1 : PChar) : Integer; function ValidStringLiteral(s1:PChar) : Boolean; ! function StripPCharQuotes( s1:PChar ) : String; ! function ValidIdentifier( s1: PChar ) : Boolean; function EndChar( x : char ) : Boolean; *************** *** 244,253 **** { Strip quotes and return as a real Delphi String } ! function StripQuotes( s1:PChar ) : String; var ! tempbuf: array [0..128] of char; begin if ValidStringLiteral(s1) then begin ! StrLCopy(tempbuf,s1+1,strlen(s1)-2 ); end; result := String(tempbuf); --- 248,271 ---- { Strip quotes and return as a real Delphi String } ! function StripQuotes( s1:String ) : String; ! begin ! if ValidStringLiteral(PChar(s1)) then ! result := Copy(s1,2,Length(s1)-2) ! else ! result := s1; ! end; ! ! ! // This function is limited to 1 to 254 characters: ! function StripPcharQuotes( s1:PChar ) : String; var ! tempbuf: array [0..256] of char; ! l:Integer; begin + l := strlen(s1); + if (l>255) then + l := 255; if ValidStringLiteral(s1) then begin ! StrLCopy(tempbuf,s1+1,l-2 ); end; result := String(tempbuf); *************** *** 800,808 **** // if it starts at element 1, then you'll get exceptions XXX //------------------------------------------------------------------------------------------ ! function StrSplit( const inString:String; const splitChar:Char; var OutStrings:Array of String;MaxSplit:Integer):Integer; var t,Len,SplitCounter:Integer; Ch:Char; begin Len := Length(inString); for t := Low(OutStrings) to High(OutStrings) do begin // clear array that is passed in! --- 818,828 ---- // if it starts at element 1, then you'll get exceptions XXX //------------------------------------------------------------------------------------------ ! function StrSplit( const inString:String; const splitChar,quoteChar:Char; var OutStrings:Array of String;MaxSplit:Integer):Integer; var t,Len,SplitCounter:Integer; Ch:Char; + inQuotes:Boolean; begin + inQuotes := false; Len := Length(inString); for t := Low(OutStrings) to High(OutStrings) do begin // clear array that is passed in! *************** *** 814,818 **** for t := 1 to Len do begin Ch := inString[t]; ! if (Ch = splitChar) then begin Inc(SplitCounter); if SplitCounter>MaxSplit then begin --- 834,838 ---- for t := 1 to Len do begin Ch := inString[t]; ! if (Ch = splitChar) and (not inQuotes) then begin Inc(SplitCounter); if SplitCounter>MaxSplit then begin *************** *** 820,825 **** exit; end; ! end else OutStrings[SplitCounter] := OutStrings[SplitCounter] + ch; end; Inc(SplitCounter); --- 840,848 ---- exit; end; ! end else begin OutStrings[SplitCounter] := OutStrings[SplitCounter] + ch; + if (ch = quoteChar) then + inQuotes := not inQuotes; + end; end; Inc(SplitCounter); |