Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4179057

String UTF-8 Encoding of null char ('\u0000')

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.5
    • core-libs



      Name: tb29552 Date: 10/06/98


      /*
      The code in String which converts to UTF-8
      has two problems:

      1. It does not handle the null
         char ('\u0000') correctly.
         The null char is mapped to the null byte,
         according to the Unicode standard version 2.0.
         The code here allocated two bytes for it.

      2. Why it's not public? I need it and I have to
         copy the code.
      */

      /**
       * Returns the length of this string's UTF encoded form.
       */
      int utfLength() {
          int limit = offset + count;
          int utflen = 0;
          for (int i = offset; i < limit; i++) {
              int c = value[i];
              if ((c >= 0x0001) && (c <= 0x007F)) {
                  utflen++;
              } else if (c > 0x07FF) {
                  utflen += 3;
              } else {
                  utflen += 2;
              }
          }
          return utflen;
      }

      (Review ID: 28739)
      ======================================================================

            sherman Xueming Shen
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: