Skip to content

Commit 5731ae6

Browse files
committed
Fix RandomService#randomString for some eng-lang locales
1 parent 17b0d38 commit 5731ae6

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

core/src/main/kotlin/io/github/serpro69/kfaker/RandomService.kt

+22-4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class RandomService internal constructor(private val config: FakerConfig) {
177177
* Default: `24`
178178
* @param locale locale to use to generate the charset.
179179
* Defaults to `locale` config value set for the `faker` instance.
180+
* @param indexChars add additional index chars to the resulting string, as defined in
181+
* [Character_Elements](https://www.unicode.org/reports/tr35/tr35-general.html#Character_Elements).
182+
* Default: `true`
180183
* @param auxiliaryChars add additional auxiliary chars to the resulting string as defined in
181184
* [Character_Elements](https://www.unicode.org/reports/tr35/tr35-general.html#Character_Elements).
182185
* Default: `false`
@@ -193,10 +196,6 @@ class RandomService internal constructor(private val config: FakerConfig) {
193196
numericalChars: Boolean = false,
194197
): String {
195198
if (length < 1) return "" // base case
196-
if (locale in listOf(Locale.ENGLISH, Locale.US, Locale.UK, Locale.CANADA)) return randomString(
197-
length,
198-
numericalChars
199-
)
200199

201200
val localeData = LocaleData.getInstance(ULocale.forLocale(locale))
202201
val mainChars = localeData.getExemplarSet(UnicodeSet.MIN_VALUE, LocaleData.ES_STANDARD)
@@ -222,6 +221,25 @@ class RandomService internal constructor(private val config: FakerConfig) {
222221
return List(length) { chars.random(random.asKotlinRandom()) }.joinToString("")
223222
}
224223

224+
/**
225+
* Returns [String] with a randomLength withing the specified [min] and [max] boundaries
226+
* (or an empty string for if `randomLength < 1`)
227+
* consisting of pseudo-randomly generated characters
228+
* in a given [locale] with optional [auxiliaryChars] and [numericalChars]
229+
*
230+
* @param min the minimum length of the resulting string.
231+
* @param max the maximum length of the resulting string.
232+
* @param locale locale to use to generate the charset.
233+
* Defaults to `locale` config value set for the `faker` instance.
234+
* @param indexChars add additional index chars to the resulting string, as defined in
235+
* [Character_Elements](https://www.unicode.org/reports/tr35/tr35-general.html#Character_Elements).
236+
* Default: `true`
237+
* @param auxiliaryChars add additional auxiliary chars to the resulting string as defined in
238+
* [Character_Elements](https://www.unicode.org/reports/tr35/tr35-general.html#Character_Elements).
239+
* Default: `false`
240+
* @param numericalChars add additional numerical chars from 0 to 9 to the resulting string
241+
* Default: `false`
242+
*/
225243
@JvmOverloads
226244
fun randomString(
227245
min: Int,

0 commit comments

Comments
 (0)