public static List <FMDItem> ReadMd(string fmd, string floder) { MdFloder = floder; fmd = fmd.Replace(@"\#", "#"); List <FMDItem> infos = new List <FMDItem>(); string[] lines = fmd.Split(new[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (!string.IsNullOrEmpty(line) && !line.StartsWith("//")) { TempItem = new FMDItem(); TempItem.Url = _patterns[EPattern.EUrl].Match(line); bool isHasUrl = !string.IsNullOrEmpty(TempItem.Url); string h1 = _patterns[EPattern.EH1].Match(line); if (!string.IsNullOrEmpty(h1)) { if (isHasUrl) { TempItem.H1 = _patterns[EPattern.EUrlH].Match(line); } else { TempItem.H1 = h1; } } string imgUrl = _patterns[EPattern.EImgUrl].Match(line); if (imgUrl != null) { TempItem.H1 = "==="; TempItem.IsImage = true; TempItem.Url = imgUrl; } //RemapURL(); if (string.IsNullOrEmpty(TempItem.H1)) { if (isHasUrl) { TempItem.H2 = _patterns[EPattern.EUrlH].Match(line); } else { TempItem.H2 = _patterns[EPattern.EH2].Match(line); } bool isNext = true; int index = i + 1; while (isNext) { if (index < lines.Length) { string dec2 = _patterns[EPattern.EDec1].Match(lines[index]); if (!string.IsNullOrEmpty(dec2)) { if (string.IsNullOrEmpty(TempItem.Description)) { TempItem.Description = $" {dec2}"; } else { TempItem.Description = $"{TempItem.Description}\r\n {dec2}"; } index++; } else { isNext = false; } } else { isNext = false; } } i = index - 1; } if (!TempItem.IsNull()) { TempItem.Description = ReferenceUtil.ParseCustomFuhao(TempItem.Description); infos.Add(TempItem); } } } return(infos); }
public static List <CSVItem> ReadCsv(string csv) { List <CSVItem> infos = new List <CSVItem>(); string[] lines = csv.Split(new[] { "\r\n" }, StringSplitOptions.None); Queue <char> fuhao = new Queue <char>(); var properties = typeof(CSVItem).GetProperties(); var fields = typeof(CSVItem).GetFields(); string[] patterns = new string[fields.Length + properties.Length]; StringBuilder builder = new StringBuilder(); if (lines != null) { lines[0] = null; } int index = 0; foreach (var line in lines) { index = 0; builder.Clear(); fuhao.Clear(); if (string.IsNullOrEmpty(line)) { continue; } for (int i = 0; i < line.Length; i++) { switch (line[i]) { case '\"': if (fuhao.Count > 0) { fuhao.Dequeue(); } else { fuhao.Enqueue('\"'); } break; case ',': if (fuhao.Count > 0) { builder.Append(line[i]); } else { patterns[index] = builder.ToString(); index++; builder.Clear(); } break; default: builder.Append(line[i]); break; } if (i == line.Length - 1) { patterns[index] = builder.ToString(); index = 0; builder.Clear(); } } var info = new CSVItem() { H1 = patterns[0], H2 = patterns[1], Description = patterns[2], Url = patterns[3], }; info.Description = ReferenceUtil.ParseCustomFuhao(info.Description); infos.Add(info); } return(infos); }