diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs index d2d1f6aa42b..151db3ae919 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/RtxtParser.cs @@ -5,35 +5,35 @@ using System.Text.RegularExpressions; using Microsoft.Android.Build.Tasks; using Microsoft.Build.Utilities; +using System.Runtime.InteropServices; namespace Xamarin.Android.Tasks { - public enum RType { + public enum RType : byte { Integer, + Integer_Styleable, Array, } - public enum ResourceType { + public enum ResourceType : byte { System, Custom, } + [StructLayout(LayoutKind.Sequential)] public struct R : IComparable { - public RType Type; public int Id; + public RType Type; + public ResourceType ResourceType; public int [] Ids; public string Identifier; public string ResourceTypeName; - public ResourceType ResourceType; - public string Key => $"{ResourceTypeName}:{Identifier}"; public override string ToString () { - if (Type == RType.Integer) { - if (ResourceTypeName == "styleable") - return $"int {ResourceTypeName} {Identifier} {Id}"; - return $"int {ResourceTypeName} {Identifier} 0x{Id.ToString ("x8")}"; + if (Type != RType.Array) { + return $"int {ResourceTypeName} {Identifier} { (Type == RType.Integer ? $"0x{Id.ToString ("x8")}" : "{Id}")}"; } return $"int[] {ResourceTypeName} {Identifier} {{ {String.Join (", ", Ids.Select (x => $"0x{x.ToString ("x8")}"))} }}"; } @@ -104,10 +104,13 @@ public IEnumerable Parse (string file, TaskLoggingHelper logger, Dictionary result) + void ProcessRtxtFile (string file, List result) { + var lines = File.ReadAllLines (file); + result.Capacity = lines.Length; + int lineNumber = 0; - foreach (var line in File.ReadLines (file)) { + foreach (var line in lines) { lineNumber++; var items = line.Split (EmptyChar, 4); if (items.Length < 4) { @@ -119,11 +122,13 @@ void ProcessRtxtFile (string file, IList result) continue; } int value = items [1] != "styleable" ? Convert.ToInt32 (items [3].Trim (), 16) : -1; + var type = items [1] != "styleable" ? RType.Integer : RType.Integer_Styleable; string itemName = ResourceIdentifier.GetResourceName(ResourceParser.GetNestedTypeName (items [1]), items [2], map, log); if (knownTypes.Contains (items [1])) { if (items [1] != "styleable") { result.Add (new R () { ResourceTypeName = items [1], + Type =type, Identifier = itemName, Id = value, }); @@ -133,6 +138,7 @@ void ProcessRtxtFile (string file, IList result) case "int": result.Add (new R () { ResourceTypeName = items [1], + Type = type, Identifier = itemName, Id = Convert.ToInt32 (items [3].Trim (), 10), });