Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stirng smartcase lower #4

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jcl/source/common/JclAnsiStrings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ procedure StrReverseInPlace(var S: AnsiString);
function StrSingleQuote(const S: AnsiString): AnsiString;
procedure StrSkipChars(var S: PAnsiChar; const Chars: TSysCharSet); overload;
procedure StrSkipChars(const S: AnsiString; var Index: SizeInt; const Chars: TSysCharSet); overload;
function StrSmartCase(const S: AnsiString; Delimiters: TSysCharSet): AnsiString;
function StrSmartCase(const S: AnsiString; Delimiters: TSysCharSet; const LowerRest: boolean = false): AnsiString; overload; // overloading due to JclStrings "string" variants
function StrStringToEscaped(const S: AnsiString): AnsiString;
function StrStripNonNumberChars(const S: AnsiString): AnsiString;
function StrToHex(const Source: AnsiString): AnsiString;
Expand Down Expand Up @@ -2103,7 +2103,7 @@ procedure StrSkipChars(const S: AnsiString; var Index: SizeInt; const Chars: TSy
Inc(Index);
end;

function StrSmartCase(const S: AnsiString; Delimiters: TSysCharSet): AnsiString;
function StrSmartCase(const S: AnsiString; Delimiters: TSysCharSet; const LowerRest: boolean): AnsiString;
var
Source, Dest: PAnsiChar;
Index, Len: SizeInt;
Expand All @@ -2114,7 +2114,7 @@ function StrSmartCase(const S: AnsiString; Delimiters: TSysCharSet): AnsiString;

if S <> '' then
begin
Result := S;
if LowerRest then Result := AnsiLowerCase(S) else Result := S;
UniqueString(Result);

Len := Length(S);
Expand Down
9 changes: 5 additions & 4 deletions jcl/source/common/JclSimpleXml.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,11 @@ procedure TJclSimpleItemHashedList.Notify(Ptr: Pointer; Action: TListNotificatio
begin
if (Action = lnDeleted) and (FNameHash <> nil) then
begin
if FCaseSensitive then
FNameHash.Remove(TJclSimpleItem(Ptr).Name)
else
FNameHash.Remove(UpperCase(TJclSimpleItem(Ptr).Name));
InvalidateHash;
// if FCaseSensitive then
// FNameHash.Remove(TJclSimpleItem(Ptr).Name)
// else
// FNameHash.Remove(UpperCase(TJclSimpleItem(Ptr).Name));
end;
inherited Notify(Ptr, Action);
end;
Expand Down
34 changes: 27 additions & 7 deletions jcl/source/common/JclStringLists.pas
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,25 @@ function TJclStringList.First: string;
function TJclStringList.Join(const ASeparator: string): string;
var
I: Integer;
SB: TStringBuilder; // Implemented by JclStrings, if missed in RTL
begin
Result := '';
for I := 0 to LastIndex - 1 do
Result := Result + Strings[I] + ASeparator;
if Count > 0 then
Result := Result + Last;
if Count <= 0 then
Result := ''
else begin
SB := TStringBuilder.Create(First);
// Warming up ? Worth it ? Capacity: Sum([Strings<i>]) + (Count-1) * [ASeparator] ?
try
for I := 1 to LastIndex do
SB.Append(ASeparator).Append(Strings[i]);
Result := SB.ToString;
finally
SB.Free;
end;
end;
// for I := 0 to LastIndex - 1 do
// Result := Result + Strings[I] + ASeparator;
// if Count > 0 then
// Result := Result + Last;
end;

function TJclStringList.Last: string;
Expand Down Expand Up @@ -682,8 +695,10 @@ function TJclStringList._Release: Integer;
FSelfAsInterface := nil;
end
else
if Result = 0 then
Destroy;
if Result = 0 then begin
pointer(FSelfAsInterface) := nil; // should work in .create / FreeAndNil scenario
Destroy;
end;
end;

{$IFDEF JCL_PCRE}
Expand Down Expand Up @@ -734,6 +749,10 @@ function TJclStringList.MatchRegEx(const S, APattern: string): Boolean;

destructor TJclStringList.Destroy;
begin
if (FRefCount = 1) and (FSelfAsInterface <> nil) then begin
pointer(FSelfAsInterface) := nil;
FRefCount := 0; // should work in .Create -> FreeAndNil scenario
end;
if CanFreeObjects then
FreeObjects(False);
{$IFDEF JCL_PCRE}
Expand Down Expand Up @@ -842,6 +861,7 @@ constructor TJclStringList.Create;
inherited Create;
if QueryInterface(IJclStringList, FSelfAsInterface) <> 0 then
System.Error(reIntfCastError);
// InterlockedDecrement(FRefCount); // should work w/o dangling pointers - bug #6081
end;

function TJclStringList.GetLists(Index: Integer): IJclStringList;
Expand Down
Loading