Skip to content

Commit

Permalink
Fixed typo in BCP 47 variant sub-regex, improved singleton/variant du…
Browse files Browse the repository at this point in the history
…pe matching
  • Loading branch information
andyearnshaw committed May 8, 2013
1 parent 06e4687 commit 495303a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions Intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var

// variant = 5*8alphanum ; registered variants
// / (DIGIT 3alphanum)
variant = '(?:[a-z0-9]{5-8}|\\d[a-z0-9]{3})',
variant = '(?:[a-z0-9]{5,8}|\\d[a-z0-9]{3})',

// ; Single alphanumerics
// ; "x" reserved for private use
Expand Down Expand Up @@ -135,11 +135,11 @@ var
// / grandfathered ; grandfathered tags
expBCP47Syntax = RegExp('^(?:'+langtag+'|'+privateuse+'|'+grandfathered+')$', 'i');

// Match duplicate variants in a language tag ###TODO: Fix###
expVariantDupes = RegExp('-('+variant+')-(?:[a-z0-9]{2,8})*\\1(?![a-z0-9])', 'i');
// Match duplicate variants in a language tag
expVariantDupes = RegExp('\\b('+variant+')-(?:\\w{4,8}-)*\\1\\b', 'i');

// Match duplicate singletons in a language tag
expSingletonDupes = RegExp('-('+singleton+')-(?:[a-z0-9]{2,}-)*\\1(?![a-z0-9])', 'i');
expSingletonDupes = RegExp('\\b('+singleton+')-(?:\\w+-)*\\1\\b', 'i');
})();

// Sect 6.2 Language Tags
Expand All @@ -161,21 +161,20 @@ var
* interpreted as the Unicode equivalents of the ASCII octet values given.
*/
function /* 6.2.2 */IsStructurallyValidLanguageTag(locale) {
// - represents a well-formed BCP 47 language tag as specified in RFC 5646
if (expBCP47Syntax.test(locale))
// represents a well-formed BCP 47 language tag as specified in RFC 5646
if (!expBCP47Syntax.test(locale))
return false;

// - does not include duplicate variant subtags, and
// does not include duplicate variant subtags, and
if (expVariantDupes.test(locale))
return false;

// - does not include duplicate singleton subtags.
// does not include duplicate singleton subtags.
if (expSingletonDupes.test(locale))
return false;

return true;
}
window.isvlt = IsStructurallyValidLanguageTag;

/**
* The CanonicalizeLanguageTag abstract operation returns the canonical and case-
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ environments.

### Implemented:
- All internal methods except for some that are implementation dependent
- Checking structural validity of language tags
- __`Intl.NumberFormat`__
- The `Intl.NumberFormat` constructor ([11.1](http://www.ecma-international.org/ecma-402/1.0/#sec-11.1))
- Properties of the `Intl.NumberFormat` Constructor ([11.2](http://www.ecma-international.org/ecma-402/1.0/#sec-11.2))
Expand All @@ -29,7 +30,6 @@ environments.

### Not Implemented
- Canonicalizing language tags
- Checking structural validity of language tags
- `BestFitSupportedLocales` internal function
- Implementation-dependent numbering system mappings
- Collator objects (`Intl.Collator`)
Expand Down

0 comments on commit 495303a

Please sign in to comment.