< prev index next >

src/java.base/share/classes/java/util/Properties.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 624         int end = off + len;
 625         int start = off;
 626         while (off < end) {
 627             aChar = in[off++];
 628             if (aChar == '\\') {
 629                 break;
 630             }
 631         }
 632         if (off == end) { // No backslash
 633             return new String(in, start, len);
 634         }
 635 
 636         // backslash found at off - 1, reset the shared buffer, rewind offset
 637         out.setLength(0);
 638         off--;
 639         out.append(in, start, off - start);
 640 
 641         while (off < end) {
 642             aChar = in[off++];
 643             if (aChar == '\\') {
 644                 // No need to bounds check since LineReader::readLine excludes
 645                 // unescaped \s at the end of the line
 646                 aChar = in[off++];
 647                 if(aChar == 'u') {
 648                     // Read the xxxx
 649                     if (off > end - 4)
 650                         throw new IllegalArgumentException(
 651                                      "Malformed \\uxxxx encoding.");
 652                     int value = 0;
 653                     for (int i = 0; i < 4; i++) {
 654                         aChar = in[off++];
 655                         switch (aChar) {
 656                           case '0': case '1': case '2': case '3': case '4':
 657                           case '5': case '6': case '7': case '8': case '9':
 658                              value = (value << 4) + aChar - '0';
 659                              break;
 660                           case 'a': case 'b': case 'c':
 661                           case 'd': case 'e': case 'f':
 662                              value = (value << 4) + 10 + aChar - 'a';
 663                              break;
 664                           case 'A': case 'B': case 'C':
 665                           case 'D': case 'E': case 'F':
 666                              value = (value << 4) + 10 + aChar - 'A';
 667                              break;
 668                           default:
 669                               throw new IllegalArgumentException(
 670                                            "Malformed \\uxxxx encoding.");
 671                         }
 672                     }
 673                     out.append((char)value);


   1 /*
   2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 624         int end = off + len;
 625         int start = off;
 626         while (off < end) {
 627             aChar = in[off++];
 628             if (aChar == '\\') {
 629                 break;
 630             }
 631         }
 632         if (off == end) { // No backslash
 633             return new String(in, start, len);
 634         }
 635 
 636         // backslash found at off - 1, reset the shared buffer, rewind offset
 637         out.setLength(0);
 638         off--;
 639         out.append(in, start, off - start);
 640 
 641         while (off < end) {
 642             aChar = in[off++];
 643             if (aChar == '\\') {


 644                 aChar = in[off++];
 645                 if(aChar == 'u') {
 646                     // Read the xxxx
 647                     int value=0;
 648                     for (int i=0; i<4; i++) {



 649                         aChar = in[off++];
 650                         switch (aChar) {
 651                           case '0': case '1': case '2': case '3': case '4':
 652                           case '5': case '6': case '7': case '8': case '9':
 653                              value = (value << 4) + aChar - '0';
 654                              break;
 655                           case 'a': case 'b': case 'c':
 656                           case 'd': case 'e': case 'f':
 657                              value = (value << 4) + 10 + aChar - 'a';
 658                              break;
 659                           case 'A': case 'B': case 'C':
 660                           case 'D': case 'E': case 'F':
 661                              value = (value << 4) + 10 + aChar - 'A';
 662                              break;
 663                           default:
 664                               throw new IllegalArgumentException(
 665                                            "Malformed \\uxxxx encoding.");
 666                         }
 667                     }
 668                     out.append((char)value);


< prev index next >