-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up and restructuring of the codebase.
- Loading branch information
Showing
18 changed files
with
127 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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 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 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,15 @@ | ||
using System; | ||
|
||
namespace UniCSV | ||
{ | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] | ||
public sealed class CsvColumnAttribute : Attribute | ||
{ | ||
public string Name { get; } | ||
|
||
public CsvColumnAttribute(string name) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,63 @@ | ||
using System; | ||
using System.Linq; | ||
using static UniCSV.Delimiter; | ||
|
||
namespace UniCSV | ||
{ | ||
public enum Delimiter | ||
{ | ||
Auto, | ||
Comma, | ||
Tab, | ||
Semicolon, | ||
Pipe | ||
} | ||
|
||
public static class DelimiterUtils | ||
{ | ||
private static readonly char[] COMMON_DELIMITERS = { ',', '\t', ';', '|' }; | ||
|
||
public static Delimiter DetectDelimiterFromContent(string content) | ||
{ | ||
if (string.IsNullOrWhiteSpace(content)) | ||
return Comma; | ||
|
||
// Get the first non-empty line | ||
var firstLine = content.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None) | ||
.FirstOrDefault(line => !string.IsNullOrWhiteSpace(line)); | ||
|
||
if (string.IsNullOrWhiteSpace(firstLine)) | ||
return Comma; | ||
|
||
var delimiterCounts = COMMON_DELIMITERS | ||
.ToDictionary(d => d, d => firstLine.Count(c => c == d)); | ||
|
||
var mostFrequentDelimiter = delimiterCounts | ||
.OrderByDescending(kvp => kvp.Value) | ||
.First(); | ||
|
||
if (mostFrequentDelimiter.Value <= 1) | ||
return Comma; | ||
|
||
return CharToDelimiter(mostFrequentDelimiter.Key); | ||
} | ||
|
||
public static char ToChar(this Delimiter delimiter) => delimiter switch | ||
{ | ||
Comma => ',', | ||
Tab => '\t', | ||
Semicolon => ';', | ||
Pipe => '|', | ||
_ => throw new ArgumentException($"Unsupported delimiter: {delimiter}") | ||
}; | ||
|
||
public static Delimiter CharToDelimiter(char delimiterChar) => delimiterChar switch | ||
{ | ||
',' => Comma, | ||
'\t' => Tab, | ||
';' => Semicolon, | ||
'|' => Pipe, | ||
_ => Comma | ||
}; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,3 @@ | ||
{ | ||
"name": "Sov3rain.UniCSV" | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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
2 changes: 1 addition & 1 deletion
2
...or/Sov3rain.Unity-CSV.Editor.Tests.asmdef → ...ditor/Sov3rain.UniCSV.Editor.Tests.asmdef
This file contains 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
File renamed without changes.
This file contains 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 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
Oops, something went wrong.