1 /*
  2  * isXdigit.js - Character type is hex digit
  3  *
  4  * Copyright © 2012-2015, 2018, JEDLSoft
  5  *
  6  * Licensed under the Apache License, Version 2.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at
  9  *
 10  *     http://www.apache.org/licenses/LICENSE-2.0
 11  *
 12  * Unless required by applicable law or agreed to in writing, software
 13  * distributed under the License is distributed on an "AS IS" BASIS,
 14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  *
 16  * See the License for the specific language governing permissions and
 17  * limitations under the License.
 18  */
 19 
 20 // !data ctype
 21 
 22 var ilib = require("../index.js");
 23 
 24 var CType = require("./CType.js");
 25 var IString = require("./IString.js");
 26 
 27 /**
 28  * Return whether or not the first character is a hexadecimal digit written
 29  * in the Latin script. (0-9 or A-F)<p>
 30  *
 31  * @static
 32  * @param {string|IString|number} ch character or code point to examine
 33  * @return {boolean} true if the first character is a hexadecimal digit written
 34  * in the Latin script.
 35  */
 36 var isXdigit = function (ch) {
 37     var num;
 38     switch (typeof(ch)) {
 39         case 'number':
 40             num = ch;
 41             break;
 42         case 'string':
 43             num = IString.toCodePoint(ch, 0);
 44             break;
 45         case 'undefined':
 46             return false;
 47         default:
 48             num = ch._toCodePoint(0);
 49             break;
 50     }
 51 
 52     return ilib.data.ctype ? CType._inRange(num, 'xdigit', ilib.data.ctype) :
 53         ((num >= 0x30 && num <= 0x39) || (num >= 0x41 && num <= 0x46) || (num >= 0x61 && num <= 0x66));
 54 };
 55 
 56 /**
 57  * @protected
 58  * @param {boolean} sync
 59  * @param {Object|undefined} loadParams
 60  * @param {function(*)|undefined} onLoad
 61  */
 62 isXdigit._init = function (sync, loadParams, onLoad) {
 63     CType._init(sync, loadParams, onLoad);
 64 };
 65 
 66 module.exports = isXdigit;