Merge pull request #19 from chirino/master

Simplify the String.toRegex extension to a single function
This commit is contained in:
James Strachan
2012-03-13 07:13:18 -07:00
3 changed files with 22 additions and 12 deletions
-12
View File
@@ -104,15 +104,3 @@ inline fun <T> java.util.Collection<T>.notEmpty() : Boolean = !this.isEmpty()
inline fun <T> java.util.Collection<T>?.orEmpty() : Collection<T>
= if (this != null) this else Collections.EMPTY_LIST as Collection<T>
/** Converts the string into a regular expression [[Pattern]] so that strings can be split or matched on */
inline fun String.toRegex(): Pattern {
return Pattern.compile(this).sure()
}
/**
* Converts the string into a regular expression [[Pattern]] with the given flags from [[Pattern]] or'd together
* so that strings can be split or matched on
*/
inline fun String.toRegex(flags: Int): Pattern {
return Pattern.compile(this, flags).sure()
}
+9
View File
@@ -113,6 +113,15 @@ inline fun String.toLong() = java.lang.Long.parseLong(this).sure()
inline fun String.toFloat() = java.lang.Float.parseFloat(this).sure()
inline fun String.toDouble() = java.lang.Double.parseDouble(this).sure()
/**
* Converts the string into a regular expression [[Pattern]] optionally
* with the specified flags from [[Pattern]] or'd together
* so that strings can be split or matched on.
*/
inline fun String.toRegex(flags: Int=0): java.util.regex.Pattern {
return java.util.regex.Pattern.compile(this, flags).sure()
}
/**
Iterator for characters of given CharSequence
*/