public static List <CodeSection> ParseString(int codepage, string text) { List <UInt16> chars = new List <UInt16>(); List <CodeSection> list = new List <CodeSection>(); int first = 0, last = 0; int i; for (i = 0; i < text.Length; i++) { chars.Add(MySource.EncodingGetUint16(codepage, text.Substring(i, 1))); } for (i = 0; i < chars.Count; i++) { if (i == 0) { first = chars[i]; } else { if (chars[i] != chars[i - 1]) { last = chars[i - 1]; list.Add(new CodeSection(first, last)); first = chars[i]; } } } last = chars[i - 1]; list.Add(new CodeSection(first, last)); return(list); }
public static string CheckValid(string SourceType, int codepage, string text) { if (SourceType == SourceTypeConverter.SourceTypeSection) { List <CodeSection> list = CodeSection.Parse(text); text = ""; for (int i = 0; i < list.Count; i++) { if (i > 0) { text += ","; } if (list[i].range != null) { text += "0x" + list[i].range.first_hh.ToString("X2").ToUpper() + ":" + list[i].range.first_ll.ToString("X2").ToUpper() + "-" + "0x" + list[i].range.last_hh.ToString("X2").ToUpper() + ":" + list[i].range.last_ll.ToString("X2").ToUpper(); } else { text += "0x" + list[i].first.ToString("X4").ToUpper() + "-0x" + list[i].last.ToString("X4").ToUpper(); } } } else { List <UInt16> list = new List <UInt16>(); for (int i = 0; i < text.Length; i++) { string strTmp = text.Substring(i, 1); if (strTmp.Length > 0) { list.Add(MySource.EncodingGetUint16(codepage, strTmp)); } } list.Sort(); text = ""; for (int i = 0; i < list.Count; i++) { if (i > 0) { if (list[i] == list[i - 1]) { continue; } } text += MySource.EncodingGetString(codepage, list[i]); } } return(text); }