From 09c627c0b2f61467b8d0b60d55f37c251f03d751 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sat, 21 Sep 2024 10:53:50 +0200 Subject: [PATCH] fix uppercasing of names in processor to comply with JPA 3.2 spec --- .../hibernate/processor/util/StringUtil.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/StringUtil.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/StringUtil.java index 8240c8ce0e..8520e1302b 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/StringUtil.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/StringUtil.java @@ -6,6 +6,10 @@ package org.hibernate.processor.util; import java.util.Locale; +import static java.lang.Character.charCount; +import static java.lang.Character.isUpperCase; +import static java.lang.Character.toUpperCase; + /** * @author Hardy Ferentschik */ @@ -100,8 +104,18 @@ public final class StringUtil { return name.replaceAll("[\\s.\\-!@#%=+/*^&|(){}\\[\\],]", "_"); } - public static String getUpperUnderscoreCaseFromLowerCamelCase(String lowerCamelCaseString){ - return lowerCamelCaseString.replaceAll("(.)(\\p{Upper})", "$1_$2").toUpperCase(Locale.ROOT); + public static String getUpperUnderscoreCaseFromLowerCamelCase(String lowerCamelCaseString) { + final StringBuilder result = new StringBuilder(); + int position = 0; + while ( position < lowerCamelCaseString.length() ) { + final int codePoint = lowerCamelCaseString.codePointAt( position ); + if ( position>0 && isUpperCase( codePoint ) ) { + result.append('_'); + } + result.appendCodePoint( toUpperCase( codePoint ) ); + position += charCount( codePoint ); + } + return result.toString(); } private static boolean startsWithSeveralUpperCaseLetters(String string) {