Skip to content

Make CharacterReader internal. #19123

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

Merged
merged 3 commits into from
Jun 26, 2025
Merged
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
24 changes: 24 additions & 0 deletions api/Avalonia.nupkg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@
<Left>baseline/netstandard2.0/Avalonia.Base.dll</Left>
<Right>target/netstandard2.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Utilities.CharacterReader</Target>
<Left>baseline/netstandard2.0/Avalonia.Base.dll</Left>
<Right>target/netstandard2.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Utilities.IdentifierParser</Target>
<Left>baseline/netstandard2.0/Avalonia.Base.dll</Left>
<Right>target/netstandard2.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Utilities.KeywordParser</Target>
<Left>baseline/netstandard2.0/Avalonia.Base.dll</Left>
<Right>target/netstandard2.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Utilities.StyleClassParser</Target>
<Left>baseline/netstandard2.0/Avalonia.Base.dll</Left>
<Right>target/netstandard2.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Avalonia.Diagnostics.AppliedStyle.get_HasActivator</Target>
Expand Down
6 changes: 1 addition & 5 deletions src/Avalonia.Base/Utilities/CharacterReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace Avalonia.Utilities
{
// TODO12: This should not be public
#if !BUILDTASK
public
#endif
ref struct CharacterReader
internal ref struct CharacterReader
{
private ReadOnlySpan<char> _s;

Expand Down
5 changes: 1 addition & 4 deletions src/Avalonia.Base/Utilities/IdentifierParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

namespace Avalonia.Utilities
{
#if !BUILDTASK
public
#endif
static class IdentifierParser
internal static class IdentifierParser
{
public static ReadOnlySpan<char> ParseIdentifier(this
#if NET7SDK
Expand Down
5 changes: 1 addition & 4 deletions src/Avalonia.Base/Utilities/KeywordParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace Avalonia.Utilities
{
#if !BUILDTASK
public
#endif
static class KeywordParser
internal static class KeywordParser
{
public static bool CheckKeyword(this ref CharacterReader r, string keyword)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Avalonia.Base/Utilities/StyleClassParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

namespace Avalonia.Utilities
{
#if !BUILDTASK
public
#endif
static class StyleClassParser
internal static class StyleClassParser
{
public static ReadOnlySpan<char> ParseStyleClass(this ref CharacterReader r)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode nod

if (binding.Arguments.Count > 0 && binding.Arguments[0] is XamlAstTextNode bindingPathText)
{
var reader = new CharacterReader(bindingPathText.Text.AsSpan());
var (nodes, _) = BindingExpressionGrammar.Parse(ref reader);
var (nodes, _) = BindingExpressionGrammar.Parse(bindingPathText.Text);

if (convertedNode != null)
{
Expand All @@ -48,8 +47,7 @@ public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode nod

if (bindingPathAssignment != null && bindingPathAssignment.Values[0] is XamlAstTextNode pathValue)
{
var reader = new CharacterReader(pathValue.Text.AsSpan());
var (nodes, _) = BindingExpressionGrammar.Parse(ref reader);
var (nodes, _) = BindingExpressionGrammar.Parse(pathValue.Text);

if (nodes.Count == 1 && nodes[0] is BindingExpressionGrammar.EmptyExpressionNode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static IXamlIlAvaloniaPropertyNode CreateNode(AstTransformationContext co
{
XamlAstNamePropertyReference forgedReference;

var parsedPropertyName = PropertyParser.Parse(new CharacterReader(propertyName.AsSpan()));
var parsedPropertyName = PropertyParser.Parse(propertyName);
if(parsedPropertyName.owner == null)
forgedReference = new XamlAstNamePropertyReference(lineInfo, selectorTypeReference,
propertyName, selectorTypeReference);
Expand Down
9 changes: 8 additions & 1 deletion src/Markup/Avalonia.Markup.Xaml/Parsers/PropertyParser.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using Avalonia.Data.Core;
using System;
using Avalonia.Data.Core;
using Avalonia.Utilities;

namespace Avalonia.Markup.Xaml.Parsers
{
internal class PropertyParser
{
public static (string? ns, string? owner, string name) Parse(string text)
{
var r = new CharacterReader(text.AsSpan());
return Parse(r);
}

public static (string? ns, string? owner, string name) Parse(CharacterReader r)
{
if (r.End)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using Avalonia.Data.Core;
using Avalonia.Utilities;
using System;
using System.Collections.Generic;
using Avalonia.Data.Core;
using Avalonia.Utilities;

namespace Avalonia.Markup.Parsers
{
Expand All @@ -18,6 +18,12 @@ internal static class BindingExpressionGrammar
{
private static readonly List<INode> s_pool = new();

public static (List<INode> Nodes, SourceMode Mode) Parse(string text)
{
var r = new CharacterReader(text.AsSpan());
return Parse(ref r);
}

public static (List<INode> Nodes, SourceMode Mode) Parse(ref CharacterReader r)
{
var result = new List<INode>();
Expand Down
Loading