Skip to content

Commit

Permalink
fixed OnlyChar()
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Aug 16, 2023
1 parent 0e1a2fb commit e569de3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/core/mormot.core.unicode.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ function TrimChar(const text: RawUtf8; const exclude: TSynAnsicharSet): RawUtf8;

/// returns the supplied text content, without any other char than specified
// - specify a custom char set to be included, e.g. as ['A'..'Z']
function OnlyChar(const text: RawUtf8; only: TSynAnsicharSet): RawUtf8;
function OnlyChar(const text: RawUtf8; const only: TSynAnsicharSet): RawUtf8;

/// returns the supplied text content, without any control char
// - here control chars have an ASCII code in [#0 .. ' '], i.e. text[] <= ' '
Expand Down Expand Up @@ -7545,13 +7545,14 @@ function TrimChar(const text: RawUtf8; const exclude: TSynAnsicharSet): RawUtf8;
result := text; // no exclude char found
end;

function OnlyChar(const text: RawUtf8; only: TSynAnsicharSet): RawUtf8;
function OnlyChar(const text: RawUtf8; const only: TSynAnsicharSet): RawUtf8;
var
i: PtrInt;
begin
for i := 0 to SizeOf(only) do
PByteArray(@only)[i] := not PByteArray(@only)[i]; // reverse bits
result := TrimChar(text, only);
exclude: array[0..(SizeOf(only) shr POINTERSHR) - 1] of PtrInt;
begin // reverse bits in local stack copy before calling TrimChar()
for i := 0 to (SizeOf(only) shr POINTERSHR) - 1 do
exclude[i] := not PPtrIntArray(@only)[i];
result := TrimChar(text, TSynAnsicharSet(exclude));
end;

procedure FillZero(var secret: RawByteString);
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'2.1.5753'
'2.1.5754'

0 comments on commit e569de3

Please sign in to comment.