public void TestParseParameters_LiteralMixed() { foreach (var literal in new[] { "", " ", " ", "lkryweiuf rysiu", "Lorem Ipsum", "Int Plural Short", "LONG_TEXT_AAAAAABBBBBBBBBBBBBBBBBBBBBBB" }) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { $"\"{literal}\"", "Int test" }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 2); Assert.IsType <LiteralStringFormatTagParameter>(res.Parameters[0]); Assert.IsType <FunctionFormatTagParameter>(res.Parameters[1]); var literalParam = (LiteralStringFormatTagParameter)res.Parameters[0]; Assert.Equal(literal, literalParam.Value); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } }
public void TestParseParameters_Multi() { var strings = new[] { "", " ", " ", "lkryweiuf rysiu", "Lorem Ipsum", "Int Plural Short", "LONG_TEXT_AAAAAABBBBBBBBBBBBBBBBBBBBBBB" }; foreach (var literal1 in strings) { foreach (var literal2 in strings) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { $"\"{literal1}\"", $"\"{literal2}\"", }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 2); for (int i = 0; i < 2; ++i) { Assert.IsType <LiteralStringFormatTagParameter>(res.Parameters[i]); var literalParam = (LiteralStringFormatTagParameter)res.Parameters[i]; Assert.Equal(i == 0 ? literal1 : literal2, literalParam.Value); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } } } }
/// <summary> /// Default constructor /// </summary> public WaveFormat2(byte[] data) { if (data.Length < 16) { throw new InvalidOperationException("Not enough data"); } FormatTag = (FormatTag)BitConverter.ToInt16(data, 0); Channels = BitConverter.ToInt16(data, 2); SamplesPerSec = BitConverter.ToInt32(data, 4); AvgBytesPerSec = BitConverter.ToInt32(data, 8); BlockAlign = BitConverter.ToInt16(data, 12); BitsPerSample = BitConverter.ToInt16(data, 14); if (data.Length == 16) { Size = 0; Extra = new byte[0]; return; } Size = BitConverter.ToInt16(data, 16); Extra = new byte[Size]; if (data.Length - 18 < Size) { throw new InvalidOperationException("Not enough data"); } Buffer.BlockCopy(data, 18, Extra, 0, Size); }
public void TestParseParameters_OneLiteral() { foreach (var literal in new[] { "", " ", " ", "test", "Plural", "Int", "LONG_TEXT_AAAAAAAAAAAAAAAAAAAAAAAAA", "TEXT WITH ] CHAR", "TEXT WITH \\\" CHAR" }) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { $"\"{literal}\"" }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 1); Assert.IsType <LiteralStringFormatTagParameter>(res.Parameters[0]); var literalParam = (LiteralStringFormatTagParameter)res.Parameters[0]; Assert.Equal(literal, literalParam.Value); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } }
public void TestParseParameters_Multi() { var localizedItems = new List <ReswItem>() { new ReswItem("TestString", "Test"), new ReswItem("Hello", "World"), new ReswItem("1223", "Number"), new ReswItem("Test_String", "TEST"), }; foreach (var stringRef1 in localizedItems) { foreach (var stringRef2 in localizedItems) { var res = FormatTag.ParseParameters("test", new[] { $"{stringRef1.Key}()", $"{stringRef2.Key}()", }, localizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 2); for (int i = 0; i < 2; ++i) { Assert.IsType <StringRefFormatTagParameter>(res.Parameters[i]); var macroParam = (StringRefFormatTagParameter)res.Parameters[i]; Assert.Equal(i == 0 ? stringRef1.Key : stringRef2.Key, macroParam.Id); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } } } }
public void TestParseParameters_TypedVariantNotAccepted() { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { "Variant Int var1", "Variant var2" }, basicLocalizedItems, "test", null); Assert.Null(res); }
public void TestParseParameters_OneValidNamedPluralParameter() { foreach (var type in FormatTag.AcceptedTypes.Where(t => t.Value.CanBeQuantifier)) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { "Plural " + type.Key + " testParam" }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 1); Assert.IsType <FunctionFormatTagParameter>(res.Parameters[0]); var functionParam = (FunctionFormatTagParameter)res.Parameters[0]; Assert.Equal(functionParam.Type, type.Value.Type); Assert.Equal("testParam", functionParam.Name); Assert.Equal(res.PluralizationParameter, functionParam); Assert.False(functionParam.IsVariantId); if (type.Value.Type == ParameterType.Double) { Assert.Null(functionParam.TypeToCast); } else { Assert.Equal(ParameterType.Double, functionParam.TypeToCast); } Assert.Null(res.VariantParameter); } }
static void ParseFlags(FormatTag tag, string format, ref int i) { while (true) { switch (format[i]) { case '-': tag.LeftJustify = true; break; case '+': tag.ForceSignPrecedence = true; break; case '#': tag.Hash = true; break; case ' ': tag.PadSignWithSpace = true; break; case '0': tag.PadWithZeros = true; break; default: return; } i++; } }
protected AbstractLineFormatter(string documentLine, int maxWidth) { Tag = new FormatTag(documentLine); MaxWidth = maxWidth; FontWidth = Tag.Width; FontHeight = Tag.Height; Line = RemoveTag(documentLine); }
protected AbstractLineFormatter(string documentLine, int maxWidth) { Tag = new FormatTag(documentLine); MaxWidth = maxWidth; FontWidth = Tag.Width; FontHeight = Tag.Height; Line = RemoveTag(documentLine); }
private bool ManageFormattedFunction(Localization localization, string comment, IEnumerable <ReswItem> basicLocalizedItems, string resourceName) { FunctionFormatTagParametersInfo tagTypedInfo = null; var(format, isDotNetFormatting) = ParseTag(comment); if (format != null) { localization.IsDotNetFormatting = isDotNetFormatting; var types = FormatTag.SplitParameters(format); tagTypedInfo = FormatTag.ParseParameters(localization.Key, types, basicLocalizedItems, resourceName, _logger); if (tagTypedInfo != null) { localization.Parameters = tagTypedInfo.Parameters; } } if (localization is IVariantLocalization variantLocalization) { FunctionFormatTagParameter variantParameter = null; // Add an extra parameter for variant if necessary if (tagTypedInfo?.VariantParameter == null) { variantParameter = new FunctionFormatTagParameter { Type = ParameterType.Long, Name = "variantId", IsVariantId = true }; localization.ExtraParameters.Add(variantParameter); } else { variantParameter = tagTypedInfo.VariantParameter; } variantLocalization.ParameterToUseForVariant = variantParameter; } if (localization is PluralLocalization pluralLocalization) { FunctionFormatTagParameter pluralizationQuantifier = null; // Add an extra parameter for pluralization if necessary if (tagTypedInfo?.PluralizationParameter == null) { pluralizationQuantifier = new FunctionFormatTagParameter { Type = ParameterType.Double, Name = "pluralizationReferenceNumber" }; pluralLocalization.ExtraParameters.Add(pluralizationQuantifier); } else { pluralizationQuantifier = tagTypedInfo.PluralizationParameter; } pluralLocalization.ParameterToUseForPluralization = pluralizationQuantifier; } return(true); }
static void ParseWidth(FormatTag tag, string format, ref int i) { while (format[i].IsDecimal()) { tag.Width *= 10; tag.Width += format[i] - '0'; i++; } }
public void TestParseParameters_WrongTypePluralParameter() { foreach (var type in FormatTag.AcceptedTypes.Where(t => !t.Value.CanBeQuantifier)) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { $"Plural {type}" }, basicLocalizedItems, "test", null); Assert.Null(res); } }
public RiffWaveFmt_(FormatTag aTag, UInt16 aChannels, UInt32 aSamplesPerSec, UInt32 aAverageBytesPerSec, UInt16 aBlockAlign, UInt16 aBitsPerSample, RiffChunkList aParent) : base(ID, 16, null, null) { formatTag = aTag; channels = aChannels; samplesPerSec = aSamplesPerSec; averageBytesPerSec = aAverageBytesPerSec; blockAlign = aBlockAlign; bitsPerSample = aBitsPerSample; }
public void CopyFrom(WaveFormat2 wf) { this.AvgBytesPerSec = wf.AvgBytesPerSec; this.BitsPerSample = wf.BitsPerSample; this.BlockAlign = wf.BlockAlign; this.Channels = wf.Channels; this.Extra = wf.Extra.Clone() as byte[]; this.FormatTag = wf.FormatTag; this.SamplesPerSec = wf.SamplesPerSec; this.Size = wf.Size; }
static FormatTag ParseTag(string format, int tagCount, ref int i) { i++; var tag = new FormatTag(tagCount); ParseFlags(tag, format, ref i); ParseWidth(tag, format, ref i); ParsePrecision(tag, format, ref i); ParseSpecifier(tag, format, ref i); return(tag); }
static void ParseSpecifier(FormatTag tag, string format, ref int i) { FormatSpecifier specifier; if (!formatSpecifiers.TryGetValue(format[i], out specifier)) { throw new LuaRuntimeException(ExceptionMessage.STRING_FORMAT_INVALID_OPTION, format); } tag.Specifier = specifier; i++; }
public void TestParseParameters_OneValidParameter() { foreach (var type in FormatTag.AcceptedTypes) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { type.Key }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 1); Assert.IsType <FunctionFormatTagParameter>(res.Parameters[0]); Assert.Equal(((FunctionFormatTagParameter)res.Parameters[0]).Type, type.Value.Type); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } }
public void TestParseParameters_OneValidNamelessVariantParameter() { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { "Variant" }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 1); Assert.IsType <FunctionFormatTagParameter>(res.Parameters[0]); var functionParam = (FunctionFormatTagParameter)res.Parameters[0]; Assert.Equal(ParameterType.Long, functionParam.Type); Assert.Null(res.PluralizationParameter); Assert.True(functionParam.IsVariantId); Assert.Equal(res.VariantParameter, functionParam); }
public void TestParseParameters_TypeLessPlural() { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { "Plural" }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 1); Assert.IsType <FunctionFormatTagParameter>(res.Parameters[0]); var functionParam = (FunctionFormatTagParameter)res.Parameters[0]; Assert.Equal(ParameterType.Double, functionParam.Type); Assert.Equal(res.PluralizationParameter, functionParam); Assert.Null(functionParam.TypeToCast); Assert.Null(res.VariantParameter); }
public void TestParseParameters_OneLiteral() { foreach (var macro in FormatTag.MacrosAvailable) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { macro.Key }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 1); Assert.IsType <MacroFormatTagParameter>(res.Parameters[0]); var macroParam = (MacroFormatTagParameter)res.Parameters[0]; Assert.Equal(macro.Value, macroParam.Id); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } }
static void ParsePrecision(FormatTag tag, string format, ref int i) { if (format[i] != '.') { return; } i++; tag.Precision = 0; while (format[i].IsDecimal()) { tag.Precision *= 10; tag.Precision += format[i] - '0'; i++; } }
public RiffWaveFmt_(string aId, UInt32 aSize, AByteArray aByteArray, RiffChunkList aParent) : base(aId, aSize, aByteArray, aParent) { formatTag = ( FormatTag )aByteArray.ReadUInt16(); channels = aByteArray.ReadUInt16(); samplesPerSec = aByteArray.ReadUInt32(); averageBytesPerSec = aByteArray.ReadUInt32(); blockAlign = aByteArray.ReadUInt16(); bitsPerSample = aByteArray.ReadUInt16(); informationList.Add("Format Tag:" + formatTag); informationList.Add("Channels:" + channels); informationList.Add("Samples Per Sec:" + samplesPerSec); informationList.Add("Average Bytes Per Sec:" + averageBytesPerSec); informationList.Add("Block Align:" + blockAlign); informationList.Add("Bits Per Sample:" + bitsPerSample); Logger.BreakDebug("Size" + aSize); }
public void should_parse_tag_from_string(string raw, TagType type, object value, params TagModifier[] modifiers) { var parsed = new FormatTag(raw); TagModifier modifier = 0; foreach (var m in modifiers) { modifier |= m; } parsed.TagType.Should().Be(type); if ((parsed.Value as Regex) != null) { (parsed.Value as Regex).ToString().Should().Be((value as string)); } else { parsed.Value.Should().Be(value); } parsed.TagModifier.Should().Be(modifier); }
public void TestSplittingParameters() { var parametersList = new List <string[]>() { new string[] { "hi", "\"test\"", "hello", "world" }, new string[] { "test", "\"hello, world\"", // the comma in the string would cause the test to fail if we used .Split(',') "HI" }, new string[] { "test", "\"hello\\\" world\"", "HI" }, new string[] { " test ", " \"hello[] world\" ", "HI " }, new string[] { "Hello" } }; foreach (var parameters in parametersList) { var parametersStr = parameters.Aggregate((a, b) => a + "," + b); var resultParameters = FormatTag.SplitParameters(parametersStr).ToList(); Assert.True(parameters.Select(s => s.Trim()).SequenceEqual(resultParameters)); } }
public void TestParseParameters_StringRef() { var localizedItems = new List <ReswItem>() { new ReswItem("TestString", "Test"), new ReswItem("Hello", "World"), new ReswItem("1223", "Number"), new ReswItem("Test_String", "TEST"), }; foreach (var item in localizedItems) { var res = FormatTag.ParseParameters("test", new[] { $"{item.Key}()" }, localizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 1); Assert.IsType <StringRefFormatTagParameter>(res.Parameters[0]); var stringRefParam = (StringRefFormatTagParameter)res.Parameters[0]; Assert.Equal(item.Key, stringRefParam.Id); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } }
public void TestGetParameterTypeIncorrectTypes() { var res = FormatTag.GetParameterType("", false); Assert.Null(res.type); Assert.Null(res.typeToCast); foreach (var type in new string[] { "ant", "doble", "Int, Double", "UnsignedInt" }) { res = FormatTag.GetParameterType(type, false); Assert.Null(res.type); Assert.Null(res.typeToCast); res = FormatTag.GetParameterType(type, true); Assert.Null(res.type); Assert.Null(res.typeToCast); } }
public void TestParseParameters_WrongStringRef() { var localizedItems = new List <ReswItem>() { new ReswItem("TestString", "Test"), new ReswItem("Hello", "World"), new ReswItem("1223", "Number"), new ReswItem("Test_String", "TEST"), }; var wrongRefItems = new List <string>() { "AA", "Test", "Number" }; foreach (var item in wrongRefItems) { var res = FormatTag.ParseParameters("test", new[] { $"{item}()" }, localizedItems, "test", null); Assert.Null(res); } }
public void TestGetParameterTypeExistingTypes() { foreach (var type in FormatTag.AcceptedTypes) { var typeRes = FormatTag.GetParameterType(type.Key, false); Assert.Equal(typeRes.type, type.Value.Type); Assert.Null(typeRes.typeToCast); Assert.False(typeRes.isVariantId); typeRes = FormatTag.GetParameterType(type.Key, true); Assert.Equal(typeRes.type, type.Value.Type); Assert.Equal(typeRes.typeToCast.HasValue, type.Value.CanBeQuantifier && type.Value.Type != ParameterType.Double); if (typeRes.typeToCast.HasValue) { Assert.Equal(ParameterType.Double, typeRes.typeToCast.Value); } } var res = FormatTag.GetParameterType("", true); Assert.Equal(ParameterType.Double, res.type); Assert.Null(res.typeToCast); }
public void TestParseParameters_MultiValidParameter() { foreach (var type1 in FormatTag.AcceptedTypes) { foreach (var type2 in FormatTag.AcceptedTypes) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { type1.Key, type2.Key + " paramName" }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 2); Assert.IsType <FunctionFormatTagParameter>(res.Parameters[0]); Assert.Equal(((FunctionFormatTagParameter)res.Parameters[0]).Type, type1.Value.Type); Assert.False(((FunctionFormatTagParameter)res.Parameters[0]).IsVariantId); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); Assert.IsType <FunctionFormatTagParameter>(res.Parameters[1]); Assert.Equal(((FunctionFormatTagParameter)res.Parameters[1]).Type, type2.Value.Type); Assert.False(((FunctionFormatTagParameter)res.Parameters[1]).IsVariantId); Assert.Equal("paramName", ((FunctionFormatTagParameter)res.Parameters[1]).Name); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } } }
public void TestParseParameters_Multi() { foreach (var macro1 in FormatTag.MacrosAvailable) { foreach (var macro2 in FormatTag.MacrosAvailable) { var basicLocalizedItems = new ReswItem[0]; var res = FormatTag.ParseParameters("test", new[] { macro1.Key, macro2.Key, }, basicLocalizedItems, "test", null); Assert.NotNull(res); Assert.True(res.Parameters.Count == 2); for (int i = 0; i < 2; ++i) { Assert.IsType <MacroFormatTagParameter>(res.Parameters[i]); var macroParam = (MacroFormatTagParameter)res.Parameters[i]; Assert.Equal(i == 0 ? macro1.Value : macro2.Value, macroParam.Id); Assert.Null(res.PluralizationParameter); Assert.Null(res.VariantParameter); } } } }
static void ParseWidth(FormatTag tag, string format, ref int i) { while (format[i].IsDecimal()) { tag.Width *= 10; tag.Width += format[i] - '0'; i++; } }
static FormatTag ParseTag(string format, int tagCount, ref int i) { i++; var tag = new FormatTag(tagCount); ParseFlags(tag, format, ref i); ParseWidth(tag, format, ref i); ParsePrecision(tag, format, ref i); ParseSpecifier(tag, format, ref i); return tag; }
public Builder Format(FormatTag value) { format = value; return this; }
static void ParsePrecision(FormatTag tag, string format, ref int i) { if (format[i] != '.') return; i++; tag.Precision = 0; while (format[i].IsDecimal()) { tag.Precision *= 10; tag.Precision += format[i] - '0'; i++; } }
static void ParseSpecifier(FormatTag tag, string format, ref int i) { FormatSpecifier specifier; if (!formatSpecifiers.TryGetValue(format[i], out specifier)) throw new LuaRuntimeException(ExceptionMessage.STRING_FORMAT_INVALID_OPTION, format); tag.Specifier = specifier; i++; }
static void ParseFlags(FormatTag tag, string format, ref int i) { while (true) { switch (format[i]) { case '-': tag.LeftJustify = true; break; case '+': tag.ForceSignPrecedence = true; break; case '#': tag.Hash = true; break; case ' ': tag.PadSignWithSpace = true; break; case '0': tag.PadWithZeros = true; break; default: return; } i++; } }