Skip to content

Commit d3433bb

Browse files
committed
string parse instead of regex for autodetect
1 parent 1224f5b commit d3433bb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/avrdudess/Avrdude.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ private enum ParseMemType
124124
public event EventHandler<ReadFuseLockEventArgs> OnReadFuseLock;
125125

126126
private static readonly Regex strArrSplitRegex = new Regex("\"[\\s]*,[\\s]*\"");
127-
private static readonly Regex extractDevSigRegex = new Regex("signature = (?:0x)?([0-9a-fA-F]{2}\\s*[0-9a-fA-F]{2}\\s*[0-9a-fA-F]{2})", RegexOptions.IgnoreCase);
128127

129128
#region Getters and setters
130129

@@ -432,8 +431,10 @@ public bool launch(string args, OutputTo outputTo = OutputTo.Console)
432431
public void detectMCU(string args)
433432
{
434433
launch(args, (object _) => {
435-
var match = extractDevSigRegex.Match(outputLogStdErr);
436-
string detectedSignature = match.Groups[1].Value.Replace(" ", "").ToLower();
434+
var detectedSignature = "";
435+
var sigIdx = outputLogStdErr.IndexOf("signature = ");
436+
if (sigIdx != -1 && outputLogStdErr.Length > sigIdx + 12 + 8)
437+
detectedSignature = outputLogStdErr.Substring(sigIdx + 12, 8).Replace(" ", "").Replace("0x", "").ToLower();
437438
OnDetectedMCU?.Invoke(this, new DetectedMCUEventArgs(detectedSignature));
438439
}, null, OutputTo.Memory);
439440
}

0 commit comments

Comments
 (0)