diff --git a/.travis.yml b/.travis.yml
index db37ec3..fad41d9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,9 +4,9 @@ android:
components:
- tools
- platform-tools
- - build-tools-24.0.2
+ - build-tools-24.0.3
- extra-android-m2repository
- - android-24
+ - android-25
jdk:
- oraclejdk8
diff --git a/README.md b/README.md
index 1689ca2..a5a0e89 100644
--- a/README.md
+++ b/README.md
@@ -1,61 +1,72 @@
-
-# kotlin-pluralizer [](https://travis-ci.org/cesarferreira/kotlin-pluralizer) [](https://jitpack.io/#cesarferreira/kkotlin-pluralizer)
+# kotlin-pluralizer
+**kotlin extension** to **pluralize** and **singularize** strings
-**kotlin extension** to **pluralize** and **singularize** strings!
+[](https://travis-ci.org/cesarferreira/kotlin-pluralizer) [](https://jitpack.io/#cesarferreira/kotlin-pluralizer)
+### Show some love
+[](https://github.com/cesarferreira/kotlin-pluralizer) [](https://twitter.com/cesarmcferreira)
## Usage
+
**Pluralization:**
```kotlin
-"person".pluralize() # => "people"
-"post".pluralize() # => "posts"
-"sheep".pluralize() # => "sheep"
+"person".pluralize() # => "people"
+"post".pluralize() # => "posts"
+"sheep".pluralize() # => "sheep"
+"foot".pluralize() # => "feet"
```
**Singuralization:**
```kotlin
-"words".singularize() # => "word"
-"octopi".pluralize() # => "octopus"
+"words".singularize() # => "word"
+"octopi".singularize() # => "octopus"
+"people".singularize() # => "person"
+"feet".singularize() # => "foot"
+```
+**Quantities:**
+```kotlin
+"person".pluralize(1) # => "person"
+"person".pluralize(2) # => "people"
```
## Install
```groovy
repositories {
- jcenter()
- maven { url "https://jitpack.io" }
+ jcenter()
+ maven { url "https://jitpack.io" }
}
dependencies {
- compile 'com.github.cesarferreira:kotlin-pluralizer:0.1.0'
+ compile 'com.github.cesarferreira:kotlin-pluralizer:0.2.9'
}
```
-### Show some :heart:
-[](https://github.com/cesarferreira/kotlin-pluralizer) [](https://twitter.com/cesarmcferreira)
-
## Contributing
+
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:
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.
2. If its a feature, bugfix, or anything please only change code to what you specify.
3. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
4. Pull requests _must_ be made against `develop` branch. Any other branch (unless specified by the maintainers) will get rejected.
- 5. Check for existing [issues](https://github.com/cesarferreira/kotkotlin-pluralizer/issues) first, before filing an issue.
+ 5. Check for existing [issues](https://github.com/cesarferreira/kotlin-pluralizer/issues) first, before filing an issue.
6. Have fun!
- ## Credits
+## Credits
The pluralize and singularize methods are based on the code found in the following places.
+ - https://github.com/rails/rails/blob/26698fb91d88dca0f860adcb80528d8d3f0f6285/activesupport/lib/active_support/inflector/inflections.rb
+
- https://github.com/atteo/evo-inflector/blob/master/src/main/java/org/atteo/evo/inflector/English.java
- http://www.java2s.com/Tutorial/Java/0040__Data-Type/Transformswordstosingularpluralhumanizedhumanreadableunderscorecamelcaseorordinalform.htm
- - https://github.com/rails/rails/blob/26698fb91d88dca0f860adcb80528d8d3f0f6285/activesupport/lib/active_support/inflector/inflections.rb
+ - https://github.com/MehdiK/Humanizer.jvm
### Created & Maintained By
diff --git a/sample/.gitignore b/android-sample/.gitignore
similarity index 100%
rename from sample/.gitignore
rename to android-sample/.gitignore
diff --git a/sample/build.gradle b/android-sample/build.gradle
similarity index 61%
rename from sample/build.gradle
rename to android-sample/build.gradle
index b81014f..c3e679e 100644
--- a/sample/build.gradle
+++ b/android-sample/build.gradle
@@ -1,20 +1,29 @@
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
+ }
+}
+
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-android-extensions'
android {
- compileSdkVersion 24
- buildToolsVersion "24.0.2"
+ compileSdkVersion 25
+ buildToolsVersion "24.0.3"
defaultConfig {
- applicationId "com.cesarferreira.supposedlibrary"
minSdkVersion 16
- targetSdkVersion 24
+ targetSdkVersion 25
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
-
+
buildTypes {
release {
minifyEnabled false
@@ -29,8 +38,8 @@ android {
dependencies {
compile project(':library')
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
- compile 'com.android.support:appcompat-v7:24.2.0'
- compile 'com.android.support:design:24.2.0'
+ compile 'com.android.support:appcompat-v7:25.1.0'
+ compile 'com.android.support:design:25.1.0'
}
repositories {
mavenCentral()
diff --git a/sample/proguard-rules.pro b/android-sample/proguard-rules.pro
similarity index 100%
rename from sample/proguard-rules.pro
rename to android-sample/proguard-rules.pro
diff --git a/sample/src/main/AndroidManifest.xml b/android-sample/src/main/AndroidManifest.xml
similarity index 100%
rename from sample/src/main/AndroidManifest.xml
rename to android-sample/src/main/AndroidManifest.xml
diff --git a/sample/src/main/java/com/cesarferreira/pluralize/sample/HelloActivity.kt b/android-sample/src/main/java/com/cesarferreira/pluralize/sample/HelloActivity.kt
similarity index 52%
rename from sample/src/main/java/com/cesarferreira/pluralize/sample/HelloActivity.kt
rename to android-sample/src/main/java/com/cesarferreira/pluralize/sample/HelloActivity.kt
index 8f1e7d8..525867a 100644
--- a/sample/src/main/java/com/cesarferreira/pluralize/sample/HelloActivity.kt
+++ b/android-sample/src/main/java/com/cesarferreira/pluralize/sample/HelloActivity.kt
@@ -1,12 +1,11 @@
package com.cesarferreira.pluralize.sample
import android.os.Bundle
-import android.support.design.widget.FloatingActionButton
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
-import android.util.Log
import com.cesarferreira.pluralize.pluralize
import com.cesarferreira.pluralize.singularize
+import kotlinx.android.synthetic.main.content_hello.*
class HelloActivity : AppCompatActivity() {
@@ -16,16 +15,24 @@ class HelloActivity : AppCompatActivity() {
val toolbar = findViewById(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
- val fab = findViewById(R.id.fab) as FloatingActionButton
- fab.setOnClickListener({
- view ->
- Log.d("TAG", "person".pluralize())
- Log.d("TAG", "banana".pluralize())
- Log.d("TAG", "woman".pluralize())
+ val singulars = arrayOf("person", "banana", "woman")
- Log.d("TAG", "women".singularize())
+ for (item in singulars) {
+ concat("$item -> pluralize -> ${item.pluralize()}")
+ }
- })
+ concat("")
+ concat("")
+
+ val plurals = arrayOf("words", "octopi", "sheep")
+
+ for (item in plurals) {
+ concat("$item -> singularize -> ${item.singularize()}")
+ }
+ }
+
+ fun concat(str: String) {
+ centerTextView.append(str + "\n")
}
}
diff --git a/sample/src/main/res/layout/activity_hello.xml b/android-sample/src/main/res/layout/activity_hello.xml
similarity index 67%
rename from sample/src/main/res/layout/activity_hello.xml
rename to android-sample/src/main/res/layout/activity_hello.xml
index 48bfd3d..2b31fab 100644
--- a/sample/src/main/res/layout/activity_hello.xml
+++ b/android-sample/src/main/res/layout/activity_hello.xml
@@ -5,8 +5,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:fitsSystemWindows="true"
- tools:context="com.cesarferreira.supposedlibrary.com.cesarferreira.pluralize.sample.HelloActivity">
+ android:fitsSystemWindows="true">
-
-
diff --git a/sample/src/main/res/layout/content_hello.xml b/android-sample/src/main/res/layout/content_hello.xml
similarity index 75%
rename from sample/src/main/res/layout/content_hello.xml
rename to android-sample/src/main/res/layout/content_hello.xml
index 9ab9f39..104dfc2 100644
--- a/sample/src/main/res/layout/content_hello.xml
+++ b/android-sample/src/main/res/layout/content_hello.xml
@@ -11,7 +11,11 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
- tools:showIn="@layout/activity_hello"
- tools:context="com.cesarferreira.supposedlibrary.com.cesarferreira.pluralize.sample.HelloActivity">
+ tools:showIn="@layout/activity_hello">
+
diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher.png b/android-sample/src/main/res/mipmap-hdpi/ic_launcher.png
similarity index 100%
rename from sample/src/main/res/mipmap-hdpi/ic_launcher.png
rename to android-sample/src/main/res/mipmap-hdpi/ic_launcher.png
diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher.png b/android-sample/src/main/res/mipmap-mdpi/ic_launcher.png
similarity index 100%
rename from sample/src/main/res/mipmap-mdpi/ic_launcher.png
rename to android-sample/src/main/res/mipmap-mdpi/ic_launcher.png
diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png b/android-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
similarity index 100%
rename from sample/src/main/res/mipmap-xhdpi/ic_launcher.png
rename to android-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
similarity index 100%
rename from sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
rename to android-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
similarity index 100%
rename from sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
rename to android-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
diff --git a/sample/src/main/res/values-v21/styles.xml b/android-sample/src/main/res/values-v21/styles.xml
similarity index 100%
rename from sample/src/main/res/values-v21/styles.xml
rename to android-sample/src/main/res/values-v21/styles.xml
diff --git a/sample/src/main/res/values-w820dp/dimens.xml b/android-sample/src/main/res/values-w820dp/dimens.xml
similarity index 100%
rename from sample/src/main/res/values-w820dp/dimens.xml
rename to android-sample/src/main/res/values-w820dp/dimens.xml
diff --git a/sample/src/main/res/values/colors.xml b/android-sample/src/main/res/values/colors.xml
similarity index 100%
rename from sample/src/main/res/values/colors.xml
rename to android-sample/src/main/res/values/colors.xml
diff --git a/sample/src/main/res/values/dimens.xml b/android-sample/src/main/res/values/dimens.xml
similarity index 100%
rename from sample/src/main/res/values/dimens.xml
rename to android-sample/src/main/res/values/dimens.xml
diff --git a/sample/src/main/res/values/strings.xml b/android-sample/src/main/res/values/strings.xml
similarity index 53%
rename from sample/src/main/res/values/strings.xml
rename to android-sample/src/main/res/values/strings.xml
index 58e23dd..38e7cf4 100644
--- a/sample/src/main/res/values/strings.xml
+++ b/android-sample/src/main/res/values/strings.xml
@@ -1,4 +1,4 @@
Pluralize
- HelloActivity
+ Pluralize
diff --git a/sample/src/main/res/values/styles.xml b/android-sample/src/main/res/values/styles.xml
similarity index 100%
rename from sample/src/main/res/values/styles.xml
rename to android-sample/src/main/res/values/styles.xml
diff --git a/build.gradle b/build.gradle
index d987dad..dc8c0f7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlin_version = '1.0.3'
+ ext.kotlin_version = '1.0.6'
ext {
ext_groupId = 'com.cesarferreira'
ext_artifactId = 'kotlin-pluralizer'
- ext_version = '0.1.0'
+ ext_version = '0.2.9'
ext_url = 'https://github.com/cesarferreira/kotlin-pluralizer'
ext_vcsUrl = 'https://github.com/cesarferreira/kotlin-pluralizer.git'
ext_description = 'Kotlin extension to pluralize and singularize strings'
@@ -16,7 +16,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.2.0-rc1'
+ classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index b5fa945..3fb1e18 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
diff --git a/library/build.gradle b/library/build.gradle
index 02fde15..79f89cf 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -1,47 +1,19 @@
buildscript {
repositories {
- mavenCentral()
- }
-
- dependencies {
- classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
+ jcenter()
+ mavenLocal()
}
}
-apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android'
-apply plugin: 'com.github.dcendents.android-maven'
-
-android {
- compileSdkVersion 24
- buildToolsVersion "24.0.2"
-
- defaultConfig {
- minSdkVersion 16
- targetSdkVersion 24
- versionCode 1
- versionName "1.0"
-
- }
-
- lintOptions {
- abortOnError false
- }
-
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- sourceSets {
- main.java.srcDirs += 'src/main/kotlin'
- }
+plugins {
+ id 'com.jfrog.bintray' version '1.6'
}
+apply plugin: 'java'
+apply plugin: 'kotlin'
+apply plugin: 'maven-publish'
+
dependencies {
- compile gradleApi()
- compile 'com.android.support:appcompat-v7:24.2.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
diff --git a/library/publish.gradle b/library/publish.gradle
index a294eae..e6b8b08 100644
--- a/library/publish.gradle
+++ b/library/publish.gradle
@@ -1,52 +1,59 @@
-// build a jar with source files
+
+group "$ext_groupId"
+version "$ext_version"
+
+publishing {
+ publications {
+ MyPublication(MavenPublication) {
+ from components.java
+ artifact sourcesJar
+ groupId "$ext_groupId"
+ artifactId "$ext_artifactId"
+ version "$ext_version"
+ }
+ }
+}
+
task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
+ from sourceSets.main.java.srcDirs
classifier = 'sources'
}
-task javadoc(type: Javadoc) {
- failOnError false
- source = android.sourceSets.main.java.sourceFiles
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- classpath += configurations.compile
-}
-
-// build a jar with javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
+
artifacts {
- archives sourcesJar
archives javadocJar
+ archives sourcesJar
}
-//
-//bintray {
-// user = System.getenv('BINTRAY_USER')
-// key = System.getenv('BINTRAY_API_KEY')
-//
-// dryRun = false
-// publish = true
-//
-// publications = ['MyPublication']
-// pkg {
-// repo = 'maven'
-// name = "$ext_artifactId"
-// licenses = ['Apache-2.0']
-// labels = ['android', 'gradle-plugin']
-//
-// publicDownloadNumbers = true
-// vcsUrl = "$ext_vcsUrl"
-//
-// version {
-// name = "$ext_version"
-// desc = "$ext_description"
-// released = new Date()
-// gpg {
-// sign = true // Determines whether to GPG sign the files.
-// }
-// }
-// }
-//}
+bintray {
+ user = System.getenv('BINTRAY_USER')
+ key = System.getenv('BINTRAY_API_KEY')
+
+ dryRun = false
+ publish = true
+
+ publications = ['MyPublication']
+ pkg {
+ repo = 'maven'
+ name = "$ext_artifactId"
+ licenses = ['Apache-2.0']
+ labels = ['android', 'gradle-plugin']
+
+ publicDownloadNumbers = true
+ vcsUrl = "$ext_vcsUrl"
+
+ version {
+ name = "$ext_version"
+ desc = "$ext_description"
+ released = new Date()
+ gpg {
+ sign = true // Determines whether to GPG sign the files.
+ }
+ }
+ }
+}
diff --git a/library/src/main/java/com/cesarferreira/pluralize/Pluralize.kt b/library/src/main/kotlin/com/cesarferreira/pluralize/Pluralize.kt
similarity index 86%
rename from library/src/main/java/com/cesarferreira/pluralize/Pluralize.kt
rename to library/src/main/kotlin/com/cesarferreira/pluralize/Pluralize.kt
index db1d4cc..159c823 100644
--- a/library/src/main/java/com/cesarferreira/pluralize/Pluralize.kt
+++ b/library/src/main/kotlin/com/cesarferreira/pluralize/Pluralize.kt
@@ -25,34 +25,48 @@ fun String.singularize(plurality: Plurality = Plurality.Plural): String {
if (this.pluralizer() != this && this + "s" != this.pluralizer() &&
this.pluralizer().singularize() == this && this.singularizer() != this)
- return this;
+ return this
return this.singularize()
}
+fun String.pluralize(count: Int): String {
+ if (count > 1)
+ return this.pluralize(Plurality.Plural)
+ else
+ return this.pluralize(Plurality.Singular)
+}
+
+fun String.singularize(count: Int): String {
+ if (count > 1)
+ return this.singularize(Plurality.Plural)
+ else
+ return this.singularize(Plurality.Singular)
+}
+
private fun String.pluralizer(): String {
- if (unCountable().contains(this)) return this
+ if (unCountable().contains(this.toLowerCase())) return this
val rule = pluralizeRules().last { Pattern.compile(it.component1(), Pattern.CASE_INSENSITIVE).matcher(this).find() }
var found = Pattern.compile(rule.component1(), Pattern.CASE_INSENSITIVE).matcher(this).replaceAll(rule.component2())
- val endswith = exceptions().firstOrNull { this.endsWith(it.component1()) }
- if (endswith != null) found = this.replace(endswith.component1(), endswith.component2())
- val excep = exceptions().firstOrNull() { this.equals(it.component1()) }
- if (excep != null) found = excep.component2()
+ val endsWith = exceptions().firstOrNull { this.endsWith(it.component1()) }
+ if (endsWith != null) found = this.replace(endsWith.component1(), endsWith.component2())
+ val exception = exceptions().firstOrNull() { this.equals(it.component1()) }
+ if (exception != null) found = exception.component2()
return found
}
private fun String.singularizer(): String {
- if (unCountable().contains(this)) {
+ if (unCountable().contains(this.toLowerCase())) {
return this
}
- val excepions = exceptions().firstOrNull() { this.equals(it.component2()) }
+ val exceptions = exceptions().firstOrNull() { this.equals(it.component2()) }
- if (excepions != null) {
- return excepions.component1()
+ if (exceptions != null) {
+ return exceptions.component1()
}
- val endswith = exceptions().firstOrNull { this.endsWith(it.component2()) }
+ val endsWith = exceptions().firstOrNull { this.endsWith(it.component2()) }
- if (endswith != null) return this.replace(endswith.component2(), endswith.component1())
+ if (endsWith != null) return this.replace(endsWith.component2(), endsWith.component1())
try {
if (singularizeRules().count {
@@ -200,5 +214,3 @@ fun singularizeRules(): List> {
"i$" to "us",
"ae$" to "a")
}
-
-
diff --git a/library/src/main/java/com/cesarferreira/pluralize/utils/Plurality.kt b/library/src/main/kotlin/com/cesarferreira/pluralize/utils/Plurality.kt
similarity index 100%
rename from library/src/main/java/com/cesarferreira/pluralize/utils/Plurality.kt
rename to library/src/main/kotlin/com/cesarferreira/pluralize/utils/Plurality.kt
diff --git a/settings.gradle b/settings.gradle
index 52baf7e..b46971c 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-include ':sample', ':library'
+include ':android-sample', ':library'