├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── kotlin
│ │ │ └── com
│ │ │ └── cesarferreira
│ │ │ └── pluralize
│ │ │ └── Pluralize.kt
│ └── test
│ │ └── kotlin
│ │ └── com
│ │ └── cesarferreira
│ │ └── pluralize
│ │ ├── SingularizationTest.kt
│ │ └── PluralizationTest.kt
├── build.gradle
├── proguard-rules.pro
└── publish.gradle
├── android-sample
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── values-v21
│ │ │ └── styles.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ ├── content_hello.xml
│ │ │ └── activity_hello.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── cesarferreira
│ │ └── pluralize
│ │ └── sample
│ │ └── HelloActivity.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .travis.yml
├── gradle.properties
├── LICENSE
├── .gitignore
├── gradlew.bat
├── README.md
└── gradlew
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/android-sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':library'
2 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesarferreira/kotlin-pluralizer/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android-sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesarferreira/kotlin-pluralizer/HEAD/android-sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesarferreira/kotlin-pluralizer/HEAD/android-sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesarferreira/kotlin-pluralizer/HEAD/android-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesarferreira/kotlin-pluralizer/HEAD/android-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesarferreira/kotlin-pluralizer/HEAD/android-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Pluralize
3 | Pluralize
4 |
5 |
--------------------------------------------------------------------------------
/android-sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Sep 04 18:06:35 WEST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/android-sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/android-sample/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/android-sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | mavenLocal()
5 | }
6 | }
7 |
8 | plugins {
9 | id 'com.jfrog.bintray' version '1.6'
10 | }
11 |
12 | apply plugin: 'java'
13 | apply plugin: 'kotlin'
14 | apply plugin: 'maven-publish'
15 |
16 | dependencies {
17 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
18 | testCompile 'junit:junit:4.13'
19 | }
20 | repositories {
21 | mavenCentral()
22 | }
23 |
24 | apply from: 'publish.gradle'
25 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - tools
6 | - platform-tools
7 | - build-tools-24.0.3
8 | - extra-android-m2repository
9 | - android-25
10 |
11 | jdk:
12 | - oraclejdk8
13 |
14 | branches:
15 | except:
16 | - gh-pages
17 |
18 | notifications:
19 | email: false
20 |
21 | sudo: false
22 |
23 | cache:
24 | directories:
25 | - $HOME/.gradle/caches/
26 | - $HOME/.gradle/wrapper/
27 | - $HOME/.gradle/native/
28 | - $HOME/.gradle/daemon/native/
29 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/cesar/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/android-sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/cesar/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/android-sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/android-sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/android-sample/src/main/res/layout/content_hello.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
21 |
22 |
--------------------------------------------------------------------------------
/android-sample/src/main/res/layout/activity_hello.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 César Ferreira
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/library/src/test/kotlin/com/cesarferreira/pluralize/SingularizationTest.kt:
--------------------------------------------------------------------------------
1 | package com.cesarferreira.pluralize
2 |
3 | import org.junit.Assert.assertEquals
4 | import org.junit.Test
5 |
6 | class SingularizationTest {
7 |
8 | @Test
9 | fun `Should remove default "s" suffix`() {
10 | assertEquals("word", "words".singularize())
11 | }
12 |
13 | @Test
14 | fun `Should handle unCountable words`() {
15 | assertEquals("scissors", "scissors".singularize())
16 | }
17 |
18 | @Test
19 | fun `Should handle exception words`() {
20 | assertEquals("person", "people".singularize())
21 | }
22 |
23 | @Test
24 | fun `Should handle in case insensitive manner`() {
25 | assertEquals("goy", "Goyim".singularize())
26 | }
27 |
28 | @Test
29 | fun `Should behave like pluralize for count larger than 1`() {
30 | assertEquals("posts", "post".singularize(5))
31 | assertEquals("descriptions", "description".singularize(2))
32 | assertEquals("collections", "collection".singularize(-2))
33 | assertEquals("versions", "version".singularize(-5))
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/android-sample/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
7 | }
8 | }
9 |
10 | apply plugin: 'com.android.application'
11 | apply plugin: 'kotlin-android'
12 | apply plugin: 'kotlin-android-extensions'
13 |
14 | android {
15 | compileSdkVersion 25
16 | buildToolsVersion "24.0.3"
17 | defaultConfig {
18 | minSdkVersion 16
19 | targetSdkVersion 25
20 | versionCode 1
21 | versionName "1.0"
22 | }
23 | lintOptions {
24 | abortOnError false
25 | }
26 |
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 | sourceSets {
34 | main.java.srcDirs += 'src/main/kotlin'
35 | }
36 | }
37 |
38 | dependencies {
39 | compile project(':library')
40 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
41 | compile 'com.android.support:appcompat-v7:25.1.0'
42 | compile 'com.android.support:design:25.1.0'
43 | }
44 | repositories {
45 | mavenCentral()
46 | }
47 |
--------------------------------------------------------------------------------
/android-sample/src/main/java/com/cesarferreira/pluralize/sample/HelloActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cesarferreira.pluralize.sample
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.support.v7.widget.Toolbar
6 | import com.cesarferreira.pluralize.pluralize
7 | import com.cesarferreira.pluralize.singularize
8 | import kotlinx.android.synthetic.main.content_hello.*
9 |
10 | class HelloActivity : AppCompatActivity() {
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(R.layout.activity_hello)
15 | val toolbar = findViewById(R.id.toolbar) as Toolbar
16 | setSupportActionBar(toolbar)
17 |
18 | val singulars = arrayOf("person", "banana", "woman")
19 |
20 | for (item in singulars) {
21 | concat("$item -> pluralize -> ${item.pluralize()}")
22 | }
23 |
24 | concat("")
25 | concat("")
26 |
27 | val plurals = arrayOf("words", "octopi", "sheep")
28 |
29 | for (item in plurals) {
30 | concat("$item -> singularize -> ${item.singularize()}")
31 | }
32 | }
33 |
34 | fun concat(str: String) {
35 | centerTextView.append(str + "\n")
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/library/src/test/kotlin/com/cesarferreira/pluralize/PluralizationTest.kt:
--------------------------------------------------------------------------------
1 | package com.cesarferreira.pluralize
2 |
3 | import org.junit.Assert.assertEquals
4 | import org.junit.Test
5 |
6 | class PluralizationTest {
7 |
8 | @Test
9 | fun `Should add default "s" suffix`() {
10 | assertEquals("posts", "post".pluralize())
11 | assertEquals("descriptions", "description".pluralize())
12 | assertEquals("collections", "collection".pluralize())
13 | assertEquals("versions", "version".pluralize())
14 | }
15 |
16 | @Test
17 | fun `Should handle unCountable words`() {
18 | assertEquals("aircraft", "aircraft".pluralize())
19 | }
20 |
21 | @Test
22 | fun `Should handle exception words`() {
23 | assertEquals("men", "man".pluralize())
24 | assertEquals("feet", "foot".pluralize())
25 | }
26 |
27 | @Test
28 | fun `Should handle in case insensitive manner`() {
29 | assertEquals("people", "Person".pluralize())
30 | }
31 |
32 | @Test
33 | fun `Should not add default "s" suffix for count = 1`() {
34 | assertEquals("post", "post".pluralize(1))
35 | assertEquals("description", "description".pluralize(-1))
36 | assertEquals("collection", "collection".pluralize(-1))
37 | assertEquals("version", "version".pluralize(1))
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/library/publish.gradle:
--------------------------------------------------------------------------------
1 |
2 | group "$ext_groupId"
3 | version "$ext_version"
4 |
5 | publishing {
6 | publications {
7 | MyPublication(MavenPublication) {
8 | from components.java
9 | artifact sourcesJar
10 | groupId "$ext_groupId"
11 | artifactId "$ext_artifactId"
12 | version "$ext_version"
13 | }
14 | }
15 | }
16 |
17 | task sourcesJar(type: Jar) {
18 | from sourceSets.main.java.srcDirs
19 | classifier = 'sources'
20 | }
21 |
22 | task javadocJar(type: Jar, dependsOn: javadoc) {
23 | classifier = 'javadoc'
24 | from javadoc.destinationDir
25 | }
26 |
27 |
28 | artifacts {
29 | archives javadocJar
30 | archives sourcesJar
31 | }
32 |
33 | bintray {
34 | user = System.getenv('BINTRAY_USER')
35 | key = System.getenv('BINTRAY_API_KEY')
36 |
37 | dryRun = false
38 | publish = true
39 |
40 | publications = ['MyPublication']
41 | pkg {
42 | repo = 'maven'
43 | name = "$ext_artifactId"
44 | licenses = ['Apache-2.0']
45 | labels = ['android', 'gradle-plugin']
46 |
47 | publicDownloadNumbers = true
48 | vcsUrl = "$ext_vcsUrl"
49 |
50 | version {
51 | name = "$ext_version"
52 | desc = "$ext_description"
53 | released = new Date()
54 | gpg {
55 | sign = true // Determines whether to GPG sign the files.
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | signing.properties
2 | keystore
3 | local.properties
4 | .gradle
5 |
6 | /.idea/workspace.xml
7 | /.idea/libraries
8 | .DS_Store
9 | /build
10 | /captures
11 | # Created by https://www.gitignore.io
12 |
13 | ### Android ###
14 | # Built application files
15 | *.apk
16 | *.ap_
17 |
18 | # Files for the Dalvik VM
19 | *.dex
20 |
21 | # Java class files
22 | *.class
23 |
24 | # Generated files
25 | gen/
26 |
27 | # Gradle files
28 | .gradle/
29 | build/
30 | /*/build/
31 |
32 | # Local configuration file (sdk path, etc)
33 | local.properties
34 |
35 | # Proguard folder generated by Eclipse
36 | proguard/
37 |
38 | # Log Files
39 | *.log
40 |
41 | ### Android Patch ###
42 | gen-external-apklibs
43 |
44 |
45 | ### Intellij ###
46 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
47 |
48 | *.iml
49 |
50 | ## Directory-based project format:
51 | .idea/
52 | # if you remove the above rule, at least ignore the following:
53 |
54 | # User-specific stuff:
55 | # .idea/workspace.xml
56 | # .idea/tasks.xml
57 | # .idea/dictionaries
58 |
59 | # Sensitive or high-churn files:
60 | # .idea/dataSources.ids
61 | # .idea/dataSources.xml
62 | # .idea/sqlDataSources.xml
63 | # .idea/dynamic.xml
64 | # .idea/uiDesigner.xml
65 |
66 | # Gradle:
67 | # .idea/gradle.xml
68 | # .idea/libraries
69 |
70 | # Mongo Explorer plugin:
71 | # .idea/mongoSettings.xml
72 |
73 | ## File-based project format:
74 | *.ipr
75 | *.iws
76 |
77 | ## Plugin-specific files:
78 |
79 | # IntelliJ
80 | /out/
81 |
82 | # mpeltonen/sbt-idea plugin
83 | .idea_modules/
84 |
85 | # JIRA plugin
86 | atlassian-ide-plugin.xml
87 |
88 | # Crashlytics plugin (for Android Studio and IntelliJ)
89 | com_crashlytics_export_strings.xml
90 | crashlytics.properties
91 | crashlytics-build.properties
92 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # kotlin-pluralizer
3 |
4 | **kotlin extension** to **pluralize** and **singularize** strings
5 |
6 | [](https://travis-ci.org/cesarferreira/kotlin-pluralizer) [](https://jitpack.io/#cesarferreira/kotlin-pluralizer)
7 |
8 | ### Show some love
9 | [](https://github.com/cesarferreira/kotlin-pluralizer) [](https://twitter.com/cesarmcferreira)
10 |
11 | ## Usage
12 |
13 |
14 | **Pluralization:**
15 |
16 | ```kotlin
17 | "person".pluralize() # => "people"
18 | "post".pluralize() # => "posts"
19 | "sheep".pluralize() # => "sheep"
20 | "foot".pluralize() # => "feet"
21 | ```
22 |
23 | **Singularization:**
24 |
25 | ```kotlin
26 | "words".singularize() # => "word"
27 | "octopi".singularize() # => "octopus"
28 | "people".singularize() # => "person"
29 | "feet".singularize() # => "foot"
30 | ```
31 |
32 | **Quantities:**
33 | ```kotlin
34 | "person".pluralize(1) # => "person"
35 | "person".pluralize(2) # => "people"
36 | ```
37 |
38 | ## Install
39 |
40 | ```groovy
41 | repositories {
42 | jcenter()
43 | maven { url "https://jitpack.io" }
44 | }
45 | dependencies {
46 | compile 'com.github.cesarferreira:kotlin-pluralizer:1.0.0'
47 | }
48 | ```
49 |
50 | ## Contributing
51 |
52 | I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:
53 | 1. Match coding style (braces, spacing, etc.) This is best achieved using `CMD`+`Option`+`L` (Reformat code) on Mac (not sure for Windows) with Android Studio defaults.
54 | 2. If its a feature, bugfix, or anything please only change code to what you specify.
55 | 3. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
56 | 4. Pull requests _must_ be made against `develop` branch. Any other branch (unless specified by the maintainers) will get rejected.
57 | 5. Check for existing [issues](https://github.com/cesarferreira/kotlin-pluralizer/issues) first, before filing an issue.
58 | 6. Have fun!
59 |
60 |
61 | ## Credits
62 |
63 | The pluralize and singularize methods are based on the code found in the following places.
64 |
65 | - https://github.com/rails/rails/blob/26698fb91d88dca0f860adcb80528d8d3f0f6285/activesupport/lib/active_support/inflector/inflections.rb
66 |
67 | - https://github.com/atteo/evo-inflector/blob/master/src/main/java/org/atteo/evo/inflector/English.java
68 | - http://www.java2s.com/Tutorial/Java/0040__Data-Type/Transformswordstosingularpluralhumanizedhumanreadableunderscorecamelcaseorordinalform.htm
69 | - https://github.com/MehdiK/Humanizer.jvm
70 |
71 |
72 | ### Created & Maintained By
73 | [Cesar Ferreira](https://github.com/cesarferreira) ([@cesarmcferreira](https://www.twitter.com/cesarmcferreira))
74 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
165 | if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
166 | cd "$(dirname "$0")"
167 | fi
168 |
169 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
170 |
--------------------------------------------------------------------------------
/library/src/main/kotlin/com/cesarferreira/pluralize/Pluralize.kt:
--------------------------------------------------------------------------------
1 | package com.cesarferreira.pluralize
2 |
3 | import java.util.regex.Pattern
4 |
5 | fun String.pluralize(count: Int = 2): String {
6 | return if (Math.abs(count)!= 1)
7 | this.pluralizer()
8 | else
9 | this.singularizer()
10 | }
11 |
12 | fun String.singularize(count: Int = 1): String = pluralize(count)
13 |
14 | private fun String.pluralizer(): String {
15 | if (unCountable().contains(this.toLowerCase())) return this
16 | val rule = pluralizeRules().last { Pattern.compile(it.component1(), Pattern.CASE_INSENSITIVE).matcher(this).find() }
17 | var found = Pattern.compile(rule.component1(), Pattern.CASE_INSENSITIVE).matcher(this).replaceAll(rule.component2())
18 | val endsWith = exceptions().firstOrNull { this.endsWith(it.component1()) }
19 | if (endsWith != null) found = this.replace(endsWith.component1(), endsWith.component2())
20 | val exception = exceptions().firstOrNull() { this.equals(it.component1(), true) }
21 | if (exception != null) found = exception.component2()
22 | return found
23 | }
24 |
25 | private fun String.singularizer(): String {
26 | if (unCountable().contains(this.toLowerCase())) {
27 | return this
28 | }
29 | val exceptions = exceptions().firstOrNull() { this.equals(it.component2(), true) }
30 |
31 | if (exceptions != null) {
32 | return exceptions.component1()
33 | }
34 | val endsWith = exceptions().firstOrNull { this.endsWith(it.component2()) }
35 |
36 | if (endsWith != null) return this.replace(endsWith.component2(), endsWith.component1())
37 |
38 | try {
39 | if (singularizeRules().count {
40 | Pattern.compile(it.component1(), Pattern.CASE_INSENSITIVE).matcher(this).find()
41 | } == 0) return this
42 | val rule = singularizeRules().last {
43 | Pattern.compile(it.component1(), Pattern.CASE_INSENSITIVE).matcher(this).find()
44 | }
45 | return Pattern.compile(rule.component1(), Pattern.CASE_INSENSITIVE).matcher(this).replaceAll(rule.component2())
46 | } catch(ex: IllegalArgumentException) {
47 | Exception("Can't singularize this word, could not find a rule to match.")
48 | }
49 | return this
50 | }
51 |
52 | fun unCountable(): List {
53 | return listOf("equipment", "information", "rice", "money",
54 | "species", "series", "fish", "sheep", "aircraft", "bison",
55 | "flounder", "pliers", "bream",
56 | "gallows", "proceedings", "breeches", "graffiti", "rabies",
57 | "britches", "headquarters", "salmon", "carp", "herpes",
58 | "scissors", "chassis", "high-jinks", "sea-bass", "clippers",
59 | "homework", "cod", "innings", "shears",
60 | "contretemps", "jackanapes", "corps", "mackerel",
61 | "swine", "debris", "measles", "trout", "diabetes", "mews",
62 | "tuna", "djinn", "mumps", "whiting", "eland", "news",
63 | "wildebeest", "elk", "pincers", "sugar")
64 | }
65 |
66 | fun exceptions(): List> {
67 | return listOf("person" to "people",
68 | "man" to "men",
69 | "goose" to "geese",
70 | "child" to "children",
71 | "sex" to "sexes",
72 | "move" to "moves",
73 | "stadium" to "stadiums",
74 | "deer" to "deer",
75 | "codex" to "codices",
76 | "murex" to "murices",
77 | "silex" to "silices",
78 | "radix" to "radices",
79 | "helix" to "helices",
80 | "alumna" to "alumnae",
81 | "alga" to "algae",
82 | "vertebra" to "vertebrae",
83 | "persona" to "personae",
84 | "stamen" to "stamina",
85 | "foramen" to "foramina",
86 | "lumen" to "lumina",
87 | "afreet" to "afreeti",
88 | "afrit" to "afriti",
89 | "efreet" to "efreeti",
90 | "cherub" to "cherubim",
91 | "goy" to "goyim",
92 | "human" to "humans",
93 | "lumen" to "lumina",
94 | "seraph" to "seraphim",
95 | "Alabaman" to "Alabamans",
96 | "Bahaman" to "Bahamans",
97 | "Burman" to "Burmans",
98 | "German" to "Germans",
99 | "Hiroshiman" to "Hiroshimans",
100 | "Liman" to "Limans",
101 | "Nakayaman" to "Nakayamans",
102 | "Oklahoman" to "Oklahomans",
103 | "Panaman" to "Panamans",
104 | "Selman" to "Selmans",
105 | "Sonaman" to "Sonamans",
106 | "Tacoman" to "Tacomans",
107 | "Yakiman" to "Yakimans",
108 | "Yokohaman" to "Yokohamans",
109 | "Yuman" to "Yumans", "criterion" to "criteria",
110 | "perihelion" to "perihelia",
111 | "aphelion" to "aphelia",
112 | "phenomenon" to "phenomena",
113 | "prolegomenon" to "prolegomena",
114 | "noumenon" to "noumena",
115 | "organon" to "organa",
116 | "asyndeton" to "asyndeta",
117 | "hyperbaton" to "hyperbata",
118 | "foot" to "feet")
119 | }
120 |
121 | fun pluralizeRules(): List> {
122 | return listOf(
123 | "$" to "s",
124 | "s$" to "s",
125 | "(ax|test)is$" to "$1es",
126 | "us$" to "i",
127 | "(octop|vir)us$" to "$1i",
128 | "(octop|vir)i$" to "$1i",
129 | "(alias|status)$" to "$1es",
130 | "(bu)s$" to "$1ses",
131 | "(buffal|tomat)o$" to "$1oes",
132 | "([ti])um$" to "$1a",
133 | "([ti])a$" to "$1a",
134 | "sis$" to "ses",
135 | "(,:([^f])fe|([lr])f)$" to "$1$2ves",
136 | "(hive)$" to "$1s",
137 | "([^aeiouy]|qu)y$" to "$1ies",
138 | "(x|ch|ss|sh)$" to "$1es",
139 | "(matr|vert|ind)ix|ex$" to "$1ices",
140 | "([m|l])ouse$" to "$1ice",
141 | "([m|l])ice$" to "$1ice",
142 | "^(ox)$" to "$1en",
143 | "(quiz)$" to "$1zes",
144 | "f$" to "ves",
145 | "fe$" to "ves",
146 | "um$" to "a",
147 | "on$" to "a",
148 | "tion" to "tions",
149 | "sion" to "sions")
150 | }
151 |
152 | fun singularizeRules(): List> {
153 | return listOf(
154 | "s$" to "",
155 | "(s|si|u)s$" to "$1s",
156 | "(n)ews$" to "$1ews",
157 | "([ti])a$" to "$1um",
158 | "((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$" to "$1$2sis",
159 | "(^analy)ses$" to "$1sis",
160 | "(^analy)sis$" to "$1sis",
161 | "([^f])ves$" to "$1fe",
162 | "(hive)s$" to "$1",
163 | "(tive)s$" to "$1",
164 | "([lr])ves$" to "$1f",
165 | "([^aeiouy]|qu)ies$" to "$1y",
166 | "(s)eries$" to "$1eries",
167 | "(m)ovies$" to "$1ovie",
168 | "(x|ch|ss|sh)es$" to "$1",
169 | "([m|l])ice$" to "$1ouse",
170 | "(bus)es$" to "$1",
171 | "(o)es$" to "$1",
172 | "(shoe)s$" to "$1",
173 | "(cris|ax|test)is$" to "$1is",
174 | "(cris|ax|test)es$" to "$1is",
175 | "(octop|vir)i$" to "$1us",
176 | "(octop|vir)us$" to "$1us",
177 | "(alias|status)es$" to "$1",
178 | "(alias|status)$" to "$1",
179 | "^(ox)en" to "$1",
180 | "(vert|ind)ices$" to "$1ex",
181 | "(matr)ices$" to "$1ix",
182 | "(quiz)zes$" to "$1",
183 | "a$" to "um",
184 | "i$" to "us",
185 | "ae$" to "a")
186 | }
187 |
--------------------------------------------------------------------------------