/// <summary> /// Creates a collection of character regions which represent all of the characters /// in the specified source text. /// </summary> /// <param name="text">The source text from which to create character regions.</param> /// <returns>The collection of character regions that was created.</returns> public static IEnumerable<CharacterRegion> CreateFromSourceText(String text) { Contract.Require(text, "text"); var regions = new List<CharacterRegion>(); var characters = (from c in text where !Char.IsSurrogate(c) && (!Char.IsWhiteSpace(c) || c == ' ') select c).Distinct().OrderBy(x => x).ToArray(); if (text != null && text.Length > 0) { var start = characters[0]; for (var i = 0; i < characters.Length; i++) { var next = (i + 1 >= characters.Length) ? (Char?)null : characters[i + 1]; var diff = (next.HasValue ? next.Value - characters[i] : Int32.MaxValue); if (diff != 1) { var region = new CharacterRegion(start, characters[i]); regions.Add(region); if (i + 1 < characters.Length) { start = characters[i + 1]; } } } } return regions.OrderBy(x => x.Start).ToList(); }
/// <summary> /// Creates a collection of character regions which represent all of the characters /// in the specified source text. /// </summary> /// <param name="text">The source text from which to create character regions.</param> /// <returns>The collection of character regions that was created.</returns> public static IEnumerable <CharacterRegion> CreateFromSourceText(String text) { Contract.Require(text, nameof(text)); var regions = new List <CharacterRegion>(); var characters = (from c in text where !Char.IsSurrogate(c) && (!Char.IsWhiteSpace(c) || c == ' ') select c).Distinct().OrderBy(x => x).ToArray(); if (text != null && text.Length > 0) { var start = characters[0]; for (var i = 0; i < characters.Length; i++) { var next = (i + 1 >= characters.Length) ? (Char?)null : characters[i + 1]; var diff = (next.HasValue ? next.Value - characters[i] : Int32.MaxValue); if (diff != 1) { var region = new CharacterRegion(start, characters[i]); regions.Add(region); if (i + 1 < characters.Length) { start = characters[i + 1]; } } } } return(regions.OrderBy(x => x.Start).ToList()); }