Skip to content

Commit

Permalink
testing!!
Browse files Browse the repository at this point in the history
  • Loading branch information
LolaLollipop committed Nov 16, 2023
1 parent 3c13316 commit da071e8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 70 deletions.
4 changes: 1 addition & 3 deletions RueI/RueI/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/// </summary>
public static class Constants
{

/// <summary>
/// Gets the default height if a line-height is not provided.
/// </summary>
Expand All @@ -28,7 +27,7 @@ public static class Constants
public const float CAPSTOSMALLCAPS = 0.8f;

/// <summary>
/// Gets the pixel amount applied to turn something into a pixel.
/// Gets the pixel increase for bold characters.
/// </summary>
public const float BOLDINCREASE = 2.45f * BETTER;

Expand Down Expand Up @@ -100,7 +99,6 @@ public static class Constants
public static Parser DefaultParser { get; } = new ParserBuilder()
.AddTag<SizeTag>()
.AddTag<LineHeightTag>()
.AddTag<SpriteTag>()
.AddTag<CloseSizeTag>()
.Build();

Expand Down
11 changes: 6 additions & 5 deletions RueI/RueI/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net.Mime;
using System.Text;
using MEC;
using NorthwoodLib.Pools;
Expand Down Expand Up @@ -91,7 +92,7 @@ void FailTagMatch() // not a tag, unload buffer
AddCharacter(context, delimiter.Value);
delimiter = null;
}
Timing.Instance

tagBuffer.Clear();
paramBuffer.Clear();

Expand Down Expand Up @@ -120,7 +121,7 @@ void FailTagMatch() // not a tag, unload buffer
}
else if (currentState == ParserState.DescendingTag)
{
if ((ch > '\u0060' && ch < '\u007B') || ch == '-') // descend deeper into node
if ((ch > '\u0060' && ch < '\u007B') || ch == '-' || ch == '\\') // descend deeper into node
{
if (tagBufferSize > Constants.MAXTAGNAMESIZE)
{
Expand Down Expand Up @@ -173,9 +174,7 @@ void FailTagMatch() // not a tag, unload buffer
{
if (ch == '>')
{
#pragma warning disable
if (currentTag.HandleTag(context, delimiter.Value, paramBuffer.ToString()))
#pragma warning restore
if (currentTag!.HandleTag(context, paramBuffer.ToString()))
{
tagBuffer.Clear();
paramBuffer.Clear();
Expand All @@ -197,6 +196,8 @@ void FailTagMatch() // not a tag, unload buffer
AddCharacter(context, ch);
} // foreach

context.ApplyClosingTags();

StringBuilderPool.Shared.Return(tagBuffer);
StringBuilderPool.Shared.Return(paramBuffer);
return new ParsedData(context.ResultBuilder.ToString(), context.NewOffset);
Expand Down
17 changes: 14 additions & 3 deletions RueI/RueI/Parsing/ParserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ParserContext : TextInfo, IDisposable
/// <summary>
/// Gets a list of tags that the parser should add at the end.
/// </summary>
private List<RichTextTag> endingTags = new(10);
private readonly List<NoParamsTag> endingTags = new(10);

/// <summary>
/// Gets the end result string builder.
Expand Down Expand Up @@ -65,7 +65,7 @@ public class ParserContext : TextInfo, IDisposable
/// </summary>
/// <typeparam name="T">The type of the <see cref="RichTextTag"/> to be added as an ending tag (as a <see cref="SharedTag{Tags}"/>).</typeparam>
public void AddEndingTag<T>()
where T : RichTextTag, new()
where T : NoParamsTag, new()
{
endingTags.Add(SharedTag<T>.Singleton);
}
Expand All @@ -75,11 +75,22 @@ public void AddEndingTag<T>()
/// </summary>
/// <typeparam name="T">The type of the <see cref="RichTextTag"/> to be removed from the ending tags (as a <see cref="SharedTag{Tags}"/>).</typeparam>
public void RemoveEndingTag<T>()
where T : RichTextTag, new()
where T : NoParamsTag, new()
{
endingTags.Remove(SharedTag<T>.Singleton);
}

/// <summary>
/// Applies the <see cref="endingTags"/> tags to this <see cref="ParserContext"/>.
/// </summary>
internal void ApplyClosingTags()
{
foreach (NoParamsTag tag in endingTags)
{
tag.HandleTag(this);
}
}

/// <summary>
/// Disposes this ParserContext, returning the string builder to the pool.
/// </summary>
Expand Down
41 changes: 22 additions & 19 deletions RueI/RueI/Parsing/Tags/ConcreteTags/ColorTag.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
namespace RueI.Parsing.Tags.ConcreteTags
{
using RueI.Enums;
using RueI.Records;
using UnityEngine.Assertions;

/// <summary>
/// Provides a way to handle size tags.
/// Provides a way to handle color tags.
/// </summary>
public class SizeTag : MeasurementTag
public class ColorTag : RichTextTag
{
private const string TAGFORMAT = "<size={0}>";
/// <inheritdoc/>
public override string[] Names { get; } = { "color" };

/// <inheritdoc/>
public override string[] Names { get; } = { "size" };
public override TagStyle TagStyle { get; } = TagStyle.ValueParam;

/// <inheritdoc/>
public override bool HandleTag(ParserContext context, MeasurementInfo info)
public override bool HandleTag(ParserContext context, string param)
{
context.SizeTags.Push(context.Size);
float value = info.Style switch
if (param.StartsWith("#"))
{
MeasurementUnit.Percentage => info.Value / 100 * Constants.DEFAULTSIZE,
MeasurementUnit.Ems => info.Value * Constants.EMSTOPIXELS,
_ => info.Value
};

context.Size = value;
context.CurrentLineHeight = Constants.DEFAULTHEIGHT * (value / Constants.DEFAULTSIZE);
context.ResultBuilder.AppendFormat(TAGFORMAT, value);


if (!Constants.ValidColorSizes.Contains(param.Length - 1))
{
return false;
}
}
else
{
string? unquoted = TagHelpers.ExtractFromQuotations(param);
if (unquoted == null || !Constants.Colors.Contains(unquoted))
{
return false;
}
}

context.ResultBuilder.Append($"<color={param}>");
context.AddEndingTag<CloseSizeTag>();
return true;
}
}
Expand Down
40 changes: 0 additions & 40 deletions RueI/RueI/Parsing/Tags/ConcreteTags/SpriteTag.cs

This file was deleted.

12 changes: 12 additions & 0 deletions RueI/docs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RueI
{
class Documentation
{
}
}

0 comments on commit da071e8

Please sign in to comment.