1 /*
  2  * isPunct.js - Character type is punctuation
  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_p
 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 punctuation.<p>
 29  *
 30  * @static
 31  * @param {string|IString|number} ch character or code point to examine
 32  * @return {boolean} true if the first character is punctuation.
 33  */
 34 var isPunct = function (ch) {
 35     var num;
 36     switch (typeof(ch)) {
 37         case 'number':
 38             num = ch;
 39             break;
 40         case 'string':
 41             num = IString.toCodePoint(ch, 0);
 42             break;
 43         case 'undefined':
 44             return false;
 45         default:
 46             num = ch._toCodePoint(0);
 47             break;
 48     }
 49 
 50     return ilib.data.ctype_p ?
 51         (CType._inRange(num, 'Pd', ilib.data.ctype_p) ||
 52         CType._inRange(num, 'Ps', ilib.data.ctype_p) ||
 53         CType._inRange(num, 'Pe', ilib.data.ctype_p) ||
 54         CType._inRange(num, 'Pc', ilib.data.ctype_p) ||
 55         CType._inRange(num, 'Po', ilib.data.ctype_p) ||
 56         CType._inRange(num, 'Pi', ilib.data.ctype_p) ||
 57         CType._inRange(num, 'Pf', ilib.data.ctype_p)) :
 58         ((num >= 0x21 && num <= 0x2F) ||
 59         (num >= 0x3A && num <= 0x40) ||
 60         (num >= 0x5B && num <= 0x60) ||
 61         (num >= 0x7B && num <= 0x7E));
 62 };
 63 
 64 /**
 65  * @protected
 66  * @param {boolean} sync
 67  * @param {Object|undefined} loadParams
 68  * @param {function(*)|undefined} onLoad
 69  */
 70 isPunct._init = function (sync, loadParams, onLoad) {
 71     CType._load("ctype_p", sync, loadParams, onLoad);
 72 };
 73 
 74 module.exports = isPunct;
 75