/// <summary> /// Returns a random Unicode String. /// </summary> /// <param name="random">A random number generator.</param> /// <param name="length">The length.</param> /// <returns></returns> public static string RandomUnicodeString(Random random, int length) { if (length <= 0) { throw new ArgumentOutOfRangeException("length"); } StringBuilder sb = new StringBuilder(length); UnicodeSemantics us = new UnicodeSemantics(); // all ranges ok for (int i = 0; i < length; i++) { int candidate; // will not generate all possible uints, but the one we exclude are not interesting for purpose. do { candidate = random.Next((int)us.MinValue, (int)us.MaxValue); } while (!us.IsInRange((uint)candidate)); sb.Append((char)candidate); } return sb.ToString(); }
/// <summary> /// Returns true if the specified uint maps to a valid Unicode character in the ranges specified. /// </summary> /// <param name="value">The value.</param> /// <param name="validRanges">A series of <see cref="UnicodeRange"/> to match the value against.</param> /// <returns> /// True if the code is in one of the ranges, False otherwise. /// </returns> public static bool IsInRange(uint value, params UnicodeRange[] validRanges) { UnicodeSemantics us = new UnicodeSemantics(validRanges); return(us.IsInRange(value)); }
/// <summary> /// Returns true if the specified uint maps to a valid Unicode character in the ranges specified. /// </summary> /// <param name="value">The value.</param> /// <param name="validRanges">A series of <see cref="UnicodeRange"/> to match the value against.</param> /// <returns> /// True if the code is in one of the ranges, False otherwise. /// </returns> public static bool IsInRange(uint value, params UnicodeRange[] validRanges) { UnicodeSemantics us = new UnicodeSemantics(validRanges); return us.IsInRange(value); }