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

Allow Append()ing normal ShortStrings (length ≦ 255) to Ropes, switch DOM implementation to using that, and use that for generating reference links #157

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/html/dom.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ procedure TElement.SetAttribute(const Name: UTF8String; const Value: UTF8String)
if (Value <> '') then
begin
{$IFOPT C+} AssertStringIsConstant(Value); {$ENDIF}
R.Append(@Value);
R.Append(Value);
end;
FAttributes[Name] := R;
end;
Expand Down Expand Up @@ -1761,7 +1761,7 @@ constructor TCharacterData.Create(const NewData: UTF8String);
if (NewData <> '') then
begin
{$IFOPT C+} AssertStringIsConstant(NewData); {$ENDIF}
FData.Append(@NewData);
FData.Append(NewData);
end;
end;

Expand Down
5 changes: 2 additions & 3 deletions src/lib/ropes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TFixedSizeRopeFragment = record
private
const
FragmentPayloadSize = SizeOf(TFixedSizeRopeFragment);
UTF8InlineSize = FragmentPayloadSize - SizeOf(Byte);
UTF8InlineSize = 30;
CodepointsSize = (FragmentPayloadSize-SizeOf(Byte)) div SizeOf(TUnicodeCodepoint);
type
TUTF8InlineIndex = 0..UTF8InlineSize-1;
Expand Down Expand Up @@ -965,8 +965,7 @@ procedure Rope.Append(const NewString: RopeInternals.TInlineString);
Assert(Length(NewString) <= RopeInternals.UTF8InlineSize, 'Maximum size of short string is ' + IntToStr(RopeInternals.UTF8InlineSize));
if (Length(NewString) > RopeInternals.UTF8InlineSize) then
begin
Writeln('Error: Append() call with string length > UTF8InlineSize: "' + NewString + '"');
Writeln('Call Append() with a string pointer, not a string: Append(@Foo), not Append(Foo)');
Writeln('Error: Operation attempted with string length > UTF8InlineSize: "' + NewString + '..."');
Halt(1);
end;
if ((not Assigned(FLast)) or (FLast^.Kind <> rfUTF8Inline) or (RopeInternals.UTF8InlineSize - FLast^.InlineLength < Length(NewString))) then
Expand Down
22 changes: 8 additions & 14 deletions src/wattsi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1489,8 +1489,10 @@ TCrossReferences = record
// For vReview the title is already taken care of
if (Element.IsIdentity(nsHTML, eTitle)) and (Variant = vSnap) then
begin
Scratch := Default(Rope);
Scratch.Append(@SourceGitSHA);
Element.AppendChild(TText.Create(' (Commit Snapshot '));
Element.AppendChild(TText.Create(SourceGitSHA));
Element.AppendChild(TText.CreateDestructively(Scratch));
Element.AppendChild(TText.Create(')'));
end
else
Expand Down Expand Up @@ -1550,7 +1552,9 @@ TCrossReferences = record
else
if (Element.isIdentity(nsHTML, eA) and (Element.GetAttribute('class').AsString = 'sha-link') and (Variant = vSnap)) then
begin
Element.AppendChild(TText.Create(SourceGitSHA));
Scratch := Default(Rope);
Scratch.Append(@SourceGitSHA);
Element.AppendChild(TText.CreateDestructively(Scratch));
Element.AppendChild(TText.Create(' commit'));
Scratch := Default(Rope);
Scratch.Append(@SourceGitBaseURL);
Expand Down Expand Up @@ -1587,18 +1591,8 @@ TCrossReferences = record
MissingReferences[ReferenceName] := ListNode;

NewLink := ConstructHTMLElement(eA);
Scratch := Default(Rope);
ExtractedData := Element.TextContent.ExtractAll();
Scratch.Append('#refs');
Scratch.AppendDestructively(ExtractedData);
NewLink.SetAttributeDestructively('href', Scratch);

Scratch := Default(Rope);
ExtractedData := Element.TextContent.ExtractAll();
Scratch.Append('[');
Scratch.AppendDestructively(ExtractedData);
Scratch.Append(']');
NewLink.AppendChild(TText.CreateDestructively(Scratch));
NewLink.SetAttribute('href', '#refs' + ReferenceName);
NewLink.AppendChild(TText.Create('[' + ReferenceName + ']'));

(Node.ParentNode as TElement).ReplaceChild(NewLink, Node);
Node.Free();
Expand Down