src/java.base/share/classes/java/util/regex/PatternSyntaxException.java
changeset 48944 25aa8b9f1dae
parent 47216 71c04702a3d5
child 51154 393f8a42190b
equal deleted inserted replaced
48943:e61816fc5276 48944:25aa8b9f1dae
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package java.util.regex;
    26 package java.util.regex;
    27 
       
    28 import sun.security.action.GetPropertyAction;
       
    29 
       
    30 
    27 
    31 /**
    28 /**
    32  * Unchecked exception thrown to indicate a syntax error in a
    29  * Unchecked exception thrown to indicate a syntax error in a
    33  * regular-expression pattern.
    30  * regular-expression pattern.
    34  *
    31  *
    91      */
    88      */
    92     public String getPattern() {
    89     public String getPattern() {
    93         return pattern;
    90         return pattern;
    94     }
    91     }
    95 
    92 
    96     private static final String nl =
       
    97             GetPropertyAction.privilegedGetProperty("line.separator");
       
    98 
       
    99     /**
    93     /**
   100      * Returns a multi-line string containing the description of the syntax
    94      * Returns a multi-line string containing the description of the syntax
   101      * error and its index, the erroneous regular-expression pattern, and a
    95      * error and its index, the erroneous regular-expression pattern, and a
   102      * visual indication of the error index within the pattern.
    96      * visual indication of the error index within the pattern.
   103      *
    97      *
   108         sb.append(desc);
   102         sb.append(desc);
   109         if (index >= 0) {
   103         if (index >= 0) {
   110             sb.append(" near index ");
   104             sb.append(" near index ");
   111             sb.append(index);
   105             sb.append(index);
   112         }
   106         }
   113         sb.append(nl);
   107         sb.append(System.lineSeparator());
   114         sb.append(pattern);
   108         sb.append(pattern);
   115         if (index >= 0) {
   109         if (index >= 0) {
   116             sb.append(nl);
   110             sb.append(System.lineSeparator());
   117             for (int i = 0; i < index; i++) sb.append(' ');
   111             for (int i = 0; i < index; i++) sb.append(' ');
   118             sb.append('^');
   112             sb.append('^');
   119         }
   113         }
   120         return sb.toString();
   114         return sb.toString();
   121     }
   115     }