PageRenderTime 52ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/JavApi/java/lang/Character.cs

#
C# | 1255 lines | 636 code | 64 blank | 555 comment | 179 complexity | b15749d4e58a4f6cbfecfc703f4b5653 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14. using System;
  15. using java = biz.ritter.javapi;
  16. using org.apache.harmony.luni.util;
  17. namespace biz.ritter.javapi.lang
  18. {
  19. public class Character
  20. {
  21. /**
  22. * Unicode category constant Lu.
  23. */
  24. public const byte UPPERCASE_LETTER = 1;
  25. /**
  26. * Unicode category constant Lo.
  27. */
  28. public const byte OTHER_LETTER = 5;
  29. /**
  30. * Returns the lower case equivalent for the specified character if the
  31. * character is an upper case letter. Otherwise, the specified character is
  32. * returned unchanged.
  33. *
  34. * @param c
  35. * the character
  36. * @return if {@code c} is an upper case character then its lower case
  37. * counterpart, otherwise just {@code c}.
  38. */
  39. public static char toLowerCase(char c)
  40. {
  41. return System.Char.ToLower(c);
  42. }
  43. public static char toUpperCase(char c)
  44. {
  45. return System.Char.ToUpper(c);
  46. }
  47. /**
  48. * Indicates whether the specified character is an upper case letter.
  49. *
  50. * @param c
  51. * the character to check.
  52. * @return {@code true} if {@code c} is a upper case letter; {@code false}
  53. * otherwise.
  54. */
  55. public static bool isUpperCase(char c)
  56. {
  57. // Optimized case for ASCII
  58. if ('A' <= c && c <= 'Z')
  59. {
  60. return true;
  61. }
  62. if (c < 128)
  63. {
  64. return false;
  65. }
  66. return System.Char.IsUpper(c);
  67. //return getType(c) == UPPERCASE_LETTER;
  68. }
  69. private readonly char value;
  70. /**
  71. * Constructs a new {@code Character} with the specified primitive char
  72. * value.
  73. *
  74. * @param value
  75. * the primitive char value to store in the new instance.
  76. */
  77. public Character(char value)
  78. {
  79. this.value = value;
  80. }
  81. /**
  82. * Gets the primitive value of this character.
  83. *
  84. * @return this object's primitive value.
  85. */
  86. public char charValue()
  87. {
  88. return value;
  89. }
  90. /**
  91. * The {@link Class} object that represents the primitive type {@code char}.
  92. */
  93. public static readonly Type TYPE = new char[0].GetType().GetElementType();
  94. private static readonly String digitKeys = "0Aa\u0660\u06f0\u0966\u09e6\u0a66\u0ae6\u0b66\u0be7\u0c66\u0ce6\u0d66\u0e50\u0ed0\u0f20\u1040\u1369\u17e0\u1810\uff10\uff21\uff41";
  95. // Unicode 3.0.1 (same as Unicode 3.0.0)
  96. private static readonly String typeKeys = "\u0000 \"$&(*-/1:<?A[]_a{}\u007f\u00a0\u00a2\u00a6\u00a8\u00aa\u00ac\u00ae\u00b1\u00b3\u00b5\u00b7\u00b9\u00bb\u00bd\u00bf\u00c1\u00d7\u00d9\u00df\u00f7\u00f9\u0100\u0138\u0149\u0179\u017f\u0181\u0183\u0187\u018a\u018c\u018e\u0192\u0194\u0197\u0199\u019c\u019e\u01a0\u01a7\u01ab\u01af\u01b2\u01b4\u01b8\u01ba\u01bc\u01be\u01c0\u01c4\u01c6\u01c8\u01ca\u01cc\u01dd\u01f0\u01f2\u01f4\u01f7\u01f9\u0222\u0250\u02b0\u02b9\u02bb\u02c2\u02d0\u02d2\u02e0\u02e5\u02ee\u0300\u0360\u0374\u037a\u037e\u0384\u0386\u0389\u038c\u038e\u0390\u0392\u03a3\u03ac\u03d0\u03d2\u03d5\u03da\u03f0\u0400\u0430\u0460\u0482\u0484\u0488\u048c\u04c1\u04c7\u04cb\u04d0\u04f8\u0531\u0559\u055b\u0561\u0589\u0591\u05a3\u05bb\u05be\u05c2\u05d0\u05f0\u05f3\u060c\u061b\u061f\u0621\u0640\u0642\u064b\u0660\u066a\u0670\u0672\u06d4\u06d6\u06dd\u06df\u06e5\u06e7\u06e9\u06eb\u06f0\u06fa\u06fd\u0700\u070f\u0711\u0713\u0730\u0780\u07a6\u0901\u0903\u0905\u093c\u093e\u0941\u0949\u094d\u0950\u0952\u0958\u0962\u0964\u0966\u0970\u0981\u0983\u0985\u098f\u0993\u09aa\u09b2\u09b6\u09bc\u09be\u09c1\u09c7\u09cb\u09cd\u09d7\u09dc\u09df\u09e2\u09e6\u09f0\u09f2\u09f4\u09fa\u0a02\u0a05\u0a0f\u0a13\u0a2a\u0a32\u0a35\u0a38\u0a3c\u0a3e\u0a41\u0a47\u0a4b\u0a59\u0a5e\u0a66\u0a70\u0a72\u0a81\u0a83\u0a85\u0a8d\u0a8f\u0a93\u0aaa\u0ab2\u0ab5\u0abc\u0abe\u0ac1\u0ac7\u0ac9\u0acb\u0acd\u0ad0\u0ae0\u0ae6\u0b01\u0b03\u0b05\u0b0f\u0b13\u0b2a\u0b32\u0b36\u0b3c\u0b3e\u0b42\u0b47\u0b4b\u0b4d\u0b56\u0b5c\u0b5f\u0b66\u0b70\u0b82\u0b85\u0b8e\u0b92\u0b99\u0b9c\u0b9e\u0ba3\u0ba8\u0bae\u0bb7\u0bbe\u0bc0\u0bc2\u0bc6\u0bca\u0bcd\u0bd7\u0be7\u0bf0\u0c01\u0c05\u0c0e\u0c12\u0c2a\u0c35\u0c3e\u0c41\u0c46\u0c4a\u0c55\u0c60\u0c66\u0c82\u0c85\u0c8e\u0c92\u0caa\u0cb5\u0cbe\u0cc1\u0cc6\u0cc8\u0cca\u0ccc\u0cd5\u0cde\u0ce0\u0ce6\u0d02\u0d05\u0d0e\u0d12\u0d2a\u0d3e\u0d41\u0d46\u0d4a\u0d4d\u0d57\u0d60\u0d66\u0d82\u0d85\u0d9a\u0db3\u0dbd\u0dc0\u0dca\u0dcf\u0dd2\u0dd6\u0dd8\u0df2\u0df4\u0e01\u0e31\u0e33\u0e35\u0e3f\u0e41\u0e46\u0e48\u0e4f\u0e51\u0e5a\u0e81\u0e84\u0e87\u0e8a\u0e8d\u0e94\u0e99\u0ea1\u0ea5\u0ea7\u0eaa\u0ead\u0eb1\u0eb3\u0eb5\u0ebb\u0ebd\u0ec0\u0ec6\u0ec8\u0ed0\u0edc\u0f00\u0f02\u0f04\u0f13\u0f18\u0f1a\u0f20\u0f2a\u0f34\u0f3a\u0f3e\u0f40\u0f49\u0f71\u0f7f\u0f81\u0f85\u0f87\u0f89\u0f90\u0f99\u0fbe\u0fc6\u0fc8\u0fcf\u1000\u1023\u1029\u102c\u102e\u1031\u1036\u1038\u1040\u104a\u1050\u1056\u1058\u10a0\u10d0\u10fb\u1100\u115f\u11a8\u1200\u1208\u1248\u124a\u1250\u1258\u125a\u1260\u1288\u128a\u1290\u12b0\u12b2\u12b8\u12c0\u12c2\u12c8\u12d0\u12d8\u12f0\u1310\u1312\u1318\u1320\u1348\u1361\u1369\u1372\u13a0\u1401\u166d\u166f\u1680\u1682\u169b\u16a0\u16eb\u16ee\u1780\u17b4\u17b7\u17be\u17c6\u17c8\u17ca\u17d4\u17db\u17e0\u1800\u1806\u1808\u180b\u1810\u1820\u1843\u1845\u1880\u18a9\u1e00\u1e96\u1ea0\u1f00\u1f08\u1f10\u1f18\u1f20\u1f28\u1f30\u1f38\u1f40\u1f48\u1f50\u1f59\u1f5b\u1f5d\u1f5f\u1f61\u1f68\u1f70\u1f80\u1f88\u1f90\u1f98\u1fa0\u1fa8\u1fb0\u1fb6\u1fb8\u1fbc\u1fbe\u1fc0\u1fc2\u1fc6\u1fc8\u1fcc\u1fce\u1fd0\u1fd6\u1fd8\u1fdd\u1fe0\u1fe8\u1fed\u1ff2\u1ff6\u1ff8\u1ffc\u1ffe\u2000\u200c\u2010\u2016\u2018\u201a\u201c\u201e\u2020\u2028\u202a\u202f\u2031\u2039\u203b\u203f\u2041\u2044\u2046\u2048\u206a\u2070\u2074\u207a\u207d\u207f\u2081\u208a\u208d\u20a0\u20d0\u20dd\u20e1\u20e3\u2100\u2102\u2104\u2107\u2109\u210b\u210e\u2110\u2113\u2115\u2117\u2119\u211e\u2124\u212b\u212e\u2130\u2132\u2134\u2136\u2139\u2153\u2160\u2190\u2195\u219a\u219c\u21a0\u21a2\u21a5\u21a8\u21ae\u21b0\u21ce\u21d0\u21d2\u21d6\u2200\u2300\u2308\u230c\u2320\u2322\u2329\u232b\u237d\u2400\u2440\u2460\u249c\u24ea\u2500\u25a0\u25b7\u25b9\u25c1\u25c3\u2600\u2619\u266f\u2671\u2701\u2706\u270c\u2729\u274d\u274f\u2756\u2758\u2761\u2776\u2794\u2798\u27b1\u2800\u2e80\u2e9b\u2f00\u2ff0\u3000\u3002\u3004\u3006\u3008\u3012\u3014\u301c\u301e\u3020\u3022\u302a\u3030\u3032\u3036\u3038\u303e\u3041\u3099\u309b\u309d\u30a1\u30fb\u30fd\u3105\u3131\u3190\u3192\u3196\u31a0\u3200\u3220\u322a\u3260\u327f\u3281\u328a\u32c0\u32d0\u3300\u337b\u33e0\u3400\u4e00\ua000\ua490\ua4a4\ua4b5\ua4c2\ua4c6\uac00\ud800\ue000\uf900\ufb00\ufb13\ufb1d\ufb20\ufb29\ufb2b\ufb38\ufb3e\ufb40\ufb43\ufb46\ufbd3\ufd3e\ufd50\ufd92\ufdf0\ufe20\ufe30\ufe32\ufe34\ufe36\ufe49\ufe4d\ufe50\ufe54\ufe58\ufe5a\ufe5f\ufe62\ufe65\ufe68\ufe6b\ufe70\ufe74\ufe76\ufeff\uff01\uff04\uff06\uff08\uff0a\uff0d\uff0f\uff11\uff1a\uff1c\uff1f\uff21\uff3b\uff3d\uff3f\uff41\uff5b\uff5d\uff61\uff63\uff65\uff67\uff70\uff72\uff9e\uffa0\uffc2\uffca\uffd2\uffda\uffe0\uffe2\uffe4\uffe6\uffe8\uffea\uffed\ufff9\ufffc";
  97. private static readonly char[] typeValues = "\u001f\u000f!\u180c#\u0018%\u181a'\u0018)\u1615,\u1918.\u14180\u18099\t;\u0018>\u0019@\u0018Z\u0001\\\u1518^\u161b`\u171bz\u0002|\u1519~\u1619\u009f\u000f\u00a1\u180c\u00a5\u001a\u00a7\u001c\u00a9\u1c1b\u00ab\u1d02\u00ad\u1419\u00b0\u1b1c\u00b2\u190b\u00b4\u0b1b\u00b6\u021c\u00b8\u181b\u00ba\u0b02\u00bc\u1e0b\u00be\u000b\u00c0\u1801\u00d6\u0001\u00d8\u1901\u00de\u0001\u00f6\u0002\u00f8\u1902\u00ff\u0002\u0137\u0201\u0148\u0102\u0178\u0201\u017e\u0102\u0180\u0002\u0182\u0001\u0186\u0201\u0189\u0102\u018b\u0001\u018d\u0002\u0191\u0001\u0193\u0102\u0196\u0201\u0198\u0001\u019b\u0002\u019d\u0001\u019f\u0102\u01a6\u0201\u01aa\u0102\u01ae\u0201\u01b1\u0102\u01b3\u0001\u01b7\u0102\u01b9\u0201\u01bb\u0502\u01bd\u0201\u01bf\u0002\u01c3\u0005\u01c5\u0301\u01c7\u0102\u01c9\u0203\u01cb\u0301\u01dc\u0102\u01ef\u0201\u01f1\u0102\u01f3\u0203\u01f6\u0201\u01f8\u0001\u021f\u0201\u0233\u0201\u02ad\u0002\u02b8\u0004\u02ba\u001b\u02c1\u0004\u02cf\u001b\u02d1\u0004\u02df\u001b\u02e4\u0004\u02ed\u001b\u02ee\u0004\u034e\u0006\u0362\u0006\u0375\u001b\u037a\u0004\u037e\u0018\u0385\u001b\u0388\u1801\u038a\u0001\u038c\u0001\u038f\u0001\u0391\u0102\u03a1\u0001\u03ab\u0001\u03ce\u0002\u03d1\u0002\u03d4\u0001\u03d7\u0002\u03ef\u0201\u03f3\u0002\u042f\u0001\u045f\u0002\u0481\u0201\u0483\u061c\u0486\u0006\u0489\u0007\u04c0\u0201\u04c4\u0102\u04c8\u0102\u04cc\u0102\u04f5\u0201\u04f9\u0201\u0556\u0001\u055a\u0418\u055f\u0018\u0587\u0002\u058a\u1814\u05a1\u0006\u05b9\u0006\u05bd\u0006\u05c1\u0618\u05c4\u1806\u05ea\u0005\u05f2\u0005\u05f4\u0018\u060c\u0018\u061b\u1800\u061f\u1800\u063a\u0005\u0641\u0504\u064a\u0005\u0655\u0006\u0669\t\u066d\u0018\u0671\u0506\u06d3\u0005\u06d5\u0518\u06dc\u0006\u06de\u0007\u06e4\u0006\u06e6\u0004\u06e8\u0006\u06ea\u1c06\u06ed\u0006\u06f9\t\u06fc\u0005\u06fe\u001c\u070d\u0018\u0710\u1005\u0712\u0605\u072c\u0005\u074a\u0006\u07a5\u0005\u07b0\u0006\u0902\u0006\u0903\u0800\u0939\u0005\u093d\u0506\u0940\b\u0948\u0006\u094c\b\u094d\u0600\u0951\u0605\u0954\u0006\u0961\u0005\u0963\u0006\u0965\u0018\u096f\t\u0970\u0018\u0982\u0608\u0983\u0800\u098c\u0005\u0990\u0005\u09a8\u0005\u09b0\u0005\u09b2\u0005\u09b9\u0005\u09bc\u0006\u09c0\b\u09c4\u0006\u09c8\b\u09cc\b\u09cd\u0600\u09d7\u0800\u09dd\u0005\u09e1\u0005\u09e3\u0006\u09ef\t\u09f1\u0005\u09f3\u001a\u09f9\u000b\u09fa\u001c\u0a02\u0006\u0a0a\u0005\u0a10\u0005\u0a28\u0005\u0a30\u0005\u0a33\u0005\u0a36\u0005\u0a39\u0005\u0a3c\u0006\u0a40\b\u0a42\u0006\u0a48\u0006\u0a4d\u0006\u0a5c\u0005\u0a5e\u0005\u0a6f\t\u0a71\u0006\u0a74\u0005\u0a82\u0006\u0a83\u0800\u0a8b\u0005\u0a8d\u0500\u0a91\u0005\u0aa8\u0005\u0ab0\u0005\u0ab3\u0005\u0ab9\u0005\u0abd\u0506\u0ac0\b\u0ac5\u0006\u0ac8\u0006\u0ac9\u0800\u0acc\b\u0acd\u0600\u0ad0\u0005\u0ae0\u0005\u0aef\t\u0b02\u0608\u0b03\u0800\u0b0c\u0005\u0b10\u0005\u0b28\u0005\u0b30\u0005\u0b33\u0005\u0b39\u0005\u0b3d\u0506\u0b41\u0608\u0b43\u0006\u0b48\b\u0b4c\b\u0b4d\u0600\u0b57\u0806\u0b5d\u0005\u0b61\u0005\u0b6f\t\u0b70\u001c\u0b83\u0806\u0b8a\u0005\u0b90\u0005\u0b95\u0005\u0b9a\u0005\u0b9c\u0005\u0b9f\u0005\u0ba4\u0005\u0baa\u0005\u0bb5\u0005\u0bb9\u0005\u0bbf\b\u0bc1\u0806\u0bc2\b\u0bc8\b\u0bcc\b\u0bcd\u0600\u0bd7\u0800\u0bef\t\u0bf2\u000b\u0c03\b\u0c0c\u0005\u0c10\u0005\u0c28\u0005\u0c33\u0005\u0c39\u0005\u0c40\u0006\u0c44\b\u0c48\u0006\u0c4d\u0006\u0c56\u0006\u0c61\u0005\u0c6f\t\u0c83\b\u0c8c\u0005\u0c90\u0005\u0ca8\u0005\u0cb3\u0005\u0cb9\u0005\u0cc0\u0608\u0cc4\b\u0cc7\u0806\u0cc8\b\u0ccb\b\u0ccd\u0006\u0cd6\b\u0cde\u0005\u0ce1\u0005\u0cef\t\u0d03\b\u0d0c\u0005\u0d10\u0005\u0d28\u0005\u0d39\u0005\u0d40\b\u0d43\u0006\u0d48\b\u0d4c\b\u0d4d\u0600\u0d57\u0800\u0d61\u0005\u0d6f\t\u0d83\b\u0d96\u0005\u0db1\u0005\u0dbb\u0005\u0dbd\u0500\u0dc6\u0005\u0dca\u0006\u0dd1\b\u0dd4\u0006\u0dd6\u0006\u0ddf\b\u0df3\b\u0df4\u0018\u0e30\u0005\u0e32\u0605\u0e34\u0506\u0e3a\u0006\u0e40\u1a05\u0e45\u0005\u0e47\u0604\u0e4e\u0006\u0e50\u1809\u0e59\t\u0e5b\u0018\u0e82\u0005\u0e84\u0005\u0e88\u0005\u0e8a\u0005\u0e8d\u0500\u0e97\u0005\u0e9f\u0005\u0ea3\u0005\u0ea5\u0500\u0ea7\u0500\u0eab\u0005\u0eb0\u0005\u0eb2\u0605\u0eb4\u0506\u0eb9\u0006\u0ebc\u0006\u0ebd\u0500\u0ec4\u0005\u0ec6\u0004\u0ecd\u0006\u0ed9\t\u0edd\u0005\u0f01\u1c05\u0f03\u001c\u0f12\u0018\u0f17\u001c\u0f19\u0006\u0f1f\u001c\u0f29\t\u0f33\u000b\u0f39\u061c\u0f3d\u1615\u0f3f\b\u0f47\u0005\u0f6a\u0005\u0f7e\u0006\u0f80\u0806\u0f84\u0006\u0f86\u1806\u0f88\u0605\u0f8b\u0005\u0f97\u0006\u0fbc\u0006\u0fc5\u001c\u0fc7\u1c06\u0fcc\u001c\u0fcf\u1c00\u1021\u0005\u1027\u0005\u102a\u0005\u102d\u0608\u1030\u0006\u1032\u0806\u1037\u0006\u1039\u0608\u1049\t\u104f\u0018\u1055\u0005\u1057\b\u1059\u0006\u10c5\u0001\u10f6\u0005\u10fb\u1800\u1159\u0005\u11a2\u0005\u11f9\u0005\u1206\u0005\u1246\u0005\u1248\u0005\u124d\u0005\u1256\u0005\u1258\u0005\u125d\u0005\u1286\u0005\u1288\u0005\u128d\u0005\u12ae\u0005\u12b0\u0005\u12b5\u0005\u12be\u0005\u12c0\u0005\u12c5\u0005\u12ce\u0005\u12d6\u0005\u12ee\u0005\u130e\u0005\u1310\u0005\u1315\u0005\u131e\u0005\u1346\u0005\u135a\u0005\u1368\u0018\u1371\t\u137c\u000b\u13f4\u0005\u166c\u0005\u166e\u0018\u1676\u0005\u1681\u050c\u169a\u0005\u169c\u1516\u16ea\u0005\u16ed\u0018\u16f0\u000b\u17b3\u0005\u17b6\b\u17bd\u0006\u17c5\b\u17c7\u0806\u17c9\u0608\u17d3\u0006\u17da\u0018\u17dc\u1a18\u17e9\t\u1805\u0018\u1807\u1814\u180a\u0018\u180e\u0010\u1819\t\u1842\u0005\u1844\u0405\u1877\u0005\u18a8\u0005\u18a9\u0600\u1e95\u0201\u1e9b\u0002\u1ef9\u0201\u1f07\u0002\u1f0f\u0001\u1f15\u0002\u1f1d\u0001\u1f27\u0002\u1f2f\u0001\u1f37\u0002\u1f3f\u0001\u1f45\u0002\u1f4d\u0001\u1f57\u0002\u1f59\u0100\u1f5b\u0100\u1f5d\u0100\u1f60\u0102\u1f67\u0002\u1f6f\u0001\u1f7d\u0002\u1f87\u0002\u1f8f\u0003\u1f97\u0002\u1f9f\u0003\u1fa7\u0002\u1faf\u0003\u1fb4\u0002\u1fb7\u0002\u1fbb\u0001\u1fbd\u1b03\u1fbf\u1b02\u1fc1\u001b\u1fc4\u0002\u1fc7\u0002\u1fcb\u0001\u1fcd\u1b03\u1fcf\u001b\u1fd3\u0002\u1fd7\u0002\u1fdb\u0001\u1fdf\u001b\u1fe7\u0002\u1fec\u0001\u1fef\u001b\u1ff4\u0002\u1ff7\u0002\u1ffb\u0001\u1ffd\u1b03\u1ffe\u001b\u200b\f\u200f\u0010\u2015\u0014\u2017\u0018\u2019\u1e1d\u201b\u1d15\u201d\u1e1d\u201f\u1d15\u2027\u0018\u2029\u0e0d\u202e\u0010\u2030\u0c18\u2038\u0018\u203a\u1d1e\u203e\u0018\u2040\u0017\u2043\u0018\u2045\u1519\u2046\u0016\u204d\u0018\u206f\u0010\u2070\u000b\u2079\u000b\u207c\u0019\u207e\u1516\u2080\u020b\u2089\u000b\u208c\u0019\u208e\u1516\u20af\u001a\u20dc\u0006\u20e0\u0007\u20e2\u0607\u20e3\u0700\u2101\u001c\u2103\u1c01\u2106\u001c\u2108\u011c\u210a\u1c02\u210d\u0001\u210f\u0002\u2112\u0001\u2114\u021c\u2116\u011c\u2118\u001c\u211d\u0001\u2123\u001c\u212a\u1c01\u212d\u0001\u212f\u021c\u2131\u0001\u2133\u011c\u2135\u0502\u2138\u0005\u213a\u021c\u215f\u000b\u2183\n\u2194\u0019\u2199\u001c\u219b\u0019\u219f\u001c\u21a1\u1c19\u21a4\u191c\u21a7\u1c19\u21ad\u001c\u21af\u1c19\u21cd\u001c\u21cf\u0019\u21d1\u001c\u21d5\u1c19\u21f3\u001c\u22f1\u0019\u2307\u001c\u230b\u0019\u231f\u001c\u2321\u0019\u2328\u001c\u232a\u1516\u237b\u001c\u239a\u001c\u2426\u001c\u244a\u001c\u249b\u000b\u24e9\u001c\u24ea\u000b\u2595\u001c\u25b6\u001c\u25b8\u191c\u25c0\u001c\u25c2\u191c\u25f7\u001c\u2613\u001c\u266e\u001c\u2670\u191c\u2671\u1c00\u2704\u001c\u2709\u001c\u2727\u001c\u274b\u001c\u274d\u1c00\u2752\u001c\u2756\u001c\u275e\u001c\u2767\u001c\u2793\u000b\u2794\u001c\u27af\u001c\u27be\u001c\u28ff\u001c\u2e99\u001c\u2ef3\u001c\u2fd5\u001c\u2ffb\u001c\u3001\u180c\u3003\u0018\u3005\u041c\u3007\u0a05\u3011\u1615\u3013\u001c\u301b\u1615\u301d\u1514\u301f\u0016\u3021\u0a1c\u3029\n\u302f\u0006\u3031\u0414\u3035\u0004\u3037\u001c\u303a\n\u303f\u001c\u3094\u0005\u309a\u0006\u309c\u001b\u309e\u0004\u30fa\u0005\u30fc\u1704\u30fe\u0004\u312c\u0005\u318e\u0005\u3191\u001c\u3195\u000b\u319f\u001c\u31b7\u0005\u321c\u001c\u3229\u000b\u3243\u001c\u327b\u001c\u3280\u1c0b\u3289\u000b\u32b0\u001c\u32cb\u001c\u32fe\u001c\u3376\u001c\u33dd\u001c\u33fe\u001c\u4db5\u0005\u9fa5\u0005\ua48c\u0005\ua4a1\u001c\ua4b3\u001c\ua4c0\u001c\ua4c4\u001c\ua4c6\u001c\ud7a3\u0005\udfff\u0013\uf8ff\u0012\ufa2d\u0005\ufb06\u0002\ufb17\u0002\ufb1f\u0506\ufb28\u0005\ufb2a\u1905\ufb36\u0005\ufb3c\u0005\ufb3e\u0005\ufb41\u0005\ufb44\u0005\ufbb1\u0005\ufd3d\u0005\ufd3f\u1615\ufd8f\u0005\ufdc7\u0005\ufdfb\u0005\ufe23\u0006\ufe31\u1418\ufe33\u1714\ufe35\u1517\ufe44\u1516\ufe4c\u0018\ufe4f\u0017\ufe52\u0018\ufe57\u0018\ufe59\u1514\ufe5e\u1516\ufe61\u0018\ufe64\u1419\ufe66\u0019\ufe6a\u1a18\ufe6b\u1800\ufe72\u0005\ufe74\u0005\ufefc\u0005\ufeff\u1000\uff03\u0018\uff05\u181a\uff07\u0018\uff09\u1615\uff0c\u1918\uff0e\u1418\uff10\u1809\uff19\t\uff1b\u0018\uff1e\u0019\uff20\u0018\uff3a\u0001\uff3c\u1518\uff3e\u161b\uff40\u171b\uff5a\u0002\uff5c\u1519\uff5e\u1619\uff62\u1815\uff64\u1618\uff66\u1705\uff6f\u0005\uff71\u0504\uff9d\u0005\uff9f\u0004\uffbe\u0005\uffc7\u0005\uffcf\u0005\uffd7\u0005\uffdc\u0005\uffe1\u001a\uffe3\u1b19\uffe5\u1a1c\uffe6\u001a\uffe9\u191c\uffec\u0019\uffee\u001c\ufffb\u0010\ufffd\u001c"
  98. .getValue();
  99. /**
  100. * Unicode category constant Cn.
  101. */
  102. public const byte UNASSIGNED = 0;
  103. /**
  104. * Unicode category constant Nd.
  105. */
  106. public const byte DECIMAL_DIGIT_NUMBER = 9;
  107. /**
  108. * The minimum value of a supplementary code point, {@code U+010000}.
  109. *
  110. * @since 1.5
  111. */
  112. public static readonly int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
  113. /**
  114. * The minimum code point value, {@code U+0000}.
  115. *
  116. * @since 1.5
  117. */
  118. public static readonly int MIN_CODE_POINT = 0x000000;
  119. /**
  120. * The maximum code point value, {@code U+10FFFF}.
  121. *
  122. * @since 1.5
  123. */
  124. public static readonly int MAX_CODE_POINT = 0x10FFFF;
  125. /**
  126. * The minimum value of a high surrogate or leading surrogate unit in UTF-16
  127. * encoding, {@code '\uD800'}.
  128. *
  129. * @since 1.5
  130. */
  131. public static readonly char MIN_HIGH_SURROGATE = '\uD800';
  132. private static readonly char[] digitValues = "90Z7zW\u0669\u0660\u06f9\u06f0\u096f\u0966\u09ef\u09e6\u0a6f\u0a66\u0aef\u0ae6\u0b6f\u0b66\u0bef\u0be6\u0c6f\u0c66\u0cef\u0ce6\u0d6f\u0d66\u0e59\u0e50\u0ed9\u0ed0\u0f29\u0f20\u1049\u1040\u1371\u1368\u17e9\u17e0\u1819\u1810\uff19\uff10\uff3a\uff17\uff5a\uff37".ToCharArray();
  133. /**
  134. * The maximum value of a high surrogate or leading surrogate unit in UTF-16
  135. * encoding, {@code '\uDBFF'}.
  136. *
  137. * @since 1.5
  138. */
  139. public static readonly char MAX_HIGH_SURROGATE = '\uDBFF';
  140. /**
  141. * The minimum value of a low surrogate or trailing surrogate unit in UTF-16
  142. * encoding, {@code '\uDC00'}.
  143. *
  144. * @since 1.5
  145. */
  146. public static readonly char MIN_LOW_SURROGATE = '\uDC00';
  147. /**
  148. * The maximum value of a low surrogate or trailing surrogate unit in UTF-16
  149. * encoding, {@code '\uDFFF'}.
  150. *
  151. * @since 1.5
  152. */
  153. public static readonly char MAX_LOW_SURROGATE = '\uDFFF';
  154. /**
  155. * The minimum value of a surrogate unit in UTF-16 encoding, {@code '\uD800'}.
  156. *
  157. * @since 1.5
  158. */
  159. public static readonly char MIN_SURROGATE = '\uD800';
  160. /**
  161. * The minimum {@code Character} value.
  162. */
  163. public static readonly char MIN_VALUE = char.MinValue;
  164. /**
  165. * The maximum {@code Character} value.
  166. */
  167. public static readonly char MAX_VALUE = char.MaxValue;
  168. /**
  169. * The minimum radix used for conversions between characters and integers.
  170. */
  171. public static readonly int MIN_RADIX = 2;
  172. /**
  173. * The maximum radix used for conversions between characters and integers.
  174. */
  175. public static readonly int MAX_RADIX = 36;
  176. /**
  177. * Returns the character which represents the specified digit in the
  178. * specified radix. The {@code radix} must be between {@code MIN_RADIX} and
  179. * {@code MAX_RADIX} inclusive; {@code digit} must not be negative and
  180. * smaller than {@code radix}. If any of these conditions does not hold, 0
  181. * is returned.
  182. *
  183. * @param digit
  184. * the integer value.
  185. * @param radix
  186. * the radix.
  187. * @return the character which represents the {@code digit} in the
  188. * {@code radix}.
  189. */
  190. public static char forDigit(int digit, int radix)
  191. {
  192. if (MIN_RADIX <= radix && radix <= MAX_RADIX)
  193. {
  194. if (0 <= digit && digit < radix)
  195. {
  196. return (char)(digit < 10 ? digit + '0' : digit + 'a' - 10);
  197. }
  198. }
  199. return '\u0000';
  200. }
  201. /**
  202. * Convenience method to determine the value of the specified character
  203. * {@code c} in the supplied radix. The value of {@code radix} must be
  204. * between MIN_RADIX and MAX_RADIX.
  205. *
  206. * @param c
  207. * the character to determine the value of.
  208. * @param radix
  209. * the radix.
  210. * @return the value of {@code c} in {@code radix} if {@code radix} lies
  211. * between {@link #MIN_RADIX} and {@link #MAX_RADIX}; -1 otherwise.
  212. */
  213. public static int digit(char c, int radix)
  214. {
  215. if (radix >= MIN_RADIX && radix <= MAX_RADIX)
  216. {
  217. if (c < 128)
  218. {
  219. // Optimized for ASCII
  220. int result = -1;
  221. if ('0' <= c && c <= '9')
  222. {
  223. result = c - '0';
  224. }
  225. else if ('a' <= c && c <= 'z')
  226. {
  227. result = c - ('a' - 10);
  228. }
  229. else if ('A' <= c && c <= 'Z')
  230. {
  231. result = c - ('A' - 10);
  232. }
  233. return result < radix ? result : -1;
  234. }
  235. int result1 = BinarySearch.binarySearchRange(digitKeys, c);
  236. if (result1 >= 0 && c <= digitValues[result1 * 2])
  237. {
  238. int value = (char)(c - digitValues[result1 * 2 + 1]);
  239. if (value >= radix)
  240. {
  241. return -1;
  242. }
  243. return value;
  244. }
  245. }
  246. return -1;
  247. }
  248. /**
  249. * Indicates whether the specified character is a Java space.
  250. *
  251. * @param c
  252. * the character to check.
  253. * @return {@code true} if {@code c} is a Java space; {@code false}
  254. * otherwise.
  255. * @deprecated Use {@link #isWhitespace(char)}
  256. */
  257. [Obsolete]
  258. public static bool isSpace(char c)
  259. {
  260. return c == '\n' || c == '\t' || c == '\f' || c == '\r' || c == ' ';
  261. }
  262. /**
  263. * Indicates whether the specified character is a Unicode space character.
  264. * That is, if it is a member of one of the Unicode categories Space
  265. * Separator, Line Separator, or Paragraph Separator.
  266. *
  267. * @param c
  268. * the character to check.
  269. * @return {@code true} if {@code c} is a Unicode space character,
  270. * {@code false} otherwise.
  271. */
  272. public static bool isSpaceChar(char c)
  273. {
  274. if (c == 0x20 || c == 0xa0 || c == 0x1680)
  275. {
  276. return true;
  277. }
  278. if (c < 0x2000)
  279. {
  280. return false;
  281. }
  282. return c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x202f
  283. || c == 0x3000;
  284. }
  285. /**
  286. * Indicates whether the specified character is a whitespace character in
  287. * Java.
  288. *
  289. * @param c
  290. * the character to check.
  291. * @return {@code true} if the supplied {@code c} is a whitespace character
  292. * in Java; {@code false} otherwise.
  293. */
  294. public static bool isWhitespace(char c)
  295. {
  296. // Optimized case for ASCII
  297. if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd))
  298. {
  299. return true;
  300. }
  301. if (c == 0x1680)
  302. {
  303. return true;
  304. }
  305. if (c < 0x2000 || c == 0x2007)
  306. {
  307. return false;
  308. }
  309. return c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x3000;
  310. }
  311. /**
  312. * Indicates whether the specified character is an ISO control character.
  313. *
  314. * @param c
  315. * the character to check.
  316. * @return {@code true} if {@code c} is an ISO control character;
  317. * {@code false} otherwise.
  318. */
  319. public static bool isISOControl(char c)
  320. {
  321. return isISOControl((int)c);
  322. }
  323. /**
  324. * Indicates whether the specified code point is an ISO control character.
  325. *
  326. * @param c
  327. * the code point to check.
  328. * @return {@code true} if {@code c} is an ISO control character;
  329. * {@code false} otherwise.
  330. */
  331. public static bool isISOControl(int c)
  332. {
  333. return (c >= 0 && c <= 0x1f) || (c >= 0x7f && c <= 0x9f);
  334. }
  335. /**
  336. * Returns the code point at {@code index} in the specified sequence of
  337. * character units. If the unit at {@code index} is a high-surrogate unit,
  338. * {@code index + 1} is less than the length of the sequence and the unit at
  339. * {@code index + 1} is a low-surrogate unit, then the supplementary code
  340. * point represented by the pair is returned; otherwise the {@code char}
  341. * value at {@code index} is returned.
  342. *
  343. * @param seq
  344. * the source sequence of {@code char} units.
  345. * @param index
  346. * the position in {@code seq} from which to retrieve the code
  347. * point.
  348. * @return the Unicode code point or {@code char} value at {@code index} in
  349. * {@code seq}.
  350. * @throws NullPointerException
  351. * if {@code seq} is {@code null}.
  352. * @throws IndexOutOfBoundsException
  353. * if the {@code index} is negative or greater than or equal to
  354. * the length of {@code seq}.
  355. * @since 1.5
  356. */
  357. public static int codePointAt(CharSequence seq, int index)
  358. {
  359. if (seq == null)
  360. {
  361. throw new java.lang.NullPointerException();
  362. }
  363. int len = seq.length();
  364. if (index < 0 || index >= len)
  365. {
  366. throw new IndexOutOfBoundsException();
  367. }
  368. char high = seq.charAt(index++);
  369. if (index >= len)
  370. {
  371. return high;
  372. }
  373. char low = seq.charAt(index);
  374. if (isSurrogatePair(high, low))
  375. {
  376. return toCodePoint(high, low);
  377. }
  378. return high;
  379. }
  380. /**
  381. * Returns the code point at {@code index} in the specified array of
  382. * character units. If the unit at {@code index} is a high-surrogate unit,
  383. * {@code index + 1} is less than the length of the array and the unit at
  384. * {@code index + 1} is a low-surrogate unit, then the supplementary code
  385. * point represented by the pair is returned; otherwise the {@code char}
  386. * value at {@code index} is returned.
  387. *
  388. * @param seq
  389. * the source array of {@code char} units.
  390. * @param index
  391. * the position in {@code seq} from which to retrieve the code
  392. * point.
  393. * @return the Unicode code point or {@code char} value at {@code index} in
  394. * {@code seq}.
  395. * @throws NullPointerException
  396. * if {@code seq} is {@code null}.
  397. * @throws IndexOutOfBoundsException
  398. * if the {@code index} is negative or greater than or equal to
  399. * the length of {@code seq}.
  400. * @since 1.5
  401. */
  402. public static int codePointAt(char[] seq, int index)
  403. {
  404. if (seq == null)
  405. {
  406. throw new java.lang.NullPointerException();
  407. }
  408. int len = seq.Length;
  409. if (index < 0 || index >= len)
  410. {
  411. throw new IndexOutOfBoundsException();
  412. }
  413. char high = seq[index++];
  414. if (index >= len)
  415. {
  416. return high;
  417. }
  418. char low = seq[index];
  419. if (isSurrogatePair(high, low))
  420. {
  421. return toCodePoint(high, low);
  422. }
  423. return high;
  424. }
  425. /**
  426. * Returns the code point at {@code index} in the specified array of
  427. * character units, where {@code index} has to be less than {@code limit}.
  428. * If the unit at {@code index} is a high-surrogate unit, {@code index + 1}
  429. * is less than {@code limit} and the unit at {@code index + 1} is a
  430. * low-surrogate unit, then the supplementary code point represented by the
  431. * pair is returned; otherwise the {@code char} value at {@code index} is
  432. * returned.
  433. *
  434. * @param seq
  435. * the source array of {@code char} units.
  436. * @param index
  437. * the position in {@code seq} from which to get the code point.
  438. * @param limit
  439. * the index after the last unit in {@code seq} that can be used.
  440. * @return the Unicode code point or {@code char} value at {@code index} in
  441. * {@code seq}.
  442. * @throws NullPointerException
  443. * if {@code seq} is {@code null}.
  444. * @throws IndexOutOfBoundsException
  445. * if {@code index < 0}, {@code index >= limit},
  446. * {@code limit < 0} or if {@code limit} is greater than the
  447. * length of {@code seq}.
  448. * @since 1.5
  449. */
  450. public static int codePointAt(char[] seq, int index, int limit)
  451. {
  452. if (index < 0 || index >= limit || limit < 0 || limit > seq.Length)
  453. {
  454. throw new IndexOutOfBoundsException();
  455. }
  456. char high = seq[index++];
  457. if (index >= limit)
  458. {
  459. return high;
  460. }
  461. char low = seq[index];
  462. if (isSurrogatePair(high, low))
  463. {
  464. return toCodePoint(high, low);
  465. }
  466. return high;
  467. }
  468. /**
  469. * Indicates whether the specified character pair is a valid surrogate pair.
  470. *
  471. * @param high
  472. * the high surrogate unit to test.
  473. * @param low
  474. * the low surrogate unit to test.
  475. * @return {@code true} if {@code high} is a high-surrogate code unit and
  476. * {@code low} is a low-surrogate code unit; {@code false}
  477. * otherwise.
  478. * @see #isHighSurrogate(char)
  479. * @see #isLowSurrogate(char)
  480. * @since 1.5
  481. */
  482. public static bool isSurrogatePair(char high, char low)
  483. {
  484. return (isHighSurrogate(high) && isLowSurrogate(low));
  485. }
  486. /**
  487. * Indicates whether {@code ch} is a high- (or leading-) surrogate code unit
  488. * that is used for representing supplementary characters in UTF-16
  489. * encoding.
  490. *
  491. * @param ch
  492. * the character to test.
  493. * @return {@code true} if {@code ch} is a high-surrogate code unit;
  494. * {@code false} otherwise.
  495. * @see #isLowSurrogate(char)
  496. * @since 1.5
  497. */
  498. public static bool isHighSurrogate(char ch)
  499. {
  500. return (MIN_HIGH_SURROGATE <= ch && MAX_HIGH_SURROGATE >= ch);
  501. }
  502. /**
  503. * Indicates whether {@code ch} is a low- (or trailing-) surrogate code unit
  504. * that is used for representing supplementary characters in UTF-16
  505. * encoding.
  506. *
  507. * @param ch
  508. * the character to test.
  509. * @return {@code true} if {@code ch} is a low-surrogate code unit;
  510. * {@code false} otherwise.
  511. * @see #isHighSurrogate(char)
  512. * @since 1.5
  513. */
  514. public static bool isLowSurrogate(char ch)
  515. {
  516. return (MIN_LOW_SURROGATE <= ch && MAX_LOW_SURROGATE >= ch);
  517. }
  518. /**
  519. * Converts a surrogate pair into a Unicode code point. This method assumes
  520. * that the pair are valid surrogates. If the pair are <i>not</i> valid
  521. * surrogates, then the result is indeterminate. The
  522. * {@link #isSurrogatePair(char, char)} method should be used prior to this
  523. * method to validate the pair.
  524. *
  525. * @param high
  526. * the high surrogate unit.
  527. * @param low
  528. * the low surrogate unit.
  529. * @return the Unicode code point corresponding to the surrogate unit pair.
  530. * @see #isSurrogatePair(char, char)
  531. * @since 1.5
  532. */
  533. public static int toCodePoint(char high, char low)
  534. {
  535. // See RFC 2781, Section 2.2
  536. // http://www.faqs.org/rfcs/rfc2781.html
  537. int h = (high & 0x3FF) << 10;
  538. int l = low & 0x3FF;
  539. return (h | l) + 0x10000;
  540. }
  541. /**
  542. * Returns the code point that preceds {@code index} in the specified
  543. * sequence of character units. If the unit at {@code index - 1} is a
  544. * low-surrogate unit, {@code index - 2} is not negative and the unit at
  545. * {@code index - 2} is a high-surrogate unit, then the supplementary code
  546. * point represented by the pair is returned; otherwise the {@code char}
  547. * value at {@code index - 1} is returned.
  548. *
  549. * @param seq
  550. * the source sequence of {@code char} units.
  551. * @param index
  552. * the position in {@code seq} following the code
  553. * point that should be returned.
  554. * @return the Unicode code point or {@code char} value before {@code index}
  555. * in {@code seq}.
  556. * @throws NullPointerException
  557. * if {@code seq} is {@code null}.
  558. * @throws IndexOutOfBoundsException
  559. * if the {@code index} is less than 1 or greater than the
  560. * length of {@code seq}.
  561. * @since 1.5
  562. */
  563. public static int codePointBefore(CharSequence seq, int index)
  564. {
  565. if (seq == null)
  566. {
  567. throw new java.lang.NullPointerException();
  568. }
  569. int len = seq.length();
  570. if (index < 1 || index > len)
  571. {
  572. throw new IndexOutOfBoundsException();
  573. }
  574. char low = seq.charAt(--index);
  575. if (--index < 0)
  576. {
  577. return low;
  578. }
  579. char high = seq.charAt(index);
  580. if (isSurrogatePair(high, low))
  581. {
  582. return toCodePoint(high, low);
  583. }
  584. return low;
  585. }
  586. /**
  587. * Returns the code point that preceds {@code index} in the specified
  588. * array of character units. If the unit at {@code index - 1} is a
  589. * low-surrogate unit, {@code index - 2} is not negative and the unit at
  590. * {@code index - 2} is a high-surrogate unit, then the supplementary code
  591. * point represented by the pair is returned; otherwise the {@code char}
  592. * value at {@code index - 1} is returned.
  593. *
  594. * @param seq
  595. * the source array of {@code char} units.
  596. * @param index
  597. * the position in {@code seq} following the code
  598. * point that should be returned.
  599. * @return the Unicode code point or {@code char} value before {@code index}
  600. * in {@code seq}.
  601. * @throws NullPointerException
  602. * if {@code seq} is {@code null}.
  603. * @throws IndexOutOfBoundsException
  604. * if the {@code index} is less than 1 or greater than the
  605. * length of {@code seq}.
  606. * @since 1.5
  607. */
  608. public static int codePointBefore(char[] seq, int index)
  609. {
  610. if (seq == null)
  611. {
  612. throw new java.lang.NullPointerException();
  613. }
  614. int len = seq.Length;
  615. if (index < 1 || index > len)
  616. {
  617. throw new IndexOutOfBoundsException();
  618. }
  619. char low = seq[--index];
  620. if (--index < 0)
  621. {
  622. return low;
  623. }
  624. char high = seq[index];
  625. if (isSurrogatePair(high, low))
  626. {
  627. return toCodePoint(high, low);
  628. }
  629. return low;
  630. }
  631. /**
  632. * Returns the code point that preceds the {@code index} in the specified
  633. * array of character units and is not less than {@code start}. If the unit
  634. * at {@code index - 1} is a low-surrogate unit, {@code index - 2} is not
  635. * less than {@code start} and the unit at {@code index - 2} is a
  636. * high-surrogate unit, then the supplementary code point represented by the
  637. * pair is returned; otherwise the {@code char} value at {@code index - 1}
  638. * is returned.
  639. *
  640. * @param seq
  641. * the source array of {@code char} units.
  642. * @param index
  643. * the position in {@code seq} following the code point that
  644. * should be returned.
  645. * @param start
  646. * the index of the first element in {@code seq}.
  647. * @return the Unicode code point or {@code char} value before {@code index}
  648. * in {@code seq}.
  649. * @throws NullPointerException
  650. * if {@code seq} is {@code null}.
  651. * @throws IndexOutOfBoundsException
  652. * if the {@code index <= start}, {@code start < 0},
  653. * {@code index} is greater than the length of {@code seq}, or
  654. * if {@code start} is equal or greater than the length of
  655. * {@code seq}.
  656. * @since 1.5
  657. */
  658. public static int codePointBefore(char[] seq, int index, int start)
  659. {
  660. if (seq == null)
  661. {
  662. throw new java.lang.NullPointerException();
  663. }
  664. int len = seq.Length;
  665. if (index <= start || index > len || start < 0 || start >= len)
  666. {
  667. throw new IndexOutOfBoundsException();
  668. }
  669. char low = seq[--index];
  670. if (--index < start)
  671. {
  672. return low;
  673. }
  674. char high = seq[index];
  675. if (isSurrogatePair(high, low))
  676. {
  677. return toCodePoint(high, low);
  678. }
  679. return low;
  680. }
  681. /**
  682. * Counts the number of Unicode code points in the subsequence of the
  683. * specified character sequence, as delineated by {@code beginIndex} and
  684. * {@code endIndex}. Any surrogate values with missing pair values will be
  685. * counted as one code point.
  686. *
  687. * @param seq
  688. * the {@code CharSequence} to look through.
  689. * @param beginIndex
  690. * the inclusive index to begin counting at.
  691. * @param endIndex
  692. * the exclusive index to stop counting at.
  693. * @return the number of Unicode code points.
  694. * @throws NullPointerException
  695. * if {@code seq} is {@code null}.
  696. * @throws IndexOutOfBoundsException
  697. * if {@code beginIndex < 0}, {@code beginIndex > endIndex} or
  698. * if {@code endIndex} is greater than the length of {@code seq}.
  699. * @since 1.5
  700. */
  701. public static int codePointCount(CharSequence seq, int beginIndex,
  702. int endIndex)
  703. {
  704. if (seq == null)
  705. {
  706. throw new java.lang.NullPointerException();
  707. }
  708. int len = seq.length();
  709. if (beginIndex < 0 || endIndex > len || beginIndex > endIndex)
  710. {
  711. throw new IndexOutOfBoundsException();
  712. }
  713. int result = 0;
  714. for (int i = beginIndex; i < endIndex; i++)
  715. {
  716. char c = seq.charAt(i);
  717. if (isHighSurrogate(c))
  718. {
  719. if (++i < endIndex)
  720. {
  721. c = seq.charAt(i);
  722. if (!isLowSurrogate(c))
  723. {
  724. result++;
  725. }
  726. }
  727. }
  728. result++;
  729. }
  730. return result;
  731. }
  732. /**
  733. * Counts the number of Unicode code points in the subsequence of the
  734. * specified char array, as delineated by {@code offset} and {@code count}.
  735. * Any surrogate values with missing pair values will be counted as one code
  736. * point.
  737. *
  738. * @param seq
  739. * the char array to look through
  740. * @param offset
  741. * the inclusive index to begin counting at.
  742. * @param count
  743. * the number of {@code char} values to look through in
  744. * {@code seq}.
  745. * @return the number of Unicode code points.
  746. * @throws NullPointerException
  747. * if {@code seq} is {@code null}.
  748. * @throws IndexOutOfBoundsException
  749. * if {@code offset < 0}, {@code count < 0} or if
  750. * {@code offset + count} is greater than the length of
  751. * {@code seq}.
  752. * @since 1.5
  753. */
  754. public static int codePointCount(char[] seq, int offset, int count)
  755. {
  756. if (seq == null)
  757. {
  758. throw new java.lang.NullPointerException();
  759. }
  760. int len = seq.Length;
  761. int endIndex = offset + count;
  762. if (offset < 0 || count < 0 || endIndex > len)
  763. {
  764. throw new IndexOutOfBoundsException();
  765. }
  766. int result = 0;
  767. for (int i = offset; i < endIndex; i++)
  768. {
  769. char c = seq[i];
  770. if (isHighSurrogate(c))
  771. {
  772. if (++i < endIndex)
  773. {
  774. c = seq[i];
  775. if (!isLowSurrogate(c))
  776. {
  777. result++;
  778. }
  779. }
  780. }
  781. result++;
  782. }
  783. return result;
  784. }
  785. /**
  786. * Determines the index in the specified character sequence that is offset
  787. * {@code codePointOffset} code points from {@code index}.
  788. *
  789. * @param seq
  790. * the character sequence to find the index in.
  791. * @param index
  792. * the start index in {@code seq}.
  793. * @param codePointOffset
  794. * the number of code points to look backwards or forwards; may
  795. * be a negative or positive value.
  796. * @return the index in {@code seq} that is {@code codePointOffset} code
  797. * points away from {@code index}.
  798. * @throws NullPointerException
  799. * if {@code seq} is {@code null}.
  800. * @throws IndexOutOfBoundsException
  801. * if {@code index < 0}, {@code index} is greater than the
  802. * length of {@code seq}, or if there are not enough values in
  803. * {@code seq} to skip {@code codePointOffset} code points
  804. * forwards or backwards (if {@code codePointOffset} is
  805. * negative) from {@code index}.
  806. * @since 1.5
  807. */
  808. public static int offsetByCodePoints(CharSequence seq, int index,
  809. int codePointOffset)
  810. {
  811. if (seq == null)
  812. {
  813. throw new java.lang.NullPointerException();
  814. }
  815. int len = seq.length();
  816. if (index < 0 || index > len)
  817. {
  818. throw new IndexOutOfBoundsException();
  819. }
  820. if (codePointOffset == 0)
  821. {
  822. return index;
  823. }
  824. if (codePointOffset > 0)
  825. {
  826. int codePoints = codePointOffset;
  827. int i = index;
  828. while (codePoints > 0)
  829. {
  830. codePoints--;
  831. if (i >= len)
  832. {
  833. throw new IndexOutOfBoundsException();
  834. }
  835. if (isHighSurrogate(seq.charAt(i)))
  836. {
  837. int next = i + 1;
  838. if (next < len && isLowSurrogate(seq.charAt(next)))
  839. {
  840. i++;
  841. }
  842. }
  843. i++;
  844. }
  845. return i;
  846. }
  847. //assert codePointOffset < 0;
  848. int codePoints2 = -codePointOffset;
  849. int i2 = index;
  850. while (codePoints2 > 0)
  851. {
  852. codePoints2--;
  853. i2--;
  854. if (i2 < 0)
  855. {
  856. throw new IndexOutOfBoundsException();
  857. }
  858. if (isLowSurrogate(seq.charAt(i2)))
  859. {
  860. int prev = i2 - 1;
  861. if (prev >= 0 && isHighSurrogate(seq.charAt(prev)))
  862. {
  863. i2--;
  864. }
  865. }
  866. }
  867. return i2;
  868. }
  869. /**
  870. * Determines the index in a subsequence of the specified character array
  871. * that is offset {@code codePointOffset} code points from {@code index}.
  872. * The subsequence is delineated by {@code start} and {@code count}.
  873. *
  874. * @param seq
  875. * the character array to find the index in.
  876. * @param start
  877. * the inclusive index that marks the beginning of the
  878. * subsequence.
  879. * @param count
  880. * the number of {@code char} values to include within the
  881. * subsequence.
  882. * @param index
  883. * the start index in the subsequence of the char array.
  884. * @param codePointOffset
  885. * the number of code points to look backwards or forwards; may
  886. * be a negative or positive value.
  887. * @return the index in {@code seq} that is {@code codePointOffset} code
  888. * points away from {@code index}.
  889. * @throws NullPointerException
  890. * if {@code seq} is {@code null}.
  891. * @throws IndexOutOfBoundsException
  892. * if {@code start < 0}, {@code count < 0},
  893. * {@code index < start}, {@code index > start + count},
  894. * {@code start + count} is greater than the length of
  895. * {@code seq}, or if there are not enough values in
  896. * {@code seq} to skip {@code codePointOffset} code points
  897. * forward or backward (if {@code codePointOffset} is
  898. * negative) from {@code index}.
  899. * @since 1.5
  900. */
  901. public static int offsetByCodePoints(char[] seq, int start, int count,
  902. int index, int codePointOffset)
  903. {
  904. if (seq == null)
  905. {
  906. throw new java.lang.NullPointerException();
  907. }
  908. int end = start + count;
  909. if (start < 0 || count < 0 || end > seq.Length || index < start
  910. || index > end)
  911. {
  912. throw new IndexOutOfBoundsException();
  913. }
  914. if (codePointOffset == 0)
  915. {
  916. return index;
  917. }
  918. if (codePointOffset > 0)
  919. {
  920. int codePoints = codePointOffset;
  921. int i = index;
  922. while (codePoints > 0)
  923. {
  924. codePoints--;
  925. if (i >= end)
  926. {
  927. throw new IndexOutOfBoundsException();
  928. }
  929. if (isHighSurrogate(seq[i]))
  930. {
  931. int next = i + 1;
  932. if (next < end && isLowSurrogate(seq[next]))
  933. {
  934. i++;
  935. }
  936. }
  937. i++;
  938. }
  939. return i;
  940. }
  941. //assert codePointOffset < 0;
  942. int codePoints2 = -codePointOffset;
  943. int i2 = index;
  944. while (codePoints2 > 0)
  945. {
  946. codePoints2--;
  947. i2--;
  948. if (i2 < start)
  949. {
  950. throw new IndexOutOfBoundsException();
  951. }
  952. if (isLowSurrogate(seq[i2]))
  953. {
  954. int prev = i2 - 1;
  955. if (prev >= start && isHighSurrogate(seq[prev]))

Large files files are truncated, but you can click here to view the full file