@@ -233,19 +233,25 @@ static int handleEscapeSequences(String s, StringBuilder sb, int c, int offset)
233
233
sb .append ("[^\\ n]" );
234
234
return offset ;
235
235
}
236
- } else if ((nextChar == 'p' || nextChar == 'P' ) && offset + 1 < length && s .charAt (offset + 1 ) == '{' ) {
237
- // Handle \p{...} and \P{...} constructs
238
- boolean negated = (nextChar == 'P' );
239
- offset += 2 ; // Skip past \p or \P
240
- int endBrace = s .indexOf ('}' , offset );
241
- if (endBrace != -1 ) {
242
- String property = s .substring (offset , endBrace ).trim ();
243
- String translatedProperty = translateUnicodeProperty (property , negated );
244
- sb .setLength (sb .length () - 1 ); // Remove the backslash
245
- sb .append (translatedProperty );
246
- offset = endBrace ;
236
+ } else if ((nextChar == 'p' || nextChar == 'P' )) {
237
+ if (offset + 1 < length && s .charAt (offset + 1 ) == '{' ) {
238
+ // Existing code for \p{...} and \P{...}
239
+ boolean negated = (nextChar == 'P' );
240
+ offset += 2 ; // Skip past \p{ or \P{
241
+ int endBrace = s .indexOf ('}' , offset );
242
+ if (endBrace != -1 ) {
243
+ String property = s .substring (offset , endBrace ).trim ();
244
+ String translatedProperty = translateUnicodeProperty (property , negated );
245
+ sb .setLength (sb .length () - 1 ); // Remove the backslash
246
+ sb .append (translatedProperty );
247
+ offset = endBrace ;
248
+ } else {
249
+ RegexPreprocessor .regexError (s , offset , "Missing right brace on \\ \\ p{}" );
250
+ }
247
251
} else {
248
- RegexPreprocessor .regexError (s , offset , "Missing right brace on \\ \\ p{}" );
252
+ // \p or \P without brace
253
+ RegexPreprocessor .regexError (s , offset + 1 ,
254
+ "Character following \\ " + nextChar + " must be '{' or a single-character Unicode property name" );
249
255
}
250
256
} else {
251
257
int c2 = s .codePointAt (offset );
0 commit comments