├── .editorconfig ├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ ├── ci.yaml │ └── gradle-wrapper-validation.yaml ├── .gitignore ├── .java-version ├── CHANGELOG.md ├── README.md ├── UNLICENSE ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src ├── main └── kotlin │ ├── extensions │ └── kotlin │ │ └── CaseFormat.kt │ └── kotlin │ └── CaseFormat.kt └── test └── kotlin └── CaseFormatTest.kt /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | max_line_length = 160 10 | tab_width = 4 11 | trim_trailing_whitespace = true 12 | 13 | ij_continuation_indent_size = 4 14 | ij_formatter_off_tag = @formatter:off 15 | ij_formatter_on_tag = @formatter:on 16 | ij_formatter_tags_enabled = true 17 | ij_smart_tabs = false 18 | ij_visual_guides = 80, 120, 160 19 | ij_wrap_on_typing = false 20 | 21 | ij_any_class_annotation_wrap = normal 22 | ij_any_field_annotation_wrap = normal 23 | ij_any_method_annotation_wrap = normal 24 | ij_any_parameter_annotation_wrap = normal 25 | ij_any_variable_annotation_wrap = normal 26 | 27 | [*.bat] 28 | end_of_line = crlf 29 | 30 | [{*.json, *.md, *.yaml}] 31 | indent_size = 2 32 | ij_continuation_indent_size = 2 33 | max_line_length = 80 34 | 35 | [{*.kt, *.kts}] 36 | ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL 37 | 38 | ij_kotlin_import_nested_classes = true 39 | ij_kotlin_imports_layout = * 40 | ij_kotlin_name_count_to_use_star_import = unset 41 | ij_kotlin_name_count_to_use_star_import_for_members = unset 42 | ij_kotlin_packages_to_use_import_on_demand = unset 43 | 44 | ij_kotlin_allow_trailing_comma = true 45 | ij_kotlin_allow_trailing_comma_on_call_site = true 46 | 47 | ij_kotlin_line_comment_add_space = true 48 | 49 | ij_kotlin_blank_lines_after_class_header = 0 50 | ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 0 51 | ij_kotlin_keep_blank_lines_before_right_brace = 1 52 | ij_kotlin_keep_blank_lines_in_code = 1 53 | ij_kotlin_keep_blank_lines_in_declarations = 1 54 | 55 | [*.properties] 56 | ij_properties_align_group_field_declarations = false 57 | ij_properties_keep_blank_lines = true 58 | ij_properties_key_value_delimiter = equals 59 | ij_properties_spaces_around_key_value_delimiter = false 60 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | gradlew* text linguist-generated 2 | *.bat text eol=crlf 3 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @Fleshgrinder 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: [ push, pull_request ] 3 | jobs: 4 | test: 5 | runs-on: ${{ matrix.os }} 6 | strategy: 7 | matrix: 8 | java: [ 8, 11, 16 ] 9 | os: [ macos-latest, ubuntu-latest, windows-latest ] 10 | steps: 11 | - uses: actions/checkout@v2 12 | - uses: actions/setup-java@v2 13 | with: 14 | distribution: zulu 15 | java-version: ${{ matrix.java }} 16 | - uses: burrunan/gradle-cache-action@v1 17 | with: 18 | job-id: ${{ matrix.os }}-j${{ matrix.java }} 19 | arguments: check 20 | - uses: codecov/codecov-action@v1 21 | with: 22 | files: build/reports/jacoco/test/jacocoTestReport.xml 23 | name: ${{ matrix.os }}-j${{ matrix.java }} 24 | -------------------------------------------------------------------------------- /.github/workflows/gradle-wrapper-validation.yaml: -------------------------------------------------------------------------------- 1 | name: gradle-wrapper-validation 2 | on: [ push, pull_request ] 3 | jobs: 4 | validation: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - uses: gradle/wrapper-validation-action@v1 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | /.idea/ 3 | *.iml 4 | *.ipr 5 | *.iws 6 | 7 | # Gradle 8 | .gradle/ 9 | build/ 10 | -------------------------------------------------------------------------------- /.java-version: -------------------------------------------------------------------------------- 1 | 1.8 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/), and this 6 | project adheres to [Semantic Versioning](https://semver.org/). 7 | 8 | ## [Unreleased] 9 | ### Added 10 | - `com.fleshgrinder.kotlin` package with the same functionality, this will 11 | become the future permanent home for everything this project offers. 12 | ### Deprecated 13 | - All functions in `com.fleshgrinder.extensions.kotlin`, they are `inline` now 14 | and delegate to the new permanent home `com.fleshgrinder.kotlin`. 15 | 16 | ## [0.2.0] - 2020-02-20 17 | ### Changed 18 | - Updated Kotlin, 1.3 is the minimum now 19 | 20 | ## [0.1.0] - 2018-10-24 21 | ### Added 22 | - initial release 23 | 24 | [Unreleased]: https://github.com/Fleshgrinder/kotlin-case-format/compare/0.2.0...HEAD 25 | [0.2.0]: https://github.com/Fleshgrinder/kotlin-case-format/compare/0.1.0...0.2.0 26 | [0.1.0]: https://github.com/Fleshgrinder/kotlin-case-format/releases/0.1.0 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin Case Format 2 | 3 | [![Maven Central](https://img.shields.io/maven-central/v/com.fleshgrinder.kotlin/case-format)][Maven Central] 4 | [![GitHub CI Workflow](https://img.shields.io/github/workflow/status/Fleshgrinder/jvm-platform/ci)](https://github.com/Fleshgrinder/kotlin-case-format/actions) 5 | [![Code Coverage](https://img.shields.io/codecov/c/github/Fleshgrinder/kotlin-case-format)](https://codecov.io/gh/Fleshgrinder/kotlin-case-format) 6 | 7 | **Kotlin Case Format** provides string extension functions to convert between 8 | various case formats (_camelCase_, _dash-case_, _snake_case_, …). 9 | 10 | ## Installation 11 | 12 | Go to [Maven Central] where you find the latest release and the code required 13 | for your dependency management tool. 14 | 15 | ## Project Info 16 | 17 | * Contributions are highly appreciated, see [CONTRIBUTING.md] for details. 18 | * We use [Semantic Versioning] and [Keep a Changelog], available versions and 19 | changes are listed on our [releases] page. 20 | * All [releases] are signed 21 | with `EBE5 EBC0 F49E 38A6 9FC7 EA26 7366 AE4A 6774 8172` ([keybase.io/fleshgrinder]) 22 | . 23 | 24 | 25 | [CONTRIBUTING.md]: https://github.com/Fleshgrinder/.github/blob/main/CONTRIBUTING.md 26 | [Keep a Changelog]: https://keepachangelog.com/ 27 | [keybase.io/fleshgrinder]: https://keybase.io/fleshgrinder 28 | [Maven Central]: https://search.maven.org/artifact/com.fleshgrinder.kotlin/case-format 29 | [releases]: https://github.com/Fleshgrinder/kotlin-case-format/releases 30 | [Semantic Versioning]: http://semver.org/ 31 | -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | import org.jetbrains.gradle.ext.ModuleSettings 3 | import org.jetbrains.gradle.ext.PackagePrefixContainer 4 | 5 | plugins { 6 | kotlin("jvm") version "1.4.32" 7 | 8 | id("idea") 9 | id("org.jetbrains.gradle.plugin.idea-ext") version "1.0" 10 | 11 | id("maven-publish") 12 | id("signing") 13 | id("org.jetbrains.dokka") version "1.4.32" 14 | id("io.github.gradle-nexus.publish-plugin") version "1.1.0" 15 | } 16 | 17 | val gitCommitId = provider { file(".git/refs/heads/main").readText().trim() } 18 | val javaVersion = provider { file(".java-version").readText().trim() } 19 | 20 | repositories { 21 | mavenCentral() 22 | } 23 | 24 | dependencies { 25 | api(kotlin("stdlib", "[1.3,)")) 26 | 27 | testImplementation(platform("org.junit:junit-bom:5.7.1")) 28 | testImplementation("org.junit.jupiter:junit-jupiter-api") 29 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") 30 | } 31 | 32 | idea { 33 | module { 34 | isDownloadJavadoc = false 35 | isDownloadSources = !System.getenv().containsKey("CI") 36 | 37 | ((this as ExtensionAware).the() as ExtensionAware).configure { 38 | this["src/main/kotlin"] = "com.fleshgrinder" 39 | this["src/test/kotlin"] = group as String 40 | } 41 | } 42 | } 43 | 44 | java { 45 | withSourcesJar() 46 | withJavadocJar() 47 | } 48 | 49 | kotlin { 50 | explicitApi() 51 | } 52 | 53 | tasks.withType().configureEach { 54 | kotlinOptions { 55 | allWarningsAsErrors = true 56 | jvmTarget = javaVersion.get() 57 | apiVersion = "1.3" 58 | languageVersion = "1.3" 59 | } 60 | } 61 | 62 | tasks.test.configure { 63 | useJUnitPlatform() 64 | } 65 | 66 | tasks.dokkaJavadoc.configure { 67 | outputDirectory.set(tasks.javadoc.map { checkNotNull(it.destinationDir) }) 68 | } 69 | 70 | tasks.javadoc.configure { 71 | dependsOn(tasks.dokkaJavadoc) 72 | } 73 | 74 | tasks.jar.configure { 75 | manifest { 76 | attributes["Name"] = "com/fleshgrinder/kotlin/" 77 | attributes["Specification-Title"] = "Kotlin Case Format" 78 | attributes["Specification-Version"] = project.version 79 | attributes["Specification-Vendor"] = "Fleshgrinder" 80 | attributes["Implementation-Title"] = "com.fleshgrinder.kotlin" 81 | attributes["Implementation-Vendor"] = "Fleshgrinder" 82 | attributes["Implementation-Version"] = gitCommitId.get() 83 | attributes["Sealed"] = false 84 | } 85 | } 86 | 87 | publishing { 88 | publications { 89 | register("sonatype") { 90 | from(components["java"]) 91 | pom { 92 | name.set("Kotlin Case Format") 93 | description.set(project.description) 94 | url.set("https://github.com/Fleshgrinder/kotlin-case-format") 95 | inceptionYear.set("2018") 96 | properties.put("commit", gitCommitId) 97 | licenses { 98 | license { 99 | name.set("Unlicense") 100 | comments.set("This is a public domain dedication") 101 | url.set("https://unlicense.org/") 102 | distribution.set("repo") 103 | } 104 | } 105 | developers { 106 | developer { 107 | id.set("Fleshgrinder") 108 | name.set("Richard Fussenegger") 109 | email.set("Fleshgrinder@users.noreply.github.com") 110 | } 111 | } 112 | scm { 113 | url.set("https://github.com/Fleshgrinder/kotlin-case-format") 114 | connection.set("scm:https://github.com/Fleshgrinder/kotlin-case-format.git") 115 | developerConnection.set("scm:git@github.com:Fleshgrinder/kotlin-case-format.git") 116 | } 117 | issueManagement { 118 | system.set("GitHub") 119 | url.set("https://github.com/Fleshgrinder/kotlin-case-format/issues") 120 | } 121 | } 122 | } 123 | } 124 | } 125 | 126 | nexusPublishing { 127 | repositories { 128 | sonatype { 129 | stagingProfileId.set("141a1dad946f") 130 | } 131 | } 132 | } 133 | 134 | signing { 135 | sign(publishing.publications["sonatype"]) 136 | } 137 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | group=com.fleshgrinder.kotlin 3 | version=0.2.0 4 | description=String extension functions to convert between various case formats (camelCase, dash-case, …) 5 | 6 | org.gradle.caching=true 7 | org.gradle.configureondemand=true 8 | org.gradle.jvmargs=-Dfile.encoding=UTF-8 9 | org.gradle.parallel=true 10 | org.gradle.warning.mode=all 11 | 12 | kotlin.code.style=official 13 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fleshgrinder/kotlin-case-format/a623850e8688fb3ef3c18baafe60ffb1624ce369/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "case-format" 2 | -------------------------------------------------------------------------------- /src/main/kotlin/extensions/kotlin/CaseFormat.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("NOTHING_TO_INLINE") 2 | 3 | package com.fleshgrinder.extensions.kotlin 4 | 5 | import com.fleshgrinder.kotlin.toLowerCamelCase as newToLowerCamelCase 6 | import com.fleshgrinder.kotlin.toLowerCaseFormat as newToLowerCaseFormat 7 | import com.fleshgrinder.kotlin.toLowerDashCase as newToLowerDashCase 8 | import com.fleshgrinder.kotlin.toLowerSnakeCase as newToLowerSnakeCase 9 | import com.fleshgrinder.kotlin.toUpperCamelCase as newToUpperCamelCase 10 | import com.fleshgrinder.kotlin.toUpperCaseFormat as newToUpperCaseFormat 11 | import com.fleshgrinder.kotlin.toUpperDashCase as newToUpperDashCase 12 | import com.fleshgrinder.kotlin.toUpperSnakeCase as newToUpperSnakeCase 13 | 14 | /** 15 | * Format this [String] in **lowerCamelCase** (aka. _mixedCase_, 16 | * _Smalltalk case_, …). 17 | * 18 | * @param ignore can be used to specify characters that should be included 19 | * verbatim in the result, note that they are still considered separators 20 | * @receiver [String] to format 21 | * @return **lowerCamelCase** formatted [String] 22 | * @since 0.1.0 23 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toLowerCamelCase 24 | */ 25 | @Deprecated( 26 | "package changed", 27 | ReplaceWith("toLowerCamelCase(*ignore)", "com.fleshgrinder.kotlin.toLowerCamelCase"), 28 | DeprecationLevel.WARNING 29 | ) 30 | public inline fun String.toLowerCamelCase(vararg ignore: Char): String = 31 | newToLowerCamelCase(*ignore) 32 | 33 | /** 34 | * Format this [String] in **UpperCamelCase** (aka. _PascalCase_, _WikiCase_, 35 | * …). 36 | * 37 | * @param ignore can be used to specify characters that should be included 38 | * verbatim in the result, note that they are still considered separators 39 | * @receiver [String] to format 40 | * @return **UpperCamelCase** formatted [String] 41 | * @since 0.1.0 42 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toUpperCamelCase 43 | */ 44 | @Deprecated( 45 | "package changed", 46 | ReplaceWith("toUpperCamelCase(*ignore)", "com.fleshgrinder.kotlin.toUpperCamelCase"), 47 | DeprecationLevel.WARNING 48 | ) 49 | public inline fun String.toUpperCamelCase(vararg ignore: Char): String = 50 | newToUpperCamelCase(*ignore) 51 | 52 | /** 53 | * Format this [String] in another **lower case** format where words are 54 | * separated by the given [separator]. 55 | * 56 | * @param separator to separate words with 57 | * @param ignore can be used to specify characters that should be included 58 | * verbatim in the result, note that they are still considered separators 59 | * @receiver [String] to format 60 | * @return **lower case** formatted [String] 61 | * @since 0.1.0 62 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toLowerCaseFormat 63 | */ 64 | @Deprecated( 65 | "package changed", 66 | ReplaceWith("toLowerCaseFormat(separator, *ignore)", "com.fleshgrinder.kotlin.toLowerCaseFormat"), 67 | DeprecationLevel.WARNING 68 | ) 69 | public inline fun String.toLowerCaseFormat(separator: Char, vararg ignore: Char): String = 70 | newToLowerCaseFormat(separator, *ignore) 71 | 72 | /** 73 | * Format this [String] in **lower-dash-case** (aka. _lower hyphen case_, 74 | * _lower kebab case_, …). 75 | * 76 | * @param ignore can be used to specify characters that should be included 77 | * verbatim in the result, note that they are still considered separators 78 | * @receiver [String] to format 79 | * @return **lower-dash-case** formatted [String] 80 | * @since 0.1.0 81 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toLowerDashCase 82 | */ 83 | @Deprecated( 84 | "package changed", 85 | ReplaceWith("toLowerDashCase(*ignore)", "com.fleshgrinder.kotlin.toLowerDashCase"), 86 | DeprecationLevel.WARNING 87 | ) 88 | public inline fun String.toLowerDashCase(vararg ignore: Char): String = 89 | newToLowerDashCase(*ignore) 90 | 91 | /** 92 | * Format this [String] in **lower_snake_case**. 93 | * 94 | * @param ignore can be used to specify characters that should be included 95 | * verbatim in the result, note that they are still considered separators 96 | * @receiver [String] to format 97 | * @return **lower_snake_case** formatted [String] 98 | * @since 0.1.0 99 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toLowerSnakeCase 100 | */ 101 | @Deprecated( 102 | "package changed", 103 | ReplaceWith("toLowerSnakeCase(*ignore)", "com.fleshgrinder.kotlin.toLowerSnakeCase"), 104 | DeprecationLevel.WARNING 105 | ) 106 | public inline fun String.toLowerSnakeCase(vararg ignore: Char): String = 107 | newToLowerSnakeCase(*ignore) 108 | 109 | /** 110 | * Format this [String] in another **UPPER CASE** format where words are 111 | * separated by the given [separator]. 112 | * 113 | * @param separator to separate words with 114 | * @param ignore can be used to specify characters that should be included 115 | * verbatim in the result, note that they are still considered separators 116 | * @receiver [String] to format 117 | * @return **UPPER CASE** formatted [String] 118 | * @since 0.1.0 119 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toUpperCaseFormat 120 | */ 121 | @Deprecated( 122 | "package changed", 123 | ReplaceWith("toUpperCaseFormat(separator, *ignore)", "com.fleshgrinder.kotlin.toUpperCaseFormat"), 124 | DeprecationLevel.WARNING 125 | ) 126 | public inline fun String.toUpperCaseFormat(separator: Char, vararg ignore: Char): String = 127 | newToUpperCaseFormat(separator, *ignore) 128 | 129 | /** 130 | * Format this [String] in **UPPER-DASH-CASE** (aka. _upper hyphen case_, 131 | * _upper kebab case_, …). 132 | * 133 | * @param ignore can be used to specify characters that should be included 134 | * verbatim in the result, note that they are still considered separators 135 | * @receiver [String] to format 136 | * @return **UPPER-DASH-CASE** formatted [String] 137 | * @since 0.1.0 138 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toUpperDashCase 139 | */ 140 | @Deprecated( 141 | "package changed", 142 | ReplaceWith("toUpperDashCase(*ignore)", "com.fleshgrinder.kotlin.toUpperDashCase"), 143 | DeprecationLevel.WARNING 144 | ) 145 | public inline fun String.toUpperDashCase(vararg ignore: Char): String = 146 | newToUpperDashCase(*ignore) 147 | 148 | /** 149 | * Format this [String] in **UPPER_SNAKE_CASE** (aka. _screaming snake case_). 150 | * 151 | * @param ignore can be used to specify characters that should be included 152 | * verbatim in the result, note that they are still considered separators 153 | * @receiver [String] to format 154 | * @return **UPPER_SNAKE_CASE** formatted [String] 155 | * @since 0.1.0 156 | * @sample com.fleshgrinder.kotlin.CaseFormatTest.toUpperSnakeCase 157 | */ 158 | @Deprecated( 159 | "package changed", 160 | ReplaceWith("toUpperSnakeCase(*ignore)", "com.fleshgrinder.kotlin.toUpperSnakeCase"), 161 | DeprecationLevel.WARNING 162 | ) 163 | public inline fun String.toUpperSnakeCase(vararg ignore: Char): String = 164 | newToUpperSnakeCase(*ignore) 165 | -------------------------------------------------------------------------------- /src/main/kotlin/kotlin/CaseFormat.kt: -------------------------------------------------------------------------------- 1 | package com.fleshgrinder.kotlin 2 | 3 | private fun formatCamelCase(input: String, ignore: CharArray, upperCase: Boolean) = 4 | if (input.isEmpty()) input else StringBuilder(input.length).also { 5 | var seenSeparator = upperCase 6 | var seenUpperCase = !upperCase 7 | 8 | input.forEach { c -> 9 | when (c) { 10 | in ignore -> { 11 | it.append(c) 12 | seenSeparator = upperCase 13 | seenUpperCase = !upperCase 14 | } 15 | in '0'..'9' -> { 16 | it.append(c) 17 | seenSeparator = false 18 | seenUpperCase = false 19 | } 20 | in 'a'..'z' -> { 21 | it.append(if (seenSeparator) c.toUpperCase() else c) 22 | seenSeparator = false 23 | seenUpperCase = false 24 | } 25 | in 'A'..'Z' -> { 26 | it.append(if (seenUpperCase) c.toLowerCase() else c) 27 | seenSeparator = false 28 | seenUpperCase = true 29 | } 30 | else -> if (it.isNotEmpty()) { 31 | seenSeparator = true 32 | seenUpperCase = false 33 | } 34 | } 35 | } 36 | }.toString() 37 | 38 | /** 39 | * Format this [String] in **lowerCamelCase** (aka. _mixedCase_, 40 | * _Smalltalk case_, …). 41 | * 42 | * @param ignore can be used to specify characters that should be included 43 | * verbatim in the result, note that they are still considered separators 44 | * @receiver [String] to format 45 | * @return **lowerCamelCase** formatted [String] 46 | * @since 0.3.0 47 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toLowerCamelCase 48 | */ 49 | public fun String.toLowerCamelCase(vararg ignore: Char): String = 50 | formatCamelCase(this, ignore, false) 51 | 52 | /** 53 | * Format this [String] in **UpperCamelCase** (aka. _PascalCase_, _WikiCase_, 54 | * …). 55 | * 56 | * @param ignore can be used to specify characters that should be included 57 | * verbatim in the result, note that they are still considered separators 58 | * @receiver [String] to format 59 | * @return **UpperCamelCase** formatted [String] 60 | * @since 0.3.0 61 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toUpperCamelCase 62 | */ 63 | public fun String.toUpperCamelCase(vararg ignore: Char): String = 64 | formatCamelCase(this, ignore, true) 65 | 66 | private fun formatCase(input: String, separator: Char, ignore: CharArray, upperCase: Boolean) = 67 | if (input.isEmpty()) input else StringBuilder(input.length).also { 68 | var seenSeparator = true 69 | var seenUpperCase = false 70 | 71 | input.forEach { c -> 72 | when (c) { 73 | in ignore -> { 74 | it.append(c) 75 | seenSeparator = true 76 | seenUpperCase = false 77 | } 78 | in '0'..'9' -> { 79 | it.append(c) 80 | seenSeparator = false 81 | seenUpperCase = false 82 | } 83 | in 'a'..'z' -> { 84 | it.append(if (upperCase) c.toUpperCase() else c) 85 | seenSeparator = false 86 | seenUpperCase = false 87 | } 88 | in 'A'..'Z' -> { 89 | if (!seenSeparator && !seenUpperCase) it.append(separator) 90 | it.append(if (upperCase) c else c.toLowerCase()) 91 | seenSeparator = false 92 | seenUpperCase = true 93 | } 94 | else -> { 95 | if (!seenSeparator || !seenUpperCase) it.append(separator) 96 | seenSeparator = true 97 | seenUpperCase = false 98 | } 99 | } 100 | } 101 | }.toString() 102 | 103 | private fun formatLowerCase(input: String, separator: Char, ignore: CharArray) = 104 | formatCase(input, separator, ignore, false) 105 | 106 | /** 107 | * Format this [String] in another **lower case** format where words are 108 | * separated by the given [separator]. 109 | * 110 | * @param separator to separate words with 111 | * @param ignore can be used to specify characters that should be included 112 | * verbatim in the result, note that they are still considered separators 113 | * @receiver [String] to format 114 | * @return **lower case** formatted [String] 115 | * @since 0.3.0 116 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toLowerCaseFormat 117 | */ 118 | public fun String.toLowerCaseFormat(separator: Char, vararg ignore: Char): String = 119 | formatLowerCase(this, separator, ignore) 120 | 121 | /** 122 | * Format this [String] in **lower-dash-case** (aka. _lower hyphen case_, 123 | * _lower kebab case_, …). 124 | * 125 | * @param ignore can be used to specify characters that should be included 126 | * verbatim in the result, note that they are still considered separators 127 | * @receiver [String] to format 128 | * @return **lower-dash-case** formatted [String] 129 | * @since 0.3.0 130 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toLowerDashCase 131 | */ 132 | public fun String.toLowerDashCase(vararg ignore: Char): String = 133 | formatLowerCase(this, '-', ignore) 134 | 135 | /** 136 | * Format this [String] in **lower_snake_case**. 137 | * 138 | * @param ignore can be used to specify characters that should be included 139 | * verbatim in the result, note that they are still considered separators 140 | * @receiver [String] to format 141 | * @return **lower_snake_case** formatted [String] 142 | * @since 0.3.0 143 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toLowerSnakeCase 144 | */ 145 | public fun String.toLowerSnakeCase(vararg ignore: Char): String = 146 | formatLowerCase(this, '_', ignore) 147 | 148 | private fun formatUpperCase(input: String, separator: Char, ignore: CharArray) = 149 | formatCase(input, separator, ignore, true) 150 | 151 | /** 152 | * Format this [String] in another **UPPER CASE** format where words are 153 | * separated by the given [separator]. 154 | * 155 | * @param separator to separate words with 156 | * @param ignore can be used to specify characters that should be included 157 | * verbatim in the result, note that they are still considered separators 158 | * @receiver [String] to format 159 | * @return **UPPER CASE** formatted [String] 160 | * @since 0.3.0 161 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toUpperCaseFormat 162 | */ 163 | public fun String.toUpperCaseFormat(separator: Char, vararg ignore: Char): String = 164 | formatUpperCase(this, separator, ignore) 165 | 166 | /** 167 | * Format this [String] in **UPPER-DASH-CASE** (aka. _upper hyphen case_, 168 | * _upper kebab case_, …). 169 | * 170 | * @param ignore can be used to specify characters that should be included 171 | * verbatim in the result, note that they are still considered separators 172 | * @receiver [String] to format 173 | * @return **UPPER-DASH-CASE** formatted [String] 174 | * @since 0.3.0 175 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toUpperDashCase 176 | */ 177 | public fun String.toUpperDashCase(vararg ignore: Char): String = 178 | formatUpperCase(this, '-', ignore) 179 | 180 | /** 181 | * Format this [String] in **UPPER_SNAKE_CASE** (aka. _screaming snake case_). 182 | * 183 | * @param ignore can be used to specify characters that should be included 184 | * verbatim in the result, note that they are still considered separators 185 | * @receiver [String] to format 186 | * @return **UPPER_SNAKE_CASE** formatted [String] 187 | * @since 0.3.0 188 | * @sample com.fleshgrinder.extensions.kotlin.CaseFormatTest.toUpperSnakeCase 189 | */ 190 | public fun String.toUpperSnakeCase(vararg ignore: Char): String = 191 | formatUpperCase(this, '_', ignore) 192 | -------------------------------------------------------------------------------- /src/test/kotlin/CaseFormatTest.kt: -------------------------------------------------------------------------------- 1 | package com.fleshgrinder.kotlin 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Test 5 | 6 | /** 7 | * Note that this class is `private` so that it is excluded from the generated 8 | * docs. Note further that the bodies of the test methods are part of the public 9 | * docs, hence, the text should be written in a way that helps a person who is 10 | * interested in learning about the library. Docs inclusion is also the reason 11 | * why the tests are not parameterized but instead use multiple assertions; 12 | * annotations are never included in the docs only the function bodies. 13 | */ 14 | private class CaseFormatTest { 15 | @Test 16 | fun toLowerCamelCase() { 17 | assertEquals("", "".toLowerCamelCase()) { 18 | "empty strings are returned as-is" 19 | } 20 | 21 | assertEquals("lowerCamelCase", "lowerCamelCase".toLowerCamelCase()) { 22 | "a string that is already in `lowerCamelCase` is unchanged" 23 | } 24 | 25 | assertEquals("upperCamelCase", "UpperCamelCase".toLowerCamelCase()) { 26 | "a string that is in `UpperCamelCase` has its first character decapitalized" 27 | } 28 | 29 | listOf(' ', '-', '_').forEach { sep -> 30 | assertEquals("lowerCamelCase", "lower${sep}camel${sep}case".toLowerCamelCase()) { 31 | "every symbol outside ASCII numbers 0..9 and lower letters a..z is a word separator (`$sep`)" 32 | } 33 | } 34 | 35 | assertEquals("uniCode", "©®UNI¤CODE®©".toLowerCamelCase()) { 36 | "Unicode characters are removed" 37 | } 38 | 39 | assertEquals("java.properties.keyName", "JAVA.Properties.Key-Name".toLowerCamelCase('.')) { 40 | "ignored characters are included in the result verbatim but still considered to be word separators" 41 | } 42 | 43 | assertEquals("a.b-c_d", "a.b-c_d".toLowerCamelCase('.', '-', '_')) { 44 | "it is possible to ignore multiple characters" 45 | } 46 | 47 | assertEquals("weirDlYMiXedCaSing", "WeirDlY-MiXed_CaSing".toLowerCamelCase()) { 48 | "weirdly case formatted strings will lead to weird results" 49 | } 50 | } 51 | 52 | @Test 53 | fun toUpperCamelCase() { 54 | assertEquals("", "".toUpperCamelCase()) { 55 | "empty strings are returned as-is" 56 | } 57 | 58 | assertEquals("UpperCamelCase", "UpperCamelCase".toUpperCamelCase()) { 59 | "a string that is already in `UpperCamelCase` is unchanged" 60 | } 61 | 62 | assertEquals("LowerCamelCase", "lowerCamelCase".toUpperCamelCase()) { 63 | "a string that is in `lowerCamelCase` has its first character capitalized" 64 | } 65 | 66 | listOf(' ', '-', '_').forEach { sep -> 67 | assertEquals("UpperCamelCase", "upper${sep}camel${sep}case".toUpperCamelCase()) { 68 | "every symbol outside ASCII numbers 0..9 and lower letters a..z is a word separator (`$sep`)" 69 | } 70 | } 71 | 72 | assertEquals("UniCode", "©®UNI¤CODE®©".toUpperCamelCase()) { 73 | "Unicode characters are removed" 74 | } 75 | 76 | assertEquals("Java.Properties.KeyName", "JAVA.Properties.Key-Name".toUpperCamelCase('.')) { 77 | "ignored characters are included in the result verbatim but still considered to be word separators" 78 | } 79 | 80 | assertEquals("A.B-C_D", "a.b-c_d".toUpperCamelCase('.', '-', '_')) { 81 | "it is possible to ignore multiple characters" 82 | } 83 | 84 | assertEquals("WeirDlYMiXedCaSing", "WeirDlY-MiXed_CaSing".toUpperCamelCase()) { 85 | "weirdly case formatted strings will lead to weird results" 86 | } 87 | } 88 | 89 | @Test 90 | fun toLowerCaseFormat() { 91 | assertEquals("", "".toLowerCaseFormat('|')) { 92 | "empty strings are returned as-is" 93 | } 94 | 95 | assertEquals("lower|case|format", "lower|case|format".toLowerCaseFormat('|')) { 96 | "a string that is already in its desired form is unchanged" 97 | } 98 | 99 | assertEquals("lower|case|format", "LOWER|CASE|FORMAT".toLowerCaseFormat('|')) { 100 | "a string that is all upper is properly converted to lower" 101 | } 102 | 103 | assertEquals("lower|case|format", "LowerCaseFormat".toLowerCaseFormat('|')) { 104 | "ASCII upper letters A..Z are word separators" 105 | } 106 | 107 | listOf(' ', '-', '_').forEach { sep -> 108 | assertEquals("lower|case|format", "lower${sep}case${sep}format".toLowerCaseFormat('|')) { 109 | "every symbol outside ASCII numbers 0..9 and lower letters a..z is a word separator (`$sep`)" 110 | } 111 | } 112 | 113 | assertEquals("||uni|code||", "©®UNI¤CODE®©".toLowerCaseFormat('|')) { 114 | "Unicode characters are replaced" 115 | } 116 | 117 | assertEquals("dot.separated.string", "dot.separated.string".toLowerCaseFormat('|', '.')) { 118 | "ignored characters are included in the result verbatim" 119 | } 120 | 121 | assertEquals("a.b-c_d", "a.b-c_d".toLowerCaseFormat('|', '.', '-', '_')) { 122 | "it is possible to ignore multiple characters" 123 | } 124 | 125 | assertEquals("weir|dl|y|mi|xed|ca|sing", "WeirDlY-MiXed_CaSing".toLowerCaseFormat('|')) { 126 | "weirdly case formatted strings will lead to weird results" 127 | } 128 | } 129 | 130 | @Test 131 | fun toLowerDashCase() { 132 | assertEquals("", "".toLowerDashCase()) { 133 | "empty strings are returned as-is" 134 | } 135 | 136 | assertEquals("lower-dash-case", "lower-dash-case".toLowerDashCase()) { 137 | "a string that is already in its desired form is unchanged" 138 | } 139 | 140 | assertEquals("lower-dash-case", "LOWER-DASH-CASE".toLowerDashCase()) { 141 | "a string that is all upper is properly converted to lower" 142 | } 143 | 144 | listOf(' ', '|', '_').forEach { sep -> 145 | assertEquals("lower-dash-case", "lower${sep}dash${sep}case".toLowerDashCase()) { 146 | "every symbol outside ASCII numbers 0..9 and lower letters a..z is a word separator (`$sep`)" 147 | } 148 | } 149 | 150 | assertEquals("--uni-code--", "©®UNI¤CODE®©".toLowerDashCase()) { 151 | "Unicode characters are replaced" 152 | } 153 | 154 | assertEquals("dot.separated.string", "dot.separated.string".toLowerDashCase('.')) { 155 | "ignored characters are included in the result verbatim" 156 | } 157 | 158 | assertEquals("a.b|c_d", "a.b|c_d".toLowerDashCase('.', '|', '_')) { 159 | "it is possible to ignore multiple characters" 160 | } 161 | 162 | assertEquals("weir-dl-y-mi-xed-ca-sing", "WeirDlY-MiXed_CaSing".toLowerDashCase()) { 163 | "weirdly case formatted strings will lead to weird results" 164 | } 165 | } 166 | 167 | @Test 168 | fun toLowerSnakeCase() { 169 | assertEquals("", "".toLowerSnakeCase()) { 170 | "empty strings are returned as-is" 171 | } 172 | 173 | assertEquals("lower_snake_case", "lower_snake_case".toLowerSnakeCase()) { 174 | "a string that is already in its desired form is unchanged" 175 | } 176 | 177 | assertEquals("lower_snake_case", "LOWER_SNAKE_CASE".toLowerSnakeCase()) { 178 | "a string that is all upper is properly converted to lower" 179 | } 180 | 181 | listOf(' ', '-', '|').forEach { sep -> 182 | assertEquals("lower_snake_case", "lower${sep}snake${sep}case".toLowerSnakeCase()) { 183 | "every symbol outside ASCII numbers 0..9 and lower letters a..z is a word separator (`$sep`)" 184 | } 185 | } 186 | 187 | assertEquals("__uni_code__", "©®UNI¤CODE®©".toLowerSnakeCase()) { 188 | "Unicode characters are replaced" 189 | } 190 | 191 | assertEquals("dot.separated.string", "dot.separated.string".toLowerSnakeCase('.')) { 192 | "ignored characters are included in the result verbatim" 193 | } 194 | 195 | assertEquals("a.b-c|d", "a.b-c|d".toLowerSnakeCase('.', '-', '|')) { 196 | "it is possible to ignore multiple characters" 197 | } 198 | 199 | assertEquals("weir_dl_y_mi_xed_ca_sing", "WeirDlY_MiXed_CaSing".toLowerSnakeCase()) { 200 | "weirdly case formatted strings will lead to weird results" 201 | } 202 | } 203 | 204 | @Test 205 | fun toUpperCaseFormat() { 206 | assertEquals("", "".toUpperCaseFormat('|')) { 207 | "empty strings are returned as-is" 208 | } 209 | 210 | assertEquals("UPPER|CASE|FORMAT", "UPPER|CASE|FORMAT".toUpperCaseFormat('|')) { 211 | "a string that is already in its desired form is unchanged" 212 | } 213 | 214 | assertEquals("UPPER|CASE|FORMAT", "upper|case|format".toUpperCaseFormat('|')) { 215 | "a string that is all lower is properly converted to upper" 216 | } 217 | 218 | assertEquals("UPPER|CASE|FORMAT", "UpperCaseFormat".toUpperCaseFormat('|')) { 219 | "ASCII upper letters A..Z are word separators" 220 | } 221 | 222 | listOf(' ', '-', '_').forEach { sep -> 223 | assertEquals("UPPER|CASE|FORMAT", "upper${sep}case${sep}format".toUpperCaseFormat('|')) { 224 | "every symbol outside ASCII numbers 0..9 and lower letters a..z is a word separator (`$sep`)" 225 | } 226 | } 227 | 228 | assertEquals("||UNI|CODE||", "©®UNI¤CODE®©".toUpperCaseFormat('|')) { 229 | "Unicode characters are replaced" 230 | } 231 | 232 | assertEquals("DOT.SEPARATED.STRING", "dot.separated.string".toUpperCaseFormat('|', '.')) { 233 | "ignored characters are included in the result verbatim" 234 | } 235 | 236 | assertEquals("A.B-C_D", "a.b-c_d".toUpperCaseFormat('|', '.', '-', '_')) { 237 | "it is possible to ignore multiple characters" 238 | } 239 | 240 | assertEquals("WEIR|DL|Y|MI|XED|CA|SING", "WeirDlY-MiXed_CaSing".toUpperCaseFormat('|')) { 241 | "weirdly case formatted strings will lead to weird results" 242 | } 243 | } 244 | 245 | @Test 246 | fun toUpperDashCase() { 247 | assertEquals("", "".toUpperDashCase()) { 248 | "empty strings are returned as-is" 249 | } 250 | 251 | assertEquals("UPPER-DASH-CASE", "UPPER-DASH-CASE".toUpperDashCase()) { 252 | "a string that is already in its desired form is unchanged" 253 | } 254 | 255 | assertEquals("UPPER-DASH-CASE", "upper-dash-case".toUpperDashCase()) { 256 | "a string that is all lower is properly converted to upper" 257 | } 258 | 259 | listOf(' ', '|', '_').forEach { sep -> 260 | assertEquals("UPPER-DASH-CASE", "upper${sep}dash${sep}case".toUpperDashCase()) { 261 | "every symbol outside ASCII numbers 0..9 and upper letters a..z is a word separator (`$sep`)" 262 | } 263 | } 264 | 265 | assertEquals("--UNI-CODE--", "©®UNI¤CODE®©".toUpperDashCase()) { 266 | "Unicode characters are replaced" 267 | } 268 | 269 | assertEquals("DOT.SEPARATED.STRING", "dot.separated.string".toUpperDashCase('.')) { 270 | "ignored characters are included in the result verbatim" 271 | } 272 | 273 | assertEquals("A.B|C_D", "a.b|c_d".toUpperDashCase('.', '|', '_')) { 274 | "it is possible to ignore multiple characters" 275 | } 276 | 277 | assertEquals("WEIR-DL-Y-MI-XED-CA-SING", "WeirDlY-MiXed_CaSing".toUpperDashCase()) { 278 | "weirdly case formatted strings will lead to weird results" 279 | } 280 | } 281 | 282 | @Test 283 | fun toUpperSnakeCase() { 284 | assertEquals("", "".toUpperSnakeCase()) { 285 | "empty strings are returned as-is" 286 | } 287 | 288 | assertEquals("UPPER_SNAKE_CASE", "UPPER_SNAKE_CASE".toUpperSnakeCase()) { 289 | "a string that is already in its desired form is unchanged" 290 | } 291 | 292 | assertEquals("UPPER_SNAKE_CASE", "upper_snake_case".toUpperSnakeCase()) { 293 | "a string that is all lower is properly converted to upper" 294 | } 295 | 296 | listOf(' ', '-', '|').forEach { sep -> 297 | assertEquals("UPPER_SNAKE_CASE", "upper${sep}snake${sep}case".toUpperSnakeCase()) { 298 | "every symbol outside ASCII numbers 0..9 and upper letters a..z is a word separator (`$sep`)" 299 | } 300 | } 301 | 302 | assertEquals("__UNI_CODE__", "©®UNI¤CODE®©".toUpperSnakeCase()) { 303 | "Unicode characters are replaced" 304 | } 305 | 306 | assertEquals("DOT.SEPARATED.STRING", "dot.separated.string".toUpperSnakeCase('.')) { 307 | "ignored characters are included in the result verbatim" 308 | } 309 | 310 | assertEquals("A.B-C|D", "a.b-c|d".toUpperSnakeCase('.', '-', '|')) { 311 | "it is possible to ignore multiple characters" 312 | } 313 | 314 | assertEquals("WEIR_DL_Y_MI_XED_CA_SING", "WeirDlY_MiXed_CaSing".toUpperSnakeCase()) { 315 | "weirdly case formatted strings will lead to weird results" 316 | } 317 | } 318 | } 319 | --------------------------------------------------------------------------------