src/jdk.internal.opt/share/classes/jdk/internal/joptsimple/util/RegexMatcher.java
changeset 50428 8c88df2e8a78
parent 47216 71c04702a3d5
equal deleted inserted replaced
50427:b06f330492cd 50428:8c88df2e8a78
    29  * However, the following notice accompanied the original version of this
    29  * However, the following notice accompanied the original version of this
    30  * file:
    30  * file:
    31  *
    31  *
    32  * The MIT License
    32  * The MIT License
    33  *
    33  *
    34  * Copyright (c) 2004-2014 Paul R. Holser, Jr.
    34  * Copyright (c) 2004-2015 Paul R. Holser, Jr.
    35  *
    35  *
    36  * Permission is hereby granted, free of charge, to any person obtaining
    36  * Permission is hereby granted, free of charge, to any person obtaining
    37  * a copy of this software and associated documentation files (the
    37  * a copy of this software and associated documentation files (the
    38  * "Software"), to deal in the Software without restriction, including
    38  * "Software"), to deal in the Software without restriction, including
    39  * without limitation the rights to use, copy, modify, merge, publish,
    39  * without limitation the rights to use, copy, modify, merge, publish,
    53  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    53  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    54  */
    54  */
    55 
    55 
    56 package jdk.internal.joptsimple.util;
    56 package jdk.internal.joptsimple.util;
    57 
    57 
       
    58 import java.util.Locale;
    58 import java.util.regex.Pattern;
    59 import java.util.regex.Pattern;
    59 
    60 
    60 import static java.util.regex.Pattern.*;
    61 import static java.util.regex.Pattern.*;
       
    62 import static jdk.internal.joptsimple.internal.Messages.message;
    61 
    63 
    62 import jdk.internal.joptsimple.ValueConversionException;
    64 import jdk.internal.joptsimple.ValueConversionException;
    63 import jdk.internal.joptsimple.ValueConverter;
    65 import jdk.internal.joptsimple.ValueConverter;
    64 
    66 
    65 /**
    67 /**
    94         return new RegexMatcher( pattern, 0 );
    96         return new RegexMatcher( pattern, 0 );
    95     }
    97     }
    96 
    98 
    97     public String convert( String value ) {
    99     public String convert( String value ) {
    98         if ( !pattern.matcher( value ).matches() ) {
   100         if ( !pattern.matcher( value ).matches() ) {
    99             throw new ValueConversionException(
   101             raiseValueConversionFailure( value );
   100                 "Value [" + value + "] did not match regex [" + pattern.pattern() + ']' );
       
   101         }
   102         }
   102 
   103 
   103         return value;
   104         return value;
   104     }
   105     }
   105 
   106 
   108     }
   109     }
   109 
   110 
   110     public String valuePattern() {
   111     public String valuePattern() {
   111         return pattern.pattern();
   112         return pattern.pattern();
   112     }
   113     }
       
   114 
       
   115     private void raiseValueConversionFailure( String value ) {
       
   116         String message = message(
       
   117             Locale.getDefault(),
       
   118             "jdk.internal.joptsimple.ExceptionMessages",
       
   119             RegexMatcher.class,
       
   120             "message",
       
   121             value,
       
   122             pattern.pattern() );
       
   123         throw new ValueConversionException( message );
       
   124     }
   113 }
   125 }