| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.Metadata.Descriptors; |
| | 4 | | using ValidateLib.Metadata.Properties.AtomicProperties; |
| | 5 | |
|
| | 6 | | namespace ValidateLib.Metadata.PropertyParsers.DIalect |
| | 7 | | { |
| | 8 | | internal class TrimPropertyParser : PropertyParserBase<DialectDescriptor>, IPropertyParser<DialectDescriptor> |
| | 9 | | { |
| 1 | 10 | | public TrimPropertyParser(List<Warning> warnings, DialectDescriptor descriptor) : base(warnings, descriptor) |
| | 11 | | { |
| 1 | 12 | | } |
| | 13 | |
|
| | 14 | | public void ParseProperty(JProperty property) |
| | 15 | | { |
| 1 | 16 | | string[] acceptedValues = new string[] { "true", "false", "start", "end" }; |
| 1 | 17 | | if (property.Value.Type == JTokenType.Boolean) |
| | 18 | | { |
| 1 | 19 | | bool boolValue = (bool)property.Value; |
| 1 | 20 | | Descriptor.trim = new Properties.AtomicProperties.AtomicPropertyString(boolValue ? "true" : "false"); |
| | 21 | | } |
| 1 | 22 | | else if (property.Value.Type == JTokenType.String) |
| | 23 | | { |
| 0 | 24 | | if (acceptedValues.Contains(property.Value.ToString())) |
| 0 | 25 | | Descriptor.trim = new Properties.AtomicProperties.AtomicPropertyString(property.Value.ToString()); |
| | 26 | | else |
| | 27 | | { |
| 0 | 28 | | Warnings.Add(WarningFactory.GetInvalidTrimValueWarning(property.ToString())); |
| 0 | 29 | | if (Descriptor.trim == null) |
| 0 | 30 | | Descriptor.trim = new AtomicPropertyString("true"); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | } |
| | 34 | | else |
| | 35 | | { |
| 1 | 36 | | Warnings.Add(WarningFactory.GetStringPropertyWrongValueWarning(property.Value, property.Name, property.V |
| | 37 | | } |
| 1 | 38 | | } |
| | 39 | | } |
| | 40 | | } |