code: public static boolean isLegal(String str)
      {
          int size = str.length();
          int codepoint;
          for (int i = 0; i < size; i += Character.charCount(codepoint))
          {
              codepoint = str.codePointAt(i);
              if (!isLegal(codepoint)) {
                  return false;
              }
          }
          return true;
      }
docs: <strong>[icu]</strong> A string is legal iff all its code points are legal.
  A code point is illegal if and only if
  <ul>
  <li> Out of bounds, less than 0 or greater than UCharacter.MAX_VALUE
  <li> A surrogate value, 0xD800 to 0xDFFF
  <li> Not-a-character, having the form 0x xxFFFF or 0x xxFFFE
  </ul>
  Note: legal does not mean that it is assigned in this version of Unicode.
  @param str containing code points to examin
  @return true if and only if legal.