/** * Gets recursive decomposition of a character from the * Unicode Character Database. * @param canonical If true * bit is on in this byte, then selects the recursive * canonical decomposition, otherwise selects * the recursive compatibility and canonical decomposition. * @param ch the source character * @param buffer buffer to be filled with the decomposition */ public void GetRecursiveDecomposition(bool canonical, int ch, StringBuffer buffer) { string decomp = decompose.Get(ch); if (decomp != null && !(canonical && isCompatibility.SafeGet(ch))) { for (int i = 0; i < decomp.Length; i += UTF16Util.CodePointLength(ch)) { ch = UTF16Util.NextCodePoint(decomp, i); GetRecursiveDecomposition(canonical, ch, buffer); } } else { // if no decomp, append UTF16Util.AppendCodePoint(buffer, ch); } }
/** * Utility: Parses a sequence of hex Unicode characters separated by spaces */ static public String fromHex(String source) { StringBuffer result = new StringBuffer(); for (int i = 0; i < source.Length; ++i) { char c = source[i]; switch (c) { case ' ': break; // ignore case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': int end = 0; int value = 0; try { //Console.Out.WriteLine(source.substring(i, i + 4) + "************" + source); end = source.IndexOf(' ', i); if (end < 0) { end = source.Length; } value = int.Parse(source.Substring(i, end - i), NumberStyles.HexNumber, CultureInfo.InvariantCulture); // ICU4N: Corrected 2nd substring parameter UTF16Util.AppendCodePoint(result, value); } catch (Exception e) { Console.Out.WriteLine("i: " + i + ";end:" + end + "source:" + source); //Console.Out.WriteLine(source.substring(i, i + 4) + "************" + source); Environment.Exit(1); } //i+= 3; // skip rest of number i = end; break; case '<': int j = source.IndexOf('>', i); // skip <...> if (j > 0) { i = j; break; } // else fall through--error throw new ArgumentException("Bad hex value in " + source); default: throw new ArgumentException("Bad hex value in " + source); } } return(result.ToString()); }