@@ -73,22 +73,6 @@ class StringGenerator {
73
73
private static readonly DEFAULT_SURROGATE_PAIR_PROBABILITY = 0.33 ;
74
74
private static readonly DEFAULT_MAX_LENGTH = 20 ;
75
75
76
- // The first Unicode code point that is in the basic multilingual plane ("BMP") and,
77
- // therefore requires 1 UTF-16 code unit to be represented in UTF-16.
78
- private static readonly MIN_BMP_CODE_POINT = 0x00000000 ;
79
-
80
- // The last Unicode code point that is in the basic multilingual plane ("BMP") and,
81
- // therefore requires 1 UTF-16 code unit to be represented in UTF-16.
82
- private static readonly MAX_BMP_CODE_POINT = 0x0000ffff ;
83
-
84
- // The first Unicode code point that is outside of the basic multilingual plane ("BMP") and,
85
- // therefore requires 2 UTF-16 code units, a surrogate pair, to be represented in UTF-16.
86
- private static readonly MIN_SUPPLEMENTARY_CODE_POINT = 0x00010000 ;
87
-
88
- // The last Unicode code point that is outside of the basic multilingual plane ("BMP") and,
89
- // therefore requires 2 UTF-16 code units, a surrogate pair, to be represented in UTF-16.
90
- private static readonly MAX_SUPPLEMENTARY_CODE_POINT = 0x0010ffff ;
91
-
92
76
private readonly rnd : Random ;
93
77
private readonly surrogatePairProbability : number ;
94
78
private readonly maxLength : number ;
@@ -198,31 +182,19 @@ class StringGenerator {
198
182
}
199
183
200
184
private nextNonSurrogateCodePoint ( ) : number {
201
- return this . nextCodePointRange (
202
- StringGenerator . MIN_BMP_CODE_POINT ,
203
- StringGenerator . MAX_BMP_CODE_POINT
204
- ) ;
185
+ let codePoint ;
186
+ do {
187
+ codePoint = this . nextCodePointRange ( 0 , 0xffff ) ; // BMP range
188
+ } while ( codePoint >= 0xd800 && codePoint <= 0xdfff ) ; // Exclude surrogate range
189
+
190
+ return codePoint ;
205
191
}
206
192
207
193
private nextCodePointRange ( min : number , max : number ) : number {
208
194
const rangeSize = max - min + 1 ;
209
195
const offset = this . rnd . nextInt ( rangeSize ) ;
210
196
return min + offset ;
211
197
}
212
-
213
- // private nextCodePointRange(min: number, max: number, expectedCharCount: number): number {
214
- // const rangeSize = max - min;
215
- // const offset = this.rnd.nextInt(rangeSize);
216
- // const codePoint = min + offset;
217
- // if (String.fromCharCode(codePoint).length !== expectedCharCount) {
218
- // throw new Error(
219
- // `internal error vqgqnxcy97: Character.charCount(${codePoint}) returned ${
220
- // String.fromCharCode(codePoint).length
221
- // }, but expected ${expectedCharCount}`,
222
- // );
223
- // }
224
- // return codePoint;
225
- // }
226
198
}
227
199
228
200
class Random {
0 commit comments