@@ -228,6 +228,84 @@ export function /* 9.2.4 */BestFitMatcher (availableLocales, requestedLocales) {
228
228
return LookupMatcher ( availableLocales , requestedLocales ) ;
229
229
}
230
230
231
+ // @spec [tc39/ecma402/master/spec/negotiation.html]
232
+ // @clause [sec-unicodeextensionsubtags]
233
+ export function UnicodeExtensionSubtags ( extension ) {
234
+ // 1. Let size be the number of elements in extension.
235
+ let size = extension . length ;
236
+ // 2. If size = 0, then
237
+ if ( size === 0 ) {
238
+ // a. Return « ».
239
+ return [ ] ;
240
+ }
241
+ // 3. Let extensionSubtags be « ».
242
+ let extensionSubtags = [ ] ;
243
+ // 4. Let attribute be true.
244
+ let attribute = true ;
245
+ // 5. Let q be 3.
246
+ let q = 3 ;
247
+ // 6. Let p be q.
248
+ let p = q ;
249
+ // 7. Let t be q.
250
+ let t = q ;
251
+ // 8. Repeat, while q < size
252
+ while ( q < size ) {
253
+ // a. Let c be the code unit value of the element at index q in the String extension.
254
+ let c = extension . codePointAt ( q ) ;
255
+ // a. If c is 0x002D (HYPHEN-MINUS), then
256
+ if ( c === 0x002D ) {
257
+ // i. If q - p = 2, then
258
+ if ( q - p === 2 ) {
259
+ // 1. If p - t > 1, then
260
+ if ( p - t > 1 ) {
261
+ // a. Let type be a String value equal to the substring of extension consisting of the code units at indices t (inclusive) through p - 1 (exclusive).
262
+ let type = extension . substring ( t , p - 1 ) ;
263
+ // a. Append type as the last element of extensionSubtags.
264
+ extensionSubtags . push ( type ) ;
265
+ }
266
+ // 2. Let key be a String value equal to the substring of extension consisting of the code units at indices p (inclusive) through q (exclusive).
267
+ let key = extension . substring ( p , q ) ;
268
+ // 3. Append key as the last element of extensionSubtags.
269
+ extensionSubtags . push ( key ) ;
270
+ // 4. Let t be q + 1.
271
+ t = q + 1 ;
272
+ // 5. Let attribute be false.
273
+ attribute = false ;
274
+ // ii. Else if attribute is true, then
275
+ } else if ( attribute === true ) {
276
+ // 1. Let attr be a String value equal to the substring of extension consisting of the code units at indices p (inclusive) through q (exclusive).
277
+ let attr = extension . substring ( p , q ) ;
278
+ // 2. Append attr as the last element of extensionSubtags.
279
+ extensionSubtags . push ( attr ) ;
280
+ // 3. Let t be q + 1.
281
+ t = q + 1 ;
282
+ }
283
+ // iii. Let p be q + 1.
284
+ p = q + 1 ;
285
+ }
286
+ // a. Let q be q + 1.
287
+ q = q + 1 ;
288
+ }
289
+ // 9. If size - p = 2, then
290
+ if ( size - p === 2 ) {
291
+ // a. If p - t > 1, then
292
+ if ( p - t > 1 ) {
293
+ // i. Let type be a String value equal to the substring of extension consisting of the code units at indices t (inclusive) through p - 1 (exclusive).
294
+ let type = extension . substring ( t , p - 1 ) ;
295
+ // ii. Append type as the last element of extensionSubtags.
296
+ extensionSubtags . push ( type ) ;
297
+ }
298
+ // a. Let t be p.
299
+ t = p ;
300
+ }
301
+ // 10. Let tail be a String value equal to the substring of extension consisting of the code units at indices t (inclusive) through size (exclusive).
302
+ let tail = extension . substring ( t , size ) ;
303
+ // 11. Append tail as the last element of extensionSubtags.
304
+ extensionSubtags . push ( tail ) ;
305
+ // 12. Return extensionSubtags.
306
+ return extensionSubtags ;
307
+ }
308
+
231
309
/**
232
310
* The ResolveLocale abstract operation compares a BCP 47 language priority list
233
311
* requestedLocales against the locales in availableLocales and determines the
@@ -268,15 +346,10 @@ export function /* 9.2.5 */ResolveLocale (availableLocales, requestedLocales, op
268
346
if ( hop . call ( r , '[[extension]]' ) ) {
269
347
// a. Let extension be the value of r.[[extension]].
270
348
let extension = r [ '[[extension]]' ] ;
271
- // b. Let split be the standard built-in function object defined in ES5,
272
- // 15.5.4.14.
273
- let split = String . prototype . split ;
274
- // c. Let extensionSubtags be the result of calling the [[Call]] internal
275
- // method of split with extension as the this value and an argument
276
- // list containing the single item "-".
277
- extensionSubtags = split . call ( extension , '-' ) ;
278
- // d. Let extensionSubtagsLength be the result of calling the [[Get]]
279
- // internal method of extensionSubtags with argument "length".
349
+ // b. Let _extensionSubtags_ be
350
+ // CreateArrayFromList(UnicodeExtensionSubtags(_extension_)).
351
+ extensionSubtags = UnicodeExtensionSubtags ( extension ) ;
352
+ // c. Let _extensionSubtagsLength_ be Get(_extensionSubtags_, *"length"*)
280
353
extensionSubtagsLength = extensionSubtags . length ;
281
354
}
282
355
0 commit comments