mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-11 07:48:36 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
50 lines
1.0 KiB
C#
50 lines
1.0 KiB
C#
namespace Sandbox.UI;
|
|
|
|
internal static partial class StyleParser
|
|
{
|
|
/// <summary>
|
|
/// Parse the styles as you would if they were passed in an style="width: 100px" attribute
|
|
/// </summary>
|
|
internal static void ParseStyles( ref Parse p, Styles style, bool parentheses = false )
|
|
{
|
|
if ( parentheses )
|
|
{
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
if ( !p.TrySkip( "{" ) )
|
|
throw new Exception( $"Expected {{ {p.FileAndLine}" );
|
|
}
|
|
|
|
while ( !p.IsEnd )
|
|
{
|
|
p = p.SkipWhitespaceAndNewlines( ":;" );
|
|
|
|
if ( p.Current == ':' )
|
|
throw new System.Exception( "Parsing error - unexpected ':' at " );
|
|
|
|
var name = p.ReadUntil( ":" );
|
|
if ( name == null )
|
|
break;
|
|
|
|
p.Pointer++;
|
|
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
|
|
var value = p.ReadUntilOrEnd( ";" );
|
|
if ( value == null )
|
|
break;
|
|
|
|
p.Pointer++;
|
|
|
|
if ( !style.Set( name, value ) )
|
|
{
|
|
throw new Exception( $"Unknown Property: {name} / {value} {p.FileAndLine}" );
|
|
}
|
|
|
|
p = p.SkipWhitespaceAndNewlines();
|
|
|
|
if ( parentheses && p.TrySkip( "}" ) )
|
|
break;
|
|
}
|
|
}
|
|
}
|