1 /*
<lambda>null2  * Copyright 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.appfunctions.compiler.core
18 
19 /** Transforms a camel case string to screaming snake case string. */
20 fun String.fromCamelCaseToScreamingSnakeCase(): String {
21     fun isFullyCapitalized(input: String): Boolean {
22         val uppercaseInput = input.uppercase()
23         return input == uppercaseInput
24     }
25     if (isFullyCapitalized(this)) {
26         return this
27     }
28 
29     val camelRegex = "(?<=[a-zA-Z])[A-Z]".toRegex()
30     return camelRegex.replace(this) { "_${it.value}" }.uppercase()
31 }
32 
33 /** Transforms any string to a pascal case string, removing all separators (".", "/", "_", "-"). */
toPascalCasenull34 fun String.toPascalCase(): String {
35     if (this.isEmpty()) return ""
36 
37     val separatorsRegex = Regex("[._/-]+|\\s+") // Matches separators and spaces
38     val words = split(separatorsRegex).filter { it.isNotEmpty() }
39 
40     return words.joinToString("") { word -> word.lowercase().replaceFirstChar { it.uppercase() } }
41 }
42