From 5e8f9d848563d817cb46372e2cb3eeee2d882d7f Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Sat, 13 Nov 2021 22:50:30 +0300 Subject: [PATCH] small improvements --- DefaultLogger.cs | 6 +----- FrameworkFix.cs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/DefaultLogger.cs b/DefaultLogger.cs index a53241f..7072a2a 100644 --- a/DefaultLogger.cs +++ b/DefaultLogger.cs @@ -7,12 +7,8 @@ namespace DTLib // вывод лога в консоль и файл public class DefaultLogger { - public DefaultLogger() { } public DefaultLogger(string logfile) => Logfile = logfile; - public DefaultLogger(string dir, string programName) => SetLogfile(dir, programName); - - public void SetLogfile(string dir, string programName) - => Logfile = $"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_'); + public DefaultLogger(string dir, string programName) => Logfile = $"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_'); public string Logfile { get; set; } diff --git a/FrameworkFix.cs b/FrameworkFix.cs index f155dc4..eb95206 100644 --- a/FrameworkFix.cs +++ b/FrameworkFix.cs @@ -39,6 +39,9 @@ namespace DTLib 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(10/3) выдаст ошибку "неоднозначный вызов" public static int Truncate(this T number) => Math.Truncate(number.ToDouble()).ToInt(); @@ -190,6 +193,37 @@ namespace DTLib return o; } + // правильно реагирует на кавычки + public static List SplitToList(this string s, char c, char quot) + { + List 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 Split(this string s, int length) {