From e6548bcccd340c38ac1bbe41c2926f4261aee1b3 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 9 Feb 2023 17:39:47 +1100 Subject: [PATCH] add unCamelCaseKeepCapitals --- .../org/hl7/fhir/utilities/Utilities.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java index 508bbcb1d..e07d6b7c7 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java @@ -1181,7 +1181,21 @@ public class Utilities { return fn.contains(".") ? fn.substring(fn.lastIndexOf(".") + 1) : ""; } - + public static String unCamelCaseKeepCapitals(String name) { + StringBuilder b = new StringBuilder(); + boolean first = true; + for (char c : name.toCharArray()) { + if (Character.isUpperCase(c)) { + if (!first) + b.append(" "); + b.append(c); + } else + b.append(c); + first = false; + } + return b.toString(); + } + public static String unCamelCase(String name) { StringBuilder b = new StringBuilder(); boolean first = true; @@ -1862,4 +1876,9 @@ public class Utilities { } } + + public static boolean isValidCRName(String name) { + return name != null && name.matches("[A-Z]([A-Za-z0-9_]){1,254}"); + } + }