20 lines
542 B
C#
20 lines
542 B
C#
namespace KronaStaffTerminal.Services;
|
|
|
|
public static class CsvCellEncoder
|
|
{
|
|
public static string Encode(string? value)
|
|
{
|
|
var safe = value ?? string.Empty;
|
|
var firstContent = safe.AsSpan().TrimStart();
|
|
if (firstContent.Length > 0 && firstContent[0] is '=' or '+' or '-' or '@')
|
|
{
|
|
safe = "'" + safe;
|
|
}
|
|
else if (safe.Length > 0 && safe[0] is '\t' or '\r' or '\n')
|
|
{
|
|
safe = "'" + safe;
|
|
}
|
|
|
|
return $"\"{safe.Replace("\"", "\"\"")}\"";
|
|
}
|
|
}
|