Skip to content

Commit

Permalink
For inMem SQLLike implementation.#27
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 7, 2024
1 parent c7707b0 commit b3cf74e
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions Source/BoldOclSymbolImplementations.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2990,7 +2990,7 @@ procedure TBOS_Attributes.Evaluate(const Params: TBoldOclSymbolParameters);
begin
ClassInfo := Params.values[0] as TBoldClassTypeInfo;
Name := help.CreateNewMember(Help.StringType) as TBAString;
for i := 0 to ClassInfo.AllMembers.Count - 1 do
for i := 0 to ClassInfo.AllMembersCount - 1 do
begin
MemberRTInfo := ClassInfo.AllMembers[i];
if MemberRTInfo.IsAttribute then
Expand All @@ -3016,7 +3016,7 @@ procedure TBOS_AssociationEnds.Evaluate(const Params: TBoldOclSymbolParameters);
begin
ClassInfo := Params.values[0] as TBoldClassTypeInfo;
Name := help.CreateNewMember(Help.StringType) as TBAString;
for i := 0 to ClassInfo.AllMembers.Count - 1 do
for i := 0 to ClassInfo.AllMembersCount - 1 do
begin
MemberRTInfo := ClassInfo.AllMembers[i];
if MemberRTInfo.IsRole then
Expand Down Expand Up @@ -3110,10 +3110,38 @@ procedure TBOS_AllSubClasses.Evaluate(const Params: TBoldOclSymbolParameters);
end;
end;

function SQLLikeToRegEx(const AExpression: string): string;
var
l: integer;
Starts, Ends: boolean;
begin
l := Length(AExpression);
if l > 1 then
begin
Starts := Copy(AExpression, 1, 1) = '%';
Ends := Copy(AExpression, l, 1) = '%';
if Starts and Ends then
result := '^.*' + Copy(AExpression, 2, l-2) + '.*$'
else
if Starts then
result := '^.*' + Copy(AExpression, 2, MaxInt) + '$'
else
if Ends then
result := '^' + Copy(AExpression, 1, l-1) + '.*$'
else
result := '^' + Copy(AExpression, 1, l) + '$'
end
else
if AExpression = '%' then
result := '.*'
else
result := '^' + AExpression + '$'
end;

function EscapeRegEx(const ASource: string): string;
begin
result := StringReplace(ASource, '%', '', [rfReplaceAll]);
result := TPerlRegEx.EscapeRegExChars(result);
result := TPerlRegEx.EscapeRegExChars(ASource);
result := SQLLikeToRegEx(result);
end;

procedure TBOS_SQLLike.Evaluate(const Params: TBoldOclSymbolParameters);
Expand Down Expand Up @@ -4076,4 +4104,4 @@ initialization
finalization
FreeAndNil(G_OCLOperations);

end.
end.

0 comments on commit b3cf74e

Please sign in to comment.