small improvements
This commit is contained in:
parent
861346456c
commit
5e8f9d8485
@ -7,12 +7,8 @@ namespace DTLib
|
|||||||
// вывод лога в консоль и файл
|
// вывод лога в консоль и файл
|
||||||
public class DefaultLogger
|
public class DefaultLogger
|
||||||
{
|
{
|
||||||
public DefaultLogger() { }
|
|
||||||
public DefaultLogger(string logfile) => Logfile = logfile;
|
public DefaultLogger(string logfile) => Logfile = logfile;
|
||||||
public DefaultLogger(string dir, string programName) => SetLogfile(dir, programName);
|
public DefaultLogger(string dir, string programName) => Logfile = $"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_');
|
||||||
|
|
||||||
public void SetLogfile(string dir, string programName)
|
|
||||||
=> Logfile = $"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_');
|
|
||||||
|
|
||||||
public string Logfile { get; set; }
|
public string Logfile { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -39,6 +39,9 @@ namespace DTLib
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool StartsWith(this string s, char c) => s[0] == c;
|
||||||
|
public static bool EndsWith(this string s, char c) => s[s.Length-1] == c;
|
||||||
|
|
||||||
// Math.Truncate принимает как decimal, так и doublе,
|
// Math.Truncate принимает как decimal, так и doublе,
|
||||||
// из-за чего вызов метода так: Math.Truncate(10/3) выдаст ошибку "неоднозначный вызов"
|
// из-за чего вызов метода так: Math.Truncate(10/3) выдаст ошибку "неоднозначный вызов"
|
||||||
public static int Truncate<T>(this T number) => Math.Truncate(number.ToDouble()).ToInt();
|
public static int Truncate<T>(this T number) => Math.Truncate(number.ToDouble()).ToInt();
|
||||||
@ -190,6 +193,37 @@ namespace DTLib
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// правильно реагирует на кавычки
|
||||||
|
public static List<string> SplitToList(this string s, char c, char quot)
|
||||||
|
{
|
||||||
|
List<string> output = new();
|
||||||
|
var list = s.SplitToList(c);
|
||||||
|
bool q_open = false;
|
||||||
|
for (int i = 0; i < list.Count; i++)
|
||||||
|
{
|
||||||
|
var _s = list[i];
|
||||||
|
if (q_open)
|
||||||
|
{
|
||||||
|
if (_s.EndsWith(quot))
|
||||||
|
{
|
||||||
|
q_open = false;
|
||||||
|
_s=_s.Remove(_s.Length - 1);
|
||||||
|
}
|
||||||
|
output[output.Count - 1] += c + _s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_s.StartsWith(quot))
|
||||||
|
{
|
||||||
|
q_open = true;
|
||||||
|
_s = _s.Remove(0, 1);
|
||||||
|
}
|
||||||
|
output.Add(_s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
// разбивает на части указанной длины
|
// разбивает на части указанной длины
|
||||||
public static List<string> Split(this string s, int length)
|
public static List<string> Split(this string s, int length)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user