Update to 1.1.0 #5
6 changed files with 35 additions and 4 deletions
|
@ -92,9 +92,11 @@ class Bofa
|
|||
|
||||
}
|
||||
case .RGB:
|
||||
strBuffer.Append(scope $"rgb {Name} {Value.Rgb[0]:X2)} {Value.Rgb[1]:X2)} {Value.Rgb[2]:X2)}");
|
||||
strBuffer.Append(scope $"rgb {Name} {Value.Rgb[0]:X2} {Value.Rgb[1]:X2} {Value.Rgb[2]:X2}");
|
||||
case .RGBA:
|
||||
strBuffer.Append(scope $"rgb {Name} {Value.Rgba[0]:X2)} {Value.Rgba[1]:X2)} {Value.Rgba[2]:X2)} {Value.Rgba[3]:X2)}");
|
||||
strBuffer.Append(scope $"rgb {Name} {Value.Rgba[0]:X2} {Value.Rgba[1]:X2} {Value.Rgba[2]:X2} {Value.Rgba[3]:X2}");
|
||||
case .Hash:
|
||||
strBuffer.Append(scope $"hash {Name} sha256-{Value.Hash}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -182,6 +182,8 @@ class BofaParser
|
|||
typeName = "RBG";
|
||||
case "rgba":
|
||||
typeName = "RBGA";
|
||||
case "hash":
|
||||
typeName = "Hash";
|
||||
default:
|
||||
toReturn.Type = .Error;
|
||||
return toReturn; //Unsupported type error
|
||||
|
@ -328,6 +330,15 @@ class BofaParser
|
|||
return toReturn;
|
||||
}
|
||||
bofaRes.Value.Rgba = result.Value;
|
||||
case "hash":
|
||||
bofaRes.Type = .Hash;
|
||||
var result = AdditionalParsers.ParseHash(line);
|
||||
if(result case .Err)
|
||||
{
|
||||
toReturn.Type = .Error;
|
||||
return toReturn;
|
||||
}
|
||||
bofaRes.Value.Hash = result.Value;
|
||||
default: //Unknown type
|
||||
toReturn.Type = .Error;
|
||||
return toReturn;
|
||||
|
|
|
@ -2,6 +2,7 @@ namespace Bofa;
|
|||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
[Union]
|
||||
struct BofaValue
|
||||
|
@ -20,4 +21,5 @@ struct BofaValue
|
|||
public List<Bofa> Array;
|
||||
public uint8[3] Rgb;
|
||||
public uint8[4] Rgba;
|
||||
public SHA256Hash Hash;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
namespace Bofa.Parser;
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
class AdditionalParsers
|
||||
{
|
||||
|
@ -40,4 +41,17 @@ class AdditionalParsers
|
|||
return .Ok(toReturn);
|
||||
}
|
||||
|
||||
public static Result<SHA256Hash> ParseHash(StringView pValue)
|
||||
{
|
||||
//We currently dont support more than sha256 as hashing algorithms
|
||||
if(pValue.Contains('-') && !pValue.StartsWith("sha256-"))
|
||||
return .Err;
|
||||
|
||||
var pValue;
|
||||
if(pValue.StartsWith("sha256-"))
|
||||
pValue = pValue.Substring("sha256-".Length);
|
||||
|
||||
return SHA256Hash.Parse(pValue);
|
||||
}
|
||||
|
||||
}
|
|
@ -32,12 +32,13 @@ class Default
|
|||
# 1.1.0
|
||||
rgba color FF FF FF FF
|
||||
rgb c 34 67 EF
|
||||
hash id sha256-218989F4E69B157EA38EBFC3051FB7A0011FBD1B2E4303DCB48D46C10622DA0B
|
||||
""";
|
||||
Dictionary<StringView, Bofa> output = new .();
|
||||
List<int64> errors = new .();
|
||||
BofaParser.Parse(content, output, errors);
|
||||
|
||||
Test.Assert(output.Count == 11);
|
||||
Test.Assert(output.Count == 12);
|
||||
Test.Assert(errors.Count == 0);
|
||||
|
||||
DeleteDictionaryAndValues!(output);
|
||||
|
|
|
@ -17,5 +17,6 @@ enum EBofaType
|
|||
|
||||
//1.1.0
|
||||
RGB, //3 * 8bit
|
||||
RGBA //4 * 8bit
|
||||
RGBA, //4 * 8bit
|
||||
Hash, //Sha256
|
||||
}
|
Loading…
Add table
Reference in a new issue