< prev index next >

src/share/classes/java/util/regex/Pattern.java

Print this page
rev 12216 : imported patch 8169056-StringIndexOutOfBoundsException-in-Pattern-compile-with-CANON_EQ-flag
   1 /*
   2  * Copyright (c) 1999, 2013, 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


1394                 newPattern.appendCodePoint(c);
1395             }
1396             lastCodePoint = c;
1397             i += Character.charCount(c);
1398         }
1399         normalizedPattern = newPattern.toString();
1400     }
1401 
1402     /**
1403      * Complete the character class being parsed and add a set
1404      * of alternations to it that will match the canonical equivalences
1405      * of the characters within the class.
1406      */
1407     private int normalizeCharClass(StringBuilder newPattern, int i) {
1408         StringBuilder charClass = new StringBuilder();
1409         StringBuilder eq = null;
1410         int lastCodePoint = -1;
1411         String result;
1412 
1413         i++;


1414         charClass.append("[");
1415         while(true) {
1416             int c = normalizedPattern.codePointAt(i);
1417             StringBuilder sequenceBuffer;
1418 
1419             if (c == ']' && lastCodePoint != '\\') {
1420                 charClass.append((char)c);
1421                 break;
1422             } else if (Character.getType(c) == Character.NON_SPACING_MARK) {
1423                 sequenceBuffer = new StringBuilder();
1424                 sequenceBuffer.appendCodePoint(lastCodePoint);
1425                 while(Character.getType(c) == Character.NON_SPACING_MARK) {
1426                     sequenceBuffer.appendCodePoint(c);
1427                     i += Character.charCount(c);
1428                     if (i >= normalizedPattern.length())
1429                         break;
1430                     c = normalizedPattern.codePointAt(i);
1431                 }
1432                 String ea = produceEquivalentAlternation(
1433                                                   sequenceBuffer.toString());


   1 /*
   2  * Copyright (c) 1999, 2017, 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


1394                 newPattern.appendCodePoint(c);
1395             }
1396             lastCodePoint = c;
1397             i += Character.charCount(c);
1398         }
1399         normalizedPattern = newPattern.toString();
1400     }
1401 
1402     /**
1403      * Complete the character class being parsed and add a set
1404      * of alternations to it that will match the canonical equivalences
1405      * of the characters within the class.
1406      */
1407     private int normalizeCharClass(StringBuilder newPattern, int i) {
1408         StringBuilder charClass = new StringBuilder();
1409         StringBuilder eq = null;
1410         int lastCodePoint = -1;
1411         String result;
1412 
1413         i++;
1414         if (i == normalizedPattern.length())
1415             throw error("Unclosed character class");
1416         charClass.append("[");
1417         while(true) {
1418             int c = normalizedPattern.codePointAt(i);
1419             StringBuilder sequenceBuffer;
1420 
1421             if (c == ']' && lastCodePoint != '\\') {
1422                 charClass.append((char)c);
1423                 break;
1424             } else if (Character.getType(c) == Character.NON_SPACING_MARK) {
1425                 sequenceBuffer = new StringBuilder();
1426                 sequenceBuffer.appendCodePoint(lastCodePoint);
1427                 while(Character.getType(c) == Character.NON_SPACING_MARK) {
1428                     sequenceBuffer.appendCodePoint(c);
1429                     i += Character.charCount(c);
1430                     if (i >= normalizedPattern.length())
1431                         break;
1432                     c = normalizedPattern.codePointAt(i);
1433                 }
1434                 String ea = produceEquivalentAlternation(
1435                                                   sequenceBuffer.toString());


< prev index next >