dom/phonenumberutils/PhoneNumberNormalizer.jsm

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
michael@0 3
michael@0 4 // Don't modify this code. Please use:
michael@0 5 // https://github.com/andreasgal/PhoneNumber.js
michael@0 6
michael@0 7 "use strict";
michael@0 8
michael@0 9 this.EXPORTED_SYMBOLS = ["PhoneNumberNormalizer"];
michael@0 10
michael@0 11 this.PhoneNumberNormalizer = (function() {
michael@0 12 const UNICODE_DIGITS = /[\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9]/g;
michael@0 13 const VALID_ALPHA_PATTERN = /[a-zA-Z]/g;
michael@0 14 const LEADING_PLUS_CHARS_PATTERN = /^[+\uFF0B]+/g;
michael@0 15 const NON_DIALABLE_CHARS = /[^,#+\*\d]/g;
michael@0 16
michael@0 17 // Map letters to numbers according to the ITU E.161 standard
michael@0 18 var E161 = {
michael@0 19 'a': 2, 'b': 2, 'c': 2,
michael@0 20 'd': 3, 'e': 3, 'f': 3,
michael@0 21 'g': 4, 'h': 4, 'i': 4,
michael@0 22 'j': 5, 'k': 5, 'l': 5,
michael@0 23 'm': 6, 'n': 6, 'o': 6,
michael@0 24 'p': 7, 'q': 7, 'r': 7, 's': 7,
michael@0 25 't': 8, 'u': 8, 'v': 8,
michael@0 26 'w': 9, 'x': 9, 'y': 9, 'z': 9
michael@0 27 };
michael@0 28
michael@0 29 // Normalize a number by converting unicode numbers and symbols to their
michael@0 30 // ASCII equivalents and removing all non-dialable characters.
michael@0 31 function NormalizeNumber(number, numbersOnly) {
michael@0 32 if (typeof number !== 'string') {
michael@0 33 return '';
michael@0 34 }
michael@0 35
michael@0 36 number = number.replace(UNICODE_DIGITS,
michael@0 37 function (ch) {
michael@0 38 return String.fromCharCode(48 + (ch.charCodeAt(0) & 0xf));
michael@0 39 });
michael@0 40 if (!numbersOnly) {
michael@0 41 number = number.replace(VALID_ALPHA_PATTERN,
michael@0 42 function (ch) {
michael@0 43 return String(E161[ch.toLowerCase()] || 0);
michael@0 44 });
michael@0 45 }
michael@0 46 number = number.replace(LEADING_PLUS_CHARS_PATTERN, "+");
michael@0 47 number = number.replace(NON_DIALABLE_CHARS, "");
michael@0 48 return number;
michael@0 49 };
michael@0 50
michael@0 51
michael@0 52 return {
michael@0 53 Normalize: NormalizeNumber
michael@0 54 };
michael@0 55 })();

mercurial