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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.1.5
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description



      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)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: