Simplify parseInt function (#3410)
Refactored the parseInt function to use toIntOrNull() for more concise and idiomatic error handling. This change simplifies the code and avoids the need for manual exception handling
This commit is contained in:
1 parent
146d20ce86
commit
52699967cd
1 file changed
+2
-7
@@ -63,15 +63,10 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun parseInt(str: String?, default: Int): Int {
|
fun parseInt(str: String?, default: Int): Int {
|
||||||
str ?: return default
|
return str?.toIntOrNull() ?: default
|
||||||
return try {
|
|
||||||
Integer.parseInt(str)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
default
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get text from clipboard
|
* get text from clipboard
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user