internal static List <Keyframe <T> > Parse <T>(JsonReader reader, LottieComposition composition, float scale, IValueParser <T> valueParser) { List <Keyframe <T> > keyframes = new List <Keyframe <T> >(); if (reader.Peek() == JsonToken.String) { composition.AddWarning("Lottie doesn't support expressions."); return(keyframes); } reader.BeginObject(); while (reader.HasNext()) { switch (reader.NextName()) { case "k": if (reader.Peek() == JsonToken.StartArray) { reader.BeginArray(); if (reader.Peek() == JsonToken.Integer || reader.Peek() == JsonToken.Float) { // For properties in which the static value is an array of numbers. keyframes.Add(KeyframeParser.Parse(reader, composition, scale, valueParser, false)); } else { while (reader.HasNext()) { keyframes.Add(KeyframeParser.Parse(reader, composition, scale, valueParser, true)); } } reader.EndArray(); } else { keyframes.Add(KeyframeParser.Parse(reader, composition, scale, valueParser, false)); } break; default: reader.SkipValue(); break; } } reader.EndObject(); SetEndFrames <Keyframe <T>, T>(keyframes); return(keyframes); }
/// <summary> /// Add a new value parser to the provider, or if a value provider already exists for /// <see cref="IValueParser.TargetType"/> then replaces it with <paramref name="parser"/>. /// </summary> /// <param name="parser">An instance of the parser that is used to convert an argument from a string.</param> /// <exception cref="ArgumentNullException"><paramref name="parser"/> is null.</exception> public void AddOrReplace(IValueParser parser) { SafeAdd(parser, andReplace: true); }
public DirectoryService() { ExifDateTimeParser = new ExifDateTimeParser(); }
public static IProperty <T> GetProperty <T>(this IConfigurationManager manager, string key, T defaultValue, bool useCache, IValueParser <T> valueParser, IValueCorrector <T> valueCorrector) { manager = manager.NotNull("manager"); return(manager.GetProperty <T>(key, new PropertyConfig <T>(defaultValue, useCache, valueParser, valueCorrector))); }
public ValueTupleValueParser(IValueParser typeParser) { _typeParser = typeParser; }
/// <summary> /// Will return null if the animation can't be played such as if it has expressions. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="reader"></param> /// <param name="scale"></param> /// <param name="composition"></param> /// <param name="valueParser"></param> /// <returns></returns> private static List <Keyframe <T> > Parse <T>(JsonReader reader, LottieComposition composition, IValueParser <T> valueParser) { return(KeyframesParser.Parse(reader, composition, valueParser)); }
internal static Keyframe <T> Parse <T>(JsonReader reader, LottieComposition composition, float scale, IValueParser <T> valueParser, bool animated) { if (animated) { return(ParseKeyframe(composition, reader, scale, valueParser)); } return(ParseStaticValue(reader, scale, valueParser)); }
/// <summary> /// Parses an element of a list of values of the pattern. /// </summary> /// <param name="str">The element string.</param> /// <param name="parser">The parser used to parse the values.</param> /// <returns>A list of ints representing the allowed values.</returns> /// <exception cref="System.Exception">If the supplied pattern part is not valid.</exception> private List<int> ParseListElement(string str, IValueParser parser) { var st = str.Split('/'); int size = st.Length; if (size < 1 || size > 2) { throw new Exception("syntax error"); } List<int> values; try { values = ParseRange(st[0], parser); } catch (Exception e) { throw new Exception("invalid range, " + e.Message); } if (size == 2) { string dStr = st[1]; int div; try { div = int.Parse(dStr); } catch { throw new Exception("invalid divisor \"" + dStr + "\""); } if (div < 1) { throw new Exception("non positive divisor \"" + div + "\""); } List<int> values2 = new List<int>(); for (int i = 0; i < values.Count; i += div) { values2.Add(values[i]); } return values2; } else { return values; } }
/// <summary> /// Parses a range of values. /// </summary> /// <param name="str">The range string.</param> /// <param name="parser">The parser used to parse the values.</param> /// <returns>A list of ints representing the allowed values.</returns> /// <exception cref="System.Exception">If the supplied pattern part is not valid.</exception> private List<int> ParseRange(string str, IValueParser parser) { if (str == "*") { int min = parser.MinValue; int max = parser.MaxValue; List<int> values = new List<int>(max - min + 1); for (int i = min; i <= max; i++) { values.Add(i); } return values; } var st = str.Split('-'); int size = st.Length; if (size < 1 || size > 2) { throw new Exception("syntax error"); } string v1Str = st[0]; int v1; try { v1 = parser.Parse(v1Str); } catch (Exception e) { throw new Exception("invalid value \"" + v1Str + "\", " + e.Message); } if (size == 1) { List<int> values = new List<int>(1); values.Add(v1); return values; } else { string v2Str = st[1]; int v2; try { v2 = parser.Parse(v2Str); } catch (Exception e) { throw new Exception("invalid value \"" + v2Str + "\", " + e.Message); } List<int> values = new List<int>(); if (v1 < v2) { for (int i = v1; i <= v2; i++) { values.Add(i); } } else if (v1 > v2) { int min = parser.MinValue; int max = parser.MaxValue; for (int i = v1; i <= max; i++) { values.Add(i); } for (int i = min; i <= v2; i++) { values.Add(i); } } else { // v1 == v2 values.Add(v1); } return values; } }
/// <summary> /// /// </summary> /// <param name="cValueMatcher"></param> /// <param name="st"></param> /// <param name="cValueParser"></param> /// <param name="pattern"></param> /// <param name="cpType"></param> /// <exception cref="InvalidPatternException"></exception> private void BuildValueMatcher(List<IValueMatcher> cValueMatcher, string st, IValueParser cValueParser, string pattern, string cpType) { try { cValueMatcher.Add(BuildValueMatcher(st, cValueParser)); } catch (Exception e) { throw new InvalidPatternException(string.Format( @"invalid pattern ""{0}"". Error parsing {1} field: {2}.", pattern, cpType, e.Message)); } }
/// <summary> /// A ValueMatcher utility builder. /// </summary> /// <param name="str">The pattern part for the ValueMatcher creation.</param> /// <param name="parser">The parser used to parse the values.</param> /// <returns>The requested ValueMatcher.</returns> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.Exception"></exception> private IValueMatcher BuildValueMatcher(string str, IValueParser parser) { if (string.IsNullOrEmpty(str)) throw new ArgumentNullException("str"); if (str.Length == 1 && str == "*") { return new AlwaysTrueValueMatcher(); } List<int> values = new List<int>(); var st = str.Split(','); foreach (var element in st) { List<int> local; try { local = ParseListElement(element, parser); } catch (Exception e) { throw new Exception("invalid field \"" + str + "\", invalid element \"" + element + "\", " + e.Message); } foreach (var value in local) { if (!values.Contains(value)) { values.Add(value); } } } if (values.Count == 0) { throw new Exception("invalid field \"" + str + "\""); } if (parser == DAY_OF_MONTH_VALUE_PARSER) { return new DayOfMonthValueMatcher(values); } else { return new IntArrayValueMatcher(values); } }
private void RegisterNullable <T>(IValueParser <T> valueParser) where T : struct { this.Register <T?>((IValueParser <T?>) new NullableParser <T>(valueParser)); }
public void Register <T>(IValueParser <T> valueParser) { valueParser = valueParser.NotNull("valueParser"); this.ValueParserCache[typeof(T)] = (object)valueParser; }
/// <summary> /// Initializes a new instance of <see cref="CommandArgument{T}" /> /// </summary> /// <param name="valueParser">The value parser.</param> public CommandArgument(IValueParser <T> valueParser) { _valueParser = valueParser ?? throw new ArgumentNullException(nameof(valueParser)); UnderlyingType = typeof(T); }
public ListParser(Type elementType, IValueParser elementParser, CultureInfo parserCulture) { _elementParser = elementParser; _listType = typeof(List <>).MakeGenericType(elementType); _parserCulture = parserCulture; }
void Set(string valueString, IValueParser valueParser) { Set(new ParserState(new[] { valueString }), valueParser); }
public TupleValueParser(IValueParser <T> typeParser) { _typeParser = typeParser; }
void Set(ParserState args, IValueParser valueParser) { var value = valueParser.Parse(args, Property.PropertyType); Property.SetValue(this.instance, value); }
private static Keyframe <T> ParseStaticValue <T>(JsonReader reader, float scale, IValueParser <T> valueParser) { T value = valueParser.Parse(reader, scale); return(new Keyframe <T>(value)); }
public ArrayParser(Type elementType, IValueParser elementParser, CultureInfo parserCulture) { _elementType = elementType; _elementParser = elementParser; _parserCulture = parserCulture; }
/// <summary> /// beginObject will already be called on the keyframe so it can be differentiated with /// a non animated value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="composition"></param> /// <param name="reader"></param> /// <param name="scale"></param> /// <param name="valueParser"></param> /// <returns></returns> private static Keyframe <T> ParseKeyframe <T>(LottieComposition composition, JsonReader reader, float scale, IValueParser <T> valueParser) { Vector2? cp1 = null; Vector2? cp2 = null; float startFrame = 0; T startValue = default(T); T endValue = default(T); bool hold = false; IInterpolator interpolator; // Only used by PathKeyframe Vector2?pathCp1 = null; Vector2?pathCp2 = null; reader.BeginObject(); while (reader.HasNext()) { switch (reader.NextName()) { case "t": startFrame = reader.NextDouble(); break; case "s": startValue = valueParser.Parse(reader, scale); break; case "e": endValue = valueParser.Parse(reader, scale); break; case "o": cp1 = JsonUtils.JsonToPoint(reader, scale); break; case "i": cp2 = JsonUtils.JsonToPoint(reader, scale); break; case "h": hold = reader.NextInt() == 1; break; case "to": pathCp1 = JsonUtils.JsonToPoint(reader, scale); break; case "ti": pathCp2 = JsonUtils.JsonToPoint(reader, scale); break; default: reader.SkipValue(); break; } } reader.EndObject(); if (hold) { endValue = startValue; // TODO: create a HoldInterpolator so progress changes don't invalidate. interpolator = LinearInterpolator; } else if (cp1 != null && cp2 != null) { cp1 = new Vector2(MiscUtils.Clamp(cp1.Value.X, -scale, scale), MiscUtils.Clamp(cp1.Value.Y, -MaxCpValue, MaxCpValue)); cp2 = new Vector2(MiscUtils.Clamp(cp2.Value.X, -scale, scale), MiscUtils.Clamp(cp2.Value.Y, -MaxCpValue, MaxCpValue)); int hash = Utils.Utils.HashFor(cp1.Value.X, cp1.Value.Y, cp2.Value.X, cp2.Value.Y); if (GetInterpolator(hash, out var interpolatorRef) == false || interpolatorRef.TryGetTarget(out interpolator) == false) { interpolator = new PathInterpolator(cp1.Value.X / scale, cp1.Value.Y / scale, cp2.Value.X / scale, cp2.Value.Y / scale); try { PutInterpolator(hash, new WeakReference <IInterpolator>(interpolator)); } catch { // It is not clear why but SparseArrayCompat sometimes fails with this: // https://github.com/airbnb/lottie-android/issues/452 // Because this is not a critical operation, we can safely just ignore it. // I was unable to repro this to attempt a proper fix. } } } else { interpolator = LinearInterpolator; } var keyframe = new Keyframe <T>(composition, startValue, endValue, interpolator, startFrame, null) { PathCp1 = pathCp1, PathCp2 = pathCp2 }; return(keyframe); }
public NullableParser(IValueParser parser) { this.parser = parser; }
public static IProperty <T> GetProperty <T>(this IConfigurationManager manager, string key, T defaultValue, IValueParser <T> valueParser, T min, T max) where T : IComparable <T> { manager = manager.NotNull("manager"); return(manager.GetProperty <T>(key, new PropertyConfig <T>(defaultValue, valueParser, (IValueCorrector <T>) new RangeCorrector <T>(min, max)))); }
public NullableValueParser(IValueParser boxedParser) { _wrapped = boxedParser; }
/// <summary> /// Add a new value parser to the provider. /// </summary> /// <param name="parser">An instance of the parser that is used to convert an argument from a string.</param> /// <exception cref="ArgumentException"> /// A value parser with the same <see cref="IValueParser.TargetType"/> is already registered. /// </exception> /// <exception cref="ArgumentNullException"><paramref name="parser"/> is null.</exception> public void Add(IValueParser parser) { SafeAdd(parser); }
/// <summary> /// Intializes a new instance of <see cref="CommandOption{T}" /> /// </summary> /// <param name="valueParser">The parser use to convert values into type of T.</param> /// <param name="template">The option tempalte.</param> /// <param name="optionType">The optiont type</param> public CommandOption(IValueParser <T> valueParser, string template, CommandOptionType optionType) : base(template, optionType) { _valueParser = valueParser ?? throw new ArgumentNullException(nameof(valueParser)); UnderlyingType = typeof(T); }
public GenericParserAdapter(IValueParser inner) { _inner = inner; }
public ListParser(Type elementType, IValueParser elementParser) { _elementParser = elementParser; _listType = typeof(List <>).MakeGenericType(elementType); }
public RRuleTokenizer(IValueParser valueParser, IRRuleValidator rruleValidator) { _valueParser = valueParser; _rruleValidator = rruleValidator; }
/// <summary> /// Initializes a new instance of <see cref="CommandArgument{T}" /> /// </summary> /// <param name="valueParser">The value parser.</param> public CommandArgument(IValueParser <T> valueParser) { _valueParser = valueParser ?? throw new ArgumentNullException(nameof(valueParser)); }