public void Get_WhenTargetTypeIsItsOwnType_CanAlwaysConvert() { var val = new TomlString(new TomlTable.RootTable(TomlSettings.DefaultInstance), "SomeString"); var conv = val.Get <TomlString>(); conv.Should().NotBeNull(); conv.Value.Should().Be("SomeString"); }
public void Get_WhenTargetTypeIsItsOwnType_CanAlwaysConvert() { var val = new TomlString(new TomlTable.RootTable(TomlConfig.DefaultInstance), "SomeString"); var conv = val.Get<TomlString>(); conv.Should().NotBeNull(); conv.Value.Should().Be("SomeString"); }
private Regex ConvertRegexFromString(ITomlRoot root, TomlString tomlString) { var text = tomlString.Value; var match = PropertyWithAliasRegex.Match(text); if (!match.Success) { return(new Regex(text)); } var pattern = match.Groups["regexPattern"].Value; var optionsText = match.Groups["regexOptions"].Value; return(CreateRegex(pattern, optionsText)); }
private TDefinition ParseTimestampDefinitionFromShorthand <TDefinition>(TomlString tomlString, TimestampType defaultTimestampType, Func <TDefinition> factory) where TDefinition : TimestampBaseDefinition { var temp = ParseTimestampDefinitionFromShorthand(tomlString, defaultTimestampType); var definition = factory(); definition.FixedValue = temp.FixedValue; definition.ColumnHeader = temp.ColumnHeader; definition.ColumnIndex = temp.ColumnIndex; definition.PrefaceRegex = temp.PrefaceRegex; definition.Alias = temp.Alias; definition.Formats = temp.Formats; definition.UtcOffset = temp.UtcOffset; definition.Type = temp.Type; return(definition); }
private void WriteString(TomlString s) { this.writer.Write('\"'); this.writer.Write(s.Value.Escape() ?? string.Empty); this.writer.Write('\"'); }
public void Visit(TomlString s) => data[currentPath] = s.Value;
private PropertyDefinition ConvertShorthandPropertySyntax(ITomlRoot root, TomlString tomlString) { var text = tomlString.Value; return(ParsePropertyDefinition(text)); }
private TimestampDefinition ParseTimestampDefinitionFromShorthand(TomlString tomlString, TimestampType defaultTimestampType) { var text = tomlString.Value; var match = TimestampPropertyRegex.Match(text); if (!match.Success) { throw new ArgumentException($"'{text}' is not a supported timestamp string syntax."); } var property = ParsePropertyDefinition(match.Groups["property"].Value); var timestamp = new TimestampDefinition { FixedValue = property.FixedValue, ColumnHeader = property.ColumnHeader, ColumnIndex = property.ColumnIndex, PrefaceRegex = property.PrefaceRegex, Alias = property.Alias, }; foreach (var capture in match.Groups["timestampOption"].Captures.Cast <Capture>()) { var optionText = capture.Value.Trim(); if (string.IsNullOrEmpty(optionText)) { continue; } if (Enum.TryParse <TimestampType>(optionText, true, out var timestampType)) { if (timestamp.Type.HasValue) { throw new ArgumentException($"{nameof(timestamp.Type)} is already set to {timestamp.Type} and cannot be changed to {timestampType}."); } timestamp.Type = timestampType; } else if (TryParseUtcOffset(optionText, out var timeSpan)) { if (timestamp.UtcOffset != null) { throw new ArgumentException($"{nameof(timestamp.UtcOffset)} is already set to {timestamp.UtcOffset.Name()} and cannot be changed to '{optionText}'."); } timestamp.UtcOffset = new PropertyDefinition { FixedValue = $"{timeSpan}" }; } else { timestamp.Formats = new List <string>(timestamp.Formats ?? new string[0]) .Concat(new[] { optionText }) .ToArray(); } } if (!timestamp.Type.HasValue) { timestamp.Type = defaultTimestampType; } return(timestamp); }
private DateOnlyDefinition ConvertShorthandDateOnlySyntax(ITomlRoot root, TomlString tomlString) { return(ParseTimestampDefinitionFromShorthand(tomlString, TimestampType.DateOnly, () => new DateOnlyDefinition())); }
private TimestampDefinition ConvertShorthandTimestampSyntax(ITomlRoot root, TomlString tomlString) { return(ParseTimestampDefinitionFromShorthand(tomlString, TimestampType.DateTimeOnly)); }
void ITomlObjectVisitor.Visit(TomlString s) => sb.Append("{").Append("\"type\":\"string\", \"value\":\"").Append(s.Value.Replace(Environment.NewLine, "\n").Escape()).Append("\"}");
void ITomlObjectVisitor.Visit(TomlString s) => this.table[this.currentKey] = s.Value;
public void Visit(TomlString s) => this.Item = s.Value;
/// <summary> /// Saves the current configuration out to the config file. /// </summary> public void Save() { // Physical Paramters TomlTable physicalParameters = Toml.Create(); // Passes TomlInt passes = physicalParameters.Add("Passes", Passes).Added; passes.AddComment(" The number of times to run the complete etching path", CommentLocation.Append); // PixelSize TomlFloat pixelSize = physicalParameters.Add("PixelSize", PixelSize).Added; pixelSize.AddComment(" The size of each pixel (mm per pixel)", CommentLocation.Append); // OriginX TomlFloat originX = physicalParameters.Add("OriginX", OriginX).Added; originX.AddComment(" The X coordinate of the top-left corner, in mm", CommentLocation.Append); // OriginY TomlFloat originY = physicalParameters.Add("OriginY", OriginY).Added; originY.AddComment(" The Y coordinate of the top-left corner, in mm", CommentLocation.Append); // ZHeight TomlFloat zHeight = physicalParameters.Add("ZHeight", ZHeight).Added; zHeight.AddComment(" The Z height to set the laser cutter during etching, in mm", CommentLocation.Append); // TravelSpeed TomlFloat travelSpeed = physicalParameters.Add("TravelSpeed", TravelSpeed).Added; travelSpeed.AddComment(" The speed to move the head between etching operations (when the laser is off), in mm per minute", CommentLocation.Append); // EtchSpeed TomlFloat etchSpeed = physicalParameters.Add("EtchSpeed", EtchSpeed).Added; etchSpeed.AddComment(" The speed to move the head during etching operations (when the laser is on), in mm per minute", CommentLocation.Append); // G-code Commands TomlTable gCodeCommands = Toml.Create(); // LaserOffCommand TomlString laserOffCommand = gCodeCommands.Add("LaserOffCommand", LaserOffCommand).Added; laserOffCommand.AddComment(" The G-code command to turn the laser off", CommentLocation.Append); // LaserLowCommand TomlString laserLowCommand = gCodeCommands.Add("LaserLowCommand", LaserLowCommand).Added; laserLowCommand.AddComment(" The G-code command to turn the laser on, but at a low power level (used for the pre-etch trace preview)", CommentLocation.Append); // LaserHighCommand TomlString laserHighCommand = gCodeCommands.Add("LaserHighCommand", LaserHighCommand).Added; laserHighCommand.AddComment(" The G-code command to turn the laser on full power during etching", CommentLocation.Append); // MoveCommand TomlString moveCommand = gCodeCommands.Add("MoveCommand", MoveCommand).Added; moveCommand.AddComment(" The G-code command to use during moves", CommentLocation.Append); // CommentMode TomlString commentMode = gCodeCommands.Add("CommentMode", CommentMode.ToString()).Added; commentMode.AddComment(" The G-code comment format to use (Semicolon or Parentheses)", CommentLocation.Append); // HomeXY TomlBool homeXY = gCodeCommands.Add("HomeXY", HomeXY).Added; homeXY.AddComment(" True to home the X and Y axes at the start, false to leave them where they were and assume that they are already homed", CommentLocation.Append); // Pre-Etch Trace Preview TomlTable preEtchTracePreview = Toml.Create(); // IsBoundaryPreviewEnabled TomlBool isBoundaryPreviewEnabled = preEtchTracePreview.Add("IsBoundaryPreviewEnabled", IsBoundaryPreviewEnabled).Added; isBoundaryPreviewEnabled.AddComment(" True to perform the pre-etch boundary trace preview, false to disable it and get right to etching", CommentLocation.Append); // PreviewDelay TomlInt previewDelay = preEtchTracePreview.Add("PreviewDelay", PreviewDelay).Added; previewDelay.AddComment(" The delay, in milliseconds, to wait at the start and end of the pre-etch trace preview", CommentLocation.Append); TomlTable settingsTable = Toml.Create(); settingsTable.Add("Physical-Parameters", physicalParameters); settingsTable.Add("G-Code-Commands", gCodeCommands); settingsTable.Add("Pre-Etch-Trace-Preview", preEtchTracePreview); Toml.WriteFile(settingsTable, ConfigFileName); }