-
Notifications
You must be signed in to change notification settings - Fork 24
ImportBuddy Log Cleaning improvements #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39cced3
Instead of removing all DRV and MSG log lines, only redact sensitive …
ociaw 76c358d
Ensure the Linux appsettings file has the same case as the actual file
ociaw 31d084a
Correctly parse MSG log entries containing a ',' (comma)
ociaw fdede1c
Fix exception when reading an empty drive name
ociaw 88c57fe
Move and document TryParse methods for CsvEnumerator
ociaw adb50e3
Redact messages with "***"
ociaw e927144
Add braces to if and while statements
ociaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| namespace MakeMkv; | ||
|
|
||
| /// <summary> | ||
| /// Iterates over comma separated values in a single line of text. | ||
| /// </summary> | ||
| public sealed class CsvEnumerator | ||
| { | ||
| private readonly String _span; | ||
|
|
||
| private readonly Boolean _isInitialized; | ||
|
|
||
| private Int32 _currentStart; | ||
| private Int32 _currentEnd; | ||
|
|
||
| /// <inheritdoc cref="IEnumerator{T}.Current" /> | ||
| public ReadOnlySpan<Char> Current => _span.AsSpan()[_currentStart.._currentEnd]; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="CsvEnumerator"/> over a span of characters. | ||
| /// </summary> | ||
| public CsvEnumerator(String span) | ||
| { | ||
| _isInitialized = true; | ||
| _span = span; | ||
| _currentStart = 0; | ||
| _currentEnd = -1; | ||
| } | ||
|
|
||
| /// <inheritdoc cref="IEnumerator{T}.MoveNext" /> | ||
| public Boolean MoveNext() | ||
| { | ||
| Int32 start = _currentEnd + 1; | ||
| if (!_isInitialized || start > _span.Length) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var slice = _span[start..]; | ||
| _currentStart = start; | ||
|
|
||
| Boolean quoted = false; | ||
| Boolean escaped = false; | ||
| Int32 i; | ||
| for (i = 0; i < slice.Length; i++) | ||
| { | ||
| Char curChar = slice[i]; | ||
| if (curChar == '\\') | ||
| { | ||
| if (!escaped) | ||
| { | ||
| escaped = true; | ||
| continue; | ||
| } | ||
| } | ||
| else if (curChar == '"') | ||
| { | ||
| if (!escaped) | ||
| { | ||
| quoted = !quoted; | ||
| } | ||
| } | ||
| else if (curChar == ',') | ||
| { | ||
| if (!quoted) | ||
| { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| escaped = false; | ||
| } | ||
|
|
||
| Int32 elementLength = i; | ||
|
|
||
| _currentEnd = _currentStart + elementLength; | ||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns an enumerator suitable for use in foreach loops. | ||
| /// </summary> | ||
| public CsvEnumerator GetEnumerator() => this; | ||
|
|
||
| /// <summary> | ||
| /// Attempts to advance the enumerator and parse the value as an <see cref="int"/>. | ||
| /// </summary> | ||
| /// <returns>The parsed value, or the <see langword="default"/> value if enumeration or parsing failed.</returns> | ||
| public int TryParseInt() | ||
| { | ||
| if (MoveNext()) | ||
| { | ||
| if (Int32.TryParse(Current, out int val)) | ||
| { | ||
| return val; | ||
| } | ||
| } | ||
|
|
||
| return default; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to advance the enumerator and parse the value as a <see cref="bool"/>. | ||
| /// </summary> | ||
| /// <returns>The parsed value, or <see langword="false"/> if enumeration or parsing failed.</returns> | ||
| public bool TryParseBoolean() | ||
| { | ||
| if (MoveNext()) | ||
| { | ||
| if (Int32.TryParse(Current, out int val)) | ||
| { | ||
| return val != 256 && val != 999 && val > 0; | ||
| } | ||
| } | ||
|
|
||
| return default; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to advance the enumerator and parse the value as a <see cref="long"/>. | ||
| /// </summary> | ||
| /// <returns>The parsed value, or <see langword="null"/> if enumeration or parsing failed.</returns> | ||
| public string? GetString() | ||
| { | ||
| if (MoveNext()) | ||
| { | ||
| return Current.ToString().Replace("\"", string.Empty); | ||
| } | ||
|
|
||
| return default; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to advance the enumerator and parse the value as a <see cref="DateTime"/>. | ||
| /// </summary> | ||
| /// <returns>The parsed value, or the <see langword="default"/> value if enumeration or parsing failed.</returns> | ||
| public DateTime TryParseDateTime() | ||
| { | ||
| if (MoveNext()) | ||
| { | ||
| if (DateTime.TryParse(Current, out DateTime val)) | ||
| { | ||
| return val; | ||
| } | ||
| } | ||
|
|
||
| return default; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to advance the enumerator and parse the value as a <see cref="long"/>. | ||
| /// </summary> | ||
| /// <returns>The parsed value, or the <see langword="default"/> value if enumeration or parsing failed.</returns> | ||
| public long TryParseLong() | ||
| { | ||
| if (MoveNext()) | ||
| { | ||
| if (Int64.TryParse(Current, out long val)) | ||
| { | ||
| return val; | ||
| } | ||
| } | ||
|
|
||
| return default; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.