|
From: Micha N. <md...@us...> - 2004-08-19 09:58:15
|
Update of /cvsroot/tdbf/tdbf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31585 Modified Files: dbf.pas dbf_parser.pas history.txt Log Message: added: partial matching in expressions for filters Index: history.txt =================================================================== RCS file: /cvsroot/tdbf/tdbf/history.txt,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** history.txt 18 Aug 2004 20:00:42 -0000 1.62 --- history.txt 19 Aug 2004 09:58:05 -0000 1.63 *************** *** 50,53 **** --- 50,54 ---- - added: multi-user and insert aware ranges (req by ralf) - chngd: made all filenames lowercase to ease usage on *nix + - added: partial matching in expressions for filters Index: dbf.pas =================================================================== RCS file: /cvsroot/tdbf/tdbf/dbf.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dbf.pas 18 Aug 2004 20:00:40 -0000 1.1 --- dbf.pas 19 Aug 2004 09:58:05 -0000 1.2 *************** *** 2067,2070 **** --- 2067,2071 ---- begin // set options + FParser.PartialMatch := not (foNoPartialCompare in FilterOptions); FParser.CaseInsensitive := foCaseInsensitive in FilterOptions; // parse expression Index: dbf_parser.pas =================================================================== RCS file: /cvsroot/tdbf/tdbf/dbf_parser.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dbf_parser.pas 18 Aug 2004 20:00:41 -0000 1.1 --- dbf_parser.pas 19 Aug 2004 09:58:05 -0000 1.2 *************** *** 32,35 **** --- 32,36 ---- FCaseInsensitive: Boolean; FRawStringFields: Boolean; + FPartialMatch: boolean; protected *************** *** 44,47 **** --- 45,49 ---- procedure SetCaseInsensitive(NewInsensitive: Boolean); procedure SetRawStringFields(NewRawFields: Boolean); + procedure SetPartialMatch(NewPartialMatch: boolean); public constructor Create(ADbfFile: Pointer); *************** *** 59,62 **** --- 61,65 ---- property CaseInsensitive: Boolean read FCaseInsensitive write SetCaseInsensitive; property RawStringFields: Boolean read FRawStringFields write SetRawStringFields; + property PartialMatch: boolean read FPartialMatch write SetPartialMatch; end; *************** *** 631,634 **** --- 634,675 ---- end; + procedure FuncStrIP_EQ(Param: PExpressionRec); + var + arg0len, arg1len: integer; + match: boolean; + str0, str1: string; + begin + with Param^ do + begin + arg1len := StrLen(Args[1]); + if Args[1][0] = '*' then + begin + if Args[1][arg1len-1] = '*' then + begin + str0 := StrUpper(Args[0]); + str1 := StrUpper(Args[1]+1); + setlength(str1, arg1len-2); + match := AnsiPos(str0, str1) = 0; + end else begin + arg0len := StrLen(Args[0]); + // at least length without asterisk + match := arg0len >= arg1len - 1; + if match then + match := AnsiStrLIComp(Args[0]+(arg0len-arg1len+1), Args[1]+1, arg1len-1) = 0; + end; + end else + if Args[1][arg1len-1] = '*' then + begin + arg0len := StrLen(Args[0]); + match := arg1len >= arg0len - 1; + if match then + match := AnsiStrLIComp(Args[0], Args[1], arg1len-1) = 0; + end else begin + match := AnsiStrIComp(Args[0], Args[1]) = 0; + end; + Res.MemoryPos^^ := Char(match); + end; + end; + procedure FuncStrI_NEQ(Param: PExpressionRec); begin *************** *** 661,664 **** --- 702,741 ---- end; + procedure FuncStrP_EQ(Param: PExpressionRec); + var + arg0len, arg1len: integer; + match: boolean; + begin + with Param^ do + begin + arg1len := StrLen(Args[1]); + if Args[1][0] = '*' then + begin + if Args[1][arg1len-1] = '*' then + begin + Args[1][arg1len-1] := #0; + match := AnsiStrPos(Args[0], Args[1]+1) <> nil; + Args[1][arg1len-1] := '*'; + end else begin + arg0len := StrLen(Args[0]); + // at least length without asterisk + match := arg0len >= arg1len - 1; + if match then + match := AnsiStrLComp(Args[0]+(arg0len-arg1len+1), Args[1]+1, arg1len-1) = 0; + end; + end else + if Args[1][arg1len-1] = '*' then + begin + arg0len := StrLen(Args[0]); + match := arg1len >= arg0len - 1; + if match then + match := AnsiStrLComp(Args[0], Args[1], arg1len-1) = 0; + end else begin + match := AnsiStrComp(Args[0], Args[1]) = 0; + end; + Res.MemoryPos^^ := Char(match); + end; + end; + procedure FuncStr_EQ(Param: PExpressionRec); begin *************** *** 1046,1051 **** var ! DbfWordsSensList, DbfWordsInsensList: TExpressList; ! DbfWordsAllList: TExpressList; constructor TDbfParser.Create(ADbfFile: Pointer); --- 1123,1130 ---- var ! DbfWordsSensGeneralList, DbfWordsInsensGeneralList: TExpressList; ! DbfWordsSensPartialList, DbfWordsInsensPartialList: TExpressList; ! DbfWordsSensNoPartialList, DbfWordsInsensNoPartialList: TExpressList; ! DbfWordsGeneralList: TExpressList; constructor TDbfParser.Create(ADbfFile: Pointer); *************** *** 1086,1089 **** --- 1165,1180 ---- end; + procedure TDbfParser.SetPartialMatch(NewPartialMatch: boolean); + begin + if FPartialMatch <> NewPartialMatch then + begin + // refill function list + FPartialMatch := NewPartialMatch; + FillExpressList; + if Length(Expression) > 0 then + ParseExpression(Expression); + end; + end; + procedure TDbfParser.SetRawStringFields(NewRawFields: Boolean); begin *************** *** 1100,1108 **** begin FWordsList.FreeAll; if FCaseInsensitive then begin ! FWordsList.AddList(DbfWordsInsensList, 0, DbfWordsInsensList.Count - 1); end else begin ! FWordsList.AddList(DbfWordsSensList, 0, DbfWordsSensList.Count - 1); end; end; --- 1191,1212 ---- begin FWordsList.FreeAll; + FWordsList.AddList(DbfWordsGeneralList, 0, DbfWordsGeneralList.Count - 1); if FCaseInsensitive then begin ! FWordsList.AddList(DbfWordsInsensGeneralList, 0, DbfWordsInsensGeneralList.Count - 1); ! if FPartialMatch then ! begin ! FWordsList.AddList(DbfWordsInsensPartialList, 0, DbfWordsInsensPartialList.Count - 1); ! end else begin ! FWordsList.AddList(DbfWordsInsensNoPartialList, 0, DbfWordsInsensNoPartialList.Count - 1); ! end; end else begin ! FWordsList.AddList(DbfWordsSensGeneralList, 0, DbfWordsSensGeneralList.Count - 1); ! if FPartialMatch then ! begin ! FWordsList.AddList(DbfWordsSensPartialList, 0, DbfWordsSensPartialList.Count - 1); ! end else begin ! FWordsList.AddList(DbfWordsSensNoPartialList, 0, DbfWordsSensNoPartialList.Count - 1); ! end; end; end; *************** *** 1274,1282 **** initialization ! DbfWordsSensList := TExpressList.Create; ! DbfWordsInsensList := TExpressList.Create; ! DbfWordsAllList := TExpressList.Create; ! with DbfWordsAllList do begin // basic function functionality --- 1378,1390 ---- initialization ! DbfWordsGeneralList := TExpressList.Create; ! DbfWordsInsensGeneralList := TExpressList.Create; ! DbfWordsInsensNoPartialList := TExpressList.Create; ! DbfWordsInsensPartialList := TExpressList.Create; ! DbfWordsSensGeneralList := TExpressList.Create; ! DbfWordsSensNoPartialList := TExpressList.Create; ! DbfWordsSensPartialList := TExpressList.Create; ! with DbfWordsGeneralList do begin // basic function functionality *************** *** 1369,1376 **** end; ! with DbfWordsInsensList do begin - AddList(DbfWordsAllList, 0, DbfWordsAllList.Count - 1); - Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStrI_EQ , 80)); Add(TFunction.CreateOper('<', 'SS', etBoolean, FuncStrI_LT , 80)); Add(TFunction.CreateOper('>', 'SS', etBoolean, FuncStrI_GT , 80)); --- 1477,1482 ---- end; ! with DbfWordsInsensGeneralList do begin Add(TFunction.CreateOper('<', 'SS', etBoolean, FuncStrI_LT , 80)); Add(TFunction.CreateOper('>', 'SS', etBoolean, FuncStrI_GT , 80)); *************** *** 1380,1387 **** end; ! with DbfWordsSensList do begin - AddList(DbfWordsAllList, 0, DbfWordsAllList.Count - 1); - Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStr_EQ , 80)); Add(TFunction.CreateOper('<', 'SS', etBoolean, FuncStr_LT , 80)); Add(TFunction.CreateOper('>', 'SS', etBoolean, FuncStr_GT , 80)); --- 1486,1497 ---- end; ! with DbfWordsInsensNoPartialList do ! Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStrI_EQ , 80)); ! ! with DbfWordsInsensPartialList do ! Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStrIP_EQ, 80)); ! ! with DbfWordsSensGeneralList do begin Add(TFunction.CreateOper('<', 'SS', etBoolean, FuncStr_LT , 80)); Add(TFunction.CreateOper('>', 'SS', etBoolean, FuncStr_GT , 80)); *************** *** 1390,1399 **** Add(TFunction.CreateOper('<>','SS', etBoolean, FuncStr_NEQ, 80)); end; finalization ! DbfWordsAllList.Free; ! DbfWordsInsensList.Free; ! DbfWordsSensList.Free; end. --- 1500,1519 ---- Add(TFunction.CreateOper('<>','SS', etBoolean, FuncStr_NEQ, 80)); end; + + with DbfWordsSensNoPartialList do + Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStr_EQ , 80)); + + with DbfWordsSensPartialList do + Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStrP_EQ , 80)); finalization ! DbfWordsGeneralList.Free; ! DbfWordsInsensGeneralList.Free; ! DbfWordsInsensNoPartialList.Free; ! DbfWordsInsensPartialList.Free; ! DbfWordsSensGeneralList.Free; ! DbfWordsSensNoPartialList.Free; ! DbfWordsSensPartialList.Free; end. |