process-data-standard-format-to-json update
This commit is contained in:
@ -7,7 +7,7 @@ internal static partial class Helper20250306 {
|
||||
internal static void ProcessDataStandardFormatToJson(ILogger<Worker> logger, List<string> args) {
|
||||
string searchPattern = args[2];
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
if (files.Length != 1)
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
@ -21,21 +21,24 @@ internal static partial class Helper20250306 {
|
||||
logger.LogWarning("<{columnTitlesLine}> is null", nameof(columnTitlesLine));
|
||||
else {
|
||||
string? text = ProcessDataStandardFormatToLastDataLine(lines, columnTitlesLine.Value);
|
||||
File.WriteAllText(".lbl", text);
|
||||
File.WriteAllText(Path.Combine(".vscode", "helper", ".lbl"), text);
|
||||
if (lines.Length < columnTitlesLine.Value + 1)
|
||||
logger.LogWarning("<{lines}>(s)", lines.Length);
|
||||
else {
|
||||
string json = ProcessDataStandardFormatToJson(columnTitlesLine.Value, [], lines);
|
||||
File.WriteAllText(".json", json);
|
||||
File.WriteAllText(Path.Combine(".vscode", "helper", ".json"), json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int? GetProcessDataStandardFormatColumnTitlesLine(string[] lines) {
|
||||
int? result = null;
|
||||
bool foundEndOfFile = false;
|
||||
for (int i = 0; i < lines.Length; i++) {
|
||||
if (lines[i].StartsWith("END_OFFSET") && i + 2 < lines.Length) {
|
||||
result = i + 1;
|
||||
if (lines[i] == "EOF")
|
||||
foundEndOfFile = true;
|
||||
if (foundEndOfFile && lines[i].StartsWith("END_OFFSET") && i + 3 < lines.Length) {
|
||||
result = i + 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -46,7 +49,7 @@ internal static partial class Helper20250306 {
|
||||
string? result = null;
|
||||
for (int i = columnTitlesLine + 1; i < lines.Length; i++) {
|
||||
if (lines[i].StartsWith("NUM_DATA_ROWS")) {
|
||||
result = lines[i - 1];
|
||||
result = lines[i - 2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -60,12 +63,13 @@ internal static partial class Helper20250306 {
|
||||
string value;
|
||||
string[] segments;
|
||||
if (columns.Length == 0)
|
||||
columns = lines[columnTitlesLine].Trim().Split('\t');
|
||||
columns = lines[columnTitlesLine].Trim().Split('|');
|
||||
int columnsLength = columns.Length - 2;
|
||||
for (int i = columnTitlesLine + 1; i < lines.Length; i++) {
|
||||
line = "{";
|
||||
segments = lines[i].Trim().Split('\t');
|
||||
if (segments.Length != columns.Length)
|
||||
break;
|
||||
segments = lines[i].Trim().Split('|');
|
||||
if (segments.Length != columnsLength)
|
||||
continue;
|
||||
for (int c = 1; c < segments.Length; c++) {
|
||||
value = segments[c].Replace("\"", "\\\"").Replace("\\", "\\\\");
|
||||
line += '"' + columns[c].Trim('"') + '"' + ':' + '"' + value + '"' + ',';
|
||||
@ -73,7 +77,7 @@ internal static partial class Helper20250306 {
|
||||
line = line.Substring(0, line.Length - 1) + '}' + ',' + '\n';
|
||||
result += line;
|
||||
}
|
||||
result = result.Substring(0, result.Length - 1) + ']';
|
||||
result = result.Substring(0, result.Length - 2) + ']';
|
||||
return result;
|
||||
#pragma warning restore CA1845, IDE0057
|
||||
}
|
||||
|
Reference in New Issue
Block a user