Parse word (2 bytes)

@param &string $p Data.
@param bool $l Little-endian, defaults to false.
@return int
430230
public static function getWord(&$p, $l = false)
    {
        $r = static::bytes2int(static::binarySubstr($p, 0, 2), !!$l);
        $p = static::binarySubstr($p, 2);

        return intval($r);
    }
799521
@Override
    protected IWord nextLatinWord(int c, int pos) throws IOException
    {
        isb.clear();
        if ( c > 65280 ) c -= 65248;
        if ( c >= 65 && c <= 90 ) c += 32;
        isb.append((char)c);

        boolean _check = false, _wspace = false;
        ByteCharCounter counter = new ByteCharCounter();
        int ch, _ctype = 0, tcount = 1;             //number of different char type.
        int _TYPE  = StringUtil.getEnCharType(c);   //current char type.

        while ( (ch = readNext()) != -1 ) {
            //Covert the full-width char to half-width char.
            if ( ch > 65280 ) ch -= 65248;
            _ctype = StringUtil.getEnCharType(ch);
            if ( _ctype == StringUtil.EN_WHITESPACE ) {
                _wspace = true;
                break;
            }

            if ( _ctype == StringUtil.EN_PUNCTUATION ) {
                if ( ! StringUtil.isENKeepPunctuaton((char)ch) ) {
                    pushBack(ch);
                    break;
                }
                counter.increase((char)ch);
            }

            //Not EN_KNOW, and it could be letter, numeric.
            if ( _ctype == StringUtil.EN_UNKNOW ) {
                pushBack(ch);
                if ( StringUtil.isCJKChar( ch ) ) {
                    _check = true;
                }

                break;
            }

            //covert the lower case letter to upper case.
            if ( ch >= 65 && ch <= 90 ) ch += 32;
            if ( ch > 0 ) {
                isb.append((char)ch);
            }

            /* Char type counter.
             * condition to start the secondary segmentation.
             * @reader: we could do better.
             *
             * @added 2013-12-16
            */
            if ( _ctype != _TYPE ) {
                tcount++;
                _TYPE = _ctype;
            }

            if ( isb.length() > config.MAX_LATIN_LENGTH ) {
                break;
            }
        }

        /*
         * @added at 2016/11/24
         * clear the dot punctuation behind the string buffer
         * and recount the tcount as needed
        */
        int oLen = isb.length();
        for ( int i = oLen - 1; i > 0
                && StringUtil.isNoTailingPunctuation(isb.charAt(i)); i-- ) {
            pushBack(isb.charAt(i));
            isb.deleteCharAt(i);
            _check = false;
        }

        if ( oLen > isb.length()
                && ! StringUtil.isEnPunctuation(isb.last()) ) {
            tcount--;
        }



        IWord wd   = null;
        String str = isb.toString();
        String date = null;

        /*
         * special entity word check like email, URL, ip address
        */
        int colonNum = counter.get(':');
        int pointNum = counter.get('.');
        if ( counter.get('@') == 1 && pointNum > 0
                && EntityFormat.isMailAddress(str) ) {
            wd = new Word(str, IWord.T_BASIC_LATIN, Entity.E_EMAIL_A);
            wd.setPartSpeech(IWord.EN_POSPEECH);
            return wd;
        } else if ( tcount == 1 && StringUtil.isEnNumeric(isb.first())
                && EntityFormat.isMobileNumber(str) ) {
            wd = new Word(str, IWord.T_BASIC_LATIN, Entity.E_MOBILE_A);
            wd.setPartSpeech(IWord.NUMERIC_POSPEECH);
            return wd;
        } else if ( tcount == 7 && pointNum == 3
                && StringUtil.isEnNumeric(isb.first())
                && EntityFormat.isIpAddress(str) ) {
            wd = new Word(str, IWord.T_BASIC_LATIN, Entity.E_IP_A);
            wd.setPartSpeech(IWord.EN_POSPEECH);
            return wd;
        } else if ( pointNum > 0 && colonNum == 1
                && EntityFormat.isUrlAddress(str, dic) ) {
            wd = new Word(str, IWord.T_BASIC_LATIN, Entity.E_URL_A);
            wd.setPartSpeech(IWord.EN_POSPEECH);
            return wd;
        } else if ( pointNum == 2
                && (date = EntityFormat.isDate(str, '.')) != null ) {
            wd = new Word(date, IWord.T_BASIC_LATIN, Entity.E_DATETIME_YMD_A);
            wd.setPartSpeech(IWord.TIME_POSPEECH);
            return wd;
        } else if ( counter.get('-') >= 1
                && (date = EntityFormat.isDate(str, '-')) != null ) {
            String[] entity = counter.get('-') == 1
                    ? Entity.E_DATETIME_YM_A : Entity.E_DATETIME_YMD_A;
            wd = new Word(date, IWord.T_BASIC_LATIN, entity);
            wd.setPartSpeech(IWord.TIME_POSPEECH);
            return wd;
        } else if ( counter.get('/') >= 1
                && (date = EntityFormat.isDate(str, '/')) != null ) {
            String[] entity = counter.get('/') == 1
                    ? Entity.E_DATETIME_YM_A : Entity.E_DATETIME_YMD_A;
            wd = new Word(date, IWord.T_BASIC_LATIN, entity);
            wd.setPartSpeech(IWord.TIME_POSPEECH);
            return wd;
        } else if ( (tcount == 3 || tcount == 5)
                && colonNum >= 1 && EntityFormat.isTime(str) ) {
            String[] entity = colonNum == 1
                    ? Entity.E_DATETIME_HI_A : Entity.E_DATETIME_HIS_A;
            wd = new Word(str, IWord.T_BASIC_LATIN, entity);
            wd.setPartSpeech(IWord.TIME_POSPEECH);
            return wd;
        }

        /*
         * check the end condition.
         * and the check if the token loop was break by whitespace
         * cause there is no need to continue all the following work if it is.
        */
        if ( ch == -1 || _wspace ) {
            boolean isPercentage = false;
            for ( int i = isb.length() - 1; i > 0; i-- ) {
                if ( isb.charAt(i) == '%' ) {
                    if ( i > 0 && StringUtil.isEnNumeric(isb.charAt(i-1)) ) {
                        isPercentage = true;
                        break;
                    }
                } else if ( ! StringUtil.isEnPunctuation(isb.charAt(i)) ) {
                    break;
                }

                /*
                 * try to find a English and punctuation mixed word.
                 * this will clear all the punctuation until a mixed word is found.
                 * like "i love c++.", c++ will be found from token "c++.".
                */
                if ( dic.match(ILexicon.CJK_WORD, str) ) {
                    wd = dic.get(ILexicon.CJK_WORD, str).clone();
                    break;
                }

                pushBack(isb.charAt(i));
                isb.deleteCharAt(i);
                str = isb.toString();
            }

            if ( wd == null ) {
                if ( isPercentage ) {
                    wd = new Word(str, IWord.T_BASIC_LATIN,
                    		Entity.E_NUMERIC_PERCENTAGE_A);
                    wd.setPartSpeech(IWord.NUMERIC_POSPEECH);
                } else if ( tcount == 1 && StringUtil.isDigit(str) ) {
                    wd = new Word(str, IWord.T_BASIC_LATIN,
                    		Entity.E_NUMERIC_ARABIC_A);
                    wd.setPartSpeech(IWord.NUMERIC_POSPEECH);
                } else if ( tcount == 3 && StringUtil.isDecimal(str) ) {
                    wd = new Word(str, IWord.T_BASIC_LATIN,
                    		Entity.E_NUMERIC_DECIMAL_A);
                    wd.setPartSpeech(IWord.NUMERIC_POSPEECH);
                } else if ( dic.match(ILexicon.CJK_WORD, str) ) {
                    wd = dic.get(ILexicon.CJK_WORD, str).clone();
                } else {
                    wd = new Word(str, IWord.T_BASIC_LATIN);
                    wd.setPartSpeech(IWord.EN_POSPEECH);
                }
            }

            if ( wd.getPartSpeech() == null ) {
                wd.setPartSpeech(IWord.EN_POSPEECH);
            }

            return wd;
        }

        /*
         * the loop was broken by an unknown char and it is not a CJK char
         * 1, check if the end char is a special single unit char like '℉,℃' and so on ..
         * 2, or do it as the end stream way like (ch == -1 or _wspace == true)
        */
        if ( _check == false ) {
            /*
             * we check the units here, so we can recognize
             * many other units that is not Chinese like '℉,℃' and so on ...
            */
            boolean isDigit = StringUtil.isDigit(str);
            if ( isDigit || StringUtil.isDecimal(str) ) {
                ch = readNext();
                String unit = ((char)ch)+"";
                if ( dic.match(ILexicon.CJK_UNIT, unit) ) {
                    wd = getNumericUnitComposedWord(
                    		str, dic.get(ILexicon.CJK_UNIT, unit));
                } else {
                    String[] entity = isDigit
                    		? Entity.E_NUMERIC_ARABIC_A
                    				: Entity.E_NUMERIC_DECIMAL_A;
                    wd = new Word(str, IWord.T_BASIC_LATIN, entity);
                    wd.setPartSpeech(IWord.NUMERIC_POSPEECH);
                    pushBack(ch);
                }
            }

            if ( wd == null ) {
                if ( dic.match(ILexicon.CJK_WORD, str) ) {
                    wd = dic.get(ILexicon.CJK_WORD, str).clone();
                } else {
                    wd = new Word(str, IWord.T_BASIC_LATIN);
                }
            }

            if ( wd.getPartSpeech() == null ) {
                wd.setPartSpeech(IWord.EN_POSPEECH);
            }

            return wd;
        }

        /*
         * check and recognize the percentage
        */
        int length = isb.length();
        if ( length > 1 && isb.charAt(length-1) == '%'
                && StringUtil.isEnNumeric(isb.charAt(length-2)) ) {
            wd = new Word(str, IWord.T_BASIC_LATIN,
            		Entity.E_NUMERIC_PERCENTAGE_A);
            wd.setPartSpeech(IWord.NUMERIC_POSPEECH);
            return wd;
        }

        /*
         * check and get English and Chinese mixed word like 'B超, x射线'
         *
         * Attention:
         * make sure that (ch = readNext()) is after j < Config.MIX_CN_LENGTH.
         * or it cause the miss of the next char.
         *
         * @reader: (2013-09-25)
         * we do not check the type of the char read next.
         * so, words started with English and its length except the start English part
         * less than config.MIX_CN_LENGTH in the EC dictionary could be recognized.
         *
         * @Note added at 2017/08/05
         * Add the ibuffer.length checking logic to follow the limitation
         * of the maximum length of the current token
        */
        IStringBuffer ibuffer = new IStringBuffer(str);
        String tstr = null;
        int mc = 0, j = 0;        //the number of char that read from the stream.
        ialist.clear();
        for ( ; j < dic.mixSuffixLength
                && ibuffer.length() < config.MAX_LENGTH
                    && (ch = readNext()) != -1; j++ ) {
            /*
             * Attention:
             * it is a accident that Jcseg works fine for
             * we break the loop directly when we meet a whitespace.
             * 1, if a EC word is found, unit check process will be ignore.
             * 2, if matches no EC word, certainly return of readNext()
             *   will make sure the units check process works fine.
            */
            if ( StringUtil.isWhitespace(ch) ) {
                pushBack(ch);
                break;
            }

            ibuffer.append((char)ch);
            ialist.add(ch);
            tstr = ibuffer.toString();
            if ( dic.match(ILexicon.CJK_WORD, tstr) ) {
                wd  = dic.get(ILexicon.CJK_WORD, tstr);
                mc = j + 1;
            }
        }

        ibuffer.clear();
        ibuffer = null;                 //Let gc do it's work.
        for ( int i = j - 1; i >= mc; i-- ) {
            pushBack(ialist.get(i));    //push back the read chars.
        }

        if ( wd != null ) {
            wd = wd.clone();
            if ( wd.getPartSpeech() == null ) {
                wd.setPartSpeech(IWord.MIX_POSPEECH);
            }

            return wd;
        }

        /*
         * check the unit for the digit or the decimal Latin
        */
        boolean isDigit = StringUtil.isDigit(str);
        if ( isDigit || StringUtil.isDecimal(str) ) {
            ialist.clear();
            IWord unitWord = null;
            IStringBuffer sb = new IStringBuffer();
            for ( j = 0; j < config.MAX_UNIT_LENGTH
                    && (ch = readNext()) != -1; j++ ) {
                if ( StringUtil.isWhitespace(ch) ) {
                    pushBack(ch);
                    break;
                }

                sb.append((char)ch);
                ialist.add(ch);
                tstr = sb.toString();
                if ( dic.match(ILexicon.CJK_UNIT, tstr) ) {
                    unitWord = dic.get(ILexicon.CJK_UNIT, tstr);
                    mc = j + 1;
                }
            }

            if ( unitWord == null ) {
            	String[] entity = isDigit
                		? Entity.E_NUMERIC_ARABIC_A
                				: Entity.E_NUMERIC_DECIMAL_A;
                wd = new Word(str, IWord.T_BASIC_LATIN, entity);
                wd.setPartSpeech(IWord.NUMERIC_POSPEECH);
            } else {
            	wd = getNumericUnitComposedWord(str, unitWord);
            }

            for ( int i = j - 1; i >= mc; i-- ) {
                pushBack(ialist.get(i));
            }
        }

        /*
         * simply return the combination of English char, Arabic
         * numeric, English punctuation if matches no single units or EC word.
        */
        if ( wd == null ) {
            if ( dic.match(ILexicon.CJK_WORD, str) ) {
                wd = dic.get(ILexicon.CJK_WORD, str).clone();
            } else {
                wd = new Word(str, IWord.T_BASIC_LATIN);
            }

            if ( wd.getPartSpeech() == null ) {
                wd.setPartSpeech(IWord.EN_POSPEECH);
            }
        }

        return wd;
    }
603473
public function inverse($p)
    {
        //$theta;
        //$arg;

        $p->x-= $this->x0;
        //~ $p->y -= $this->y0;
        $arg = $p->y / (1.4142135623731 * $this->a);

        // Because of division by zero problems, 'arg' can not be 1.0.  Therefore
        // a number very close to one is used instead.
        if (abs($arg) > 0.999999999999) {
            $arg = 0.999999999999;
        }

        $theta = asin( $arg );
        $lon = Common::adjust_lon( $this->long0 + ($p->x / (0.900316316158 * $this->a * cos( $theta ))) );

        if ($lon < (-Common::PI)) {
            $lon = -Common::PI;
        }

        if ($lon > Common::PI) {
            $lon = Common::PI;
        }

        $arg = (2.0 * $theta + sin(2.0 * $theta)) / Common::PI;

        if (abs($arg) > 1.0) {
            $arg = 1.0;
        }

        $lat = asin($arg);
        //return(OK);

        $p->x = $lon;
        $p->y = $lat;

        return $p;
    }
1138318
function littleEndianToUint32(data, offset)
{
	return (littleEndianToUint8(data, offset + 3) << 24) +
		(littleEndianToUint8(data, offset + 2) << 16) +
		(littleEndianToUint8(data, offset + 1) << 8) +
		littleEndianToUint8(data, offset)
}
509716
function getbytes($l)
	{
		for($i = 0; $i < $l; $i++)
		{
			if($this->mod == 'C_FILE')
			{
        		$bin = unpack('C*', fread($this->fin, 1));
        		$this->buffer[$i] = $bin[1];
        	}
        	else if($this->mod == 'C_MEMORY')
        	{
                $bin = unpack('C*', substr($this->fin, $this->ch, 1));
                $this->buffer[$i] = $bin[1];
                $this->ch++;
        	}
		}
		return $this->buffer;
	}
253491
public final TextBuilder p(long l) {
        if (null != __buffer) __append(l);
        else __caller.p(l);
        return this;
    }
802077
public function readLong32Bit()
    {
        $wordHigh = $this->readInt();
        $wordLow  = $this->readInt();

        if ($wordHigh & (int)0x80000000) {
            // It's a negative value since the highest bit is set
            if ($wordHigh == (int)0xFFFFFFFF  &&  ($wordLow & (int)0x80000000)) {
                return $wordLow;
            } else {
                include_once 'Zend/Search/Lucene/Exception.php';
                throw new Zend_Search_Lucene_Exception('Long integers lower than -2147483648 (0x80000000) are not supported on 32-bit platforms.');
            }

        }

        if ($wordLow < 0) {
            // Value is large than 0x7FFF FFFF. Represent low word as float.
            $wordLow &= 0x7FFFFFFF;
            $wordLow += (float)0x80000000;
        }

        if ($wordHigh == 0) {
            // Return value as integer if possible
            return $wordLow;
        }

        return $wordHigh*(float)0x100000000/* 0x00000001 00000000 */ + $wordLow;
    }
359134
static function _utf8_wordwrap2($str, $width = 75, $break = "\n", $cut = false)
	{
		if(!$cut)
			$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.',}\b#U';
		else
			$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#';

		if(function_exists('mb_strlen'))
			$str_len = mb_strlen($str,'UTF-8');
		else
			$str_len = preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $var_empty);

		$while_what = ceil($str_len / $width);
		$i = 1;
		$return = '';

		while ($i < $while_what)
		{
			preg_match($regexp, $str, $matches);
//			var_dump($regexp, $str, $matches);
			$string = $matches[0];
			$return .= $string.$break;
			$str = substr($str, strlen($string));
			$i++;
		}

		return $return.$str;
	}
1191499
public function inverse(float $p): float
    {
        if ($p < 0 || $p > 1) {
            throw new OutOfBoundsException("p must be between 0 and 1; given a p of $p");
        }
        if ($p == 1) {
            return \INF;
        }

        return -log(1 - $p) / $this->λ;
    }
72969
public static function getStrQWord(&$p, $l = false)
    {
        $r = mb_orig_substr($p, 0, 8);
        if ($l) {
            $r = strrev($r);
        }
        $p = mb_orig_substr($p, 8);
        return $r;
    }
974151
public function read($len = null)
    {
        $buffer = $this->in->read($len);
        if ($buffer === -1) {
            return -1;
        }
        $newStr = '';
        $tokens = token_get_all($buffer);

        foreach ($tokens as $token) {
            if (is_array($token)) {
                list($id, $text) = $token;

                switch ($id) {
                    case T_COMMENT:
                    case T_DOC_COMMENT:
                        // no action on comments
                        continue 2;

                    default:
                        $newStr .= $text;
                        continue 2;
                }
            }
            $newStr .= $token;
        }

        return $newStr;
    }
928125
protected static function binarySubstr($s, $p, $len = null)
    {
        if ($len === null) {
            $ret = substr($s, $p);
        } else {
            $ret = substr($s, $p, $len);
        }

        if ($ret === false) {
            $ret = '';
        }

        return $ret;
    }
94976
private function readMoWords($fp, $offset, $count, $pack)
    {
        fseek($fp, $offset);

        return unpack($pack . $count, fread($fp, $count * 4));
    }
1208670
private static function retrievePositiveInteger(string $data): string
    {
        while (0 === \mb_strpos($data, '00', 0, '8bit') && \mb_substr($data, 2, 2, '8bit') > '7f') {
            $data = \mb_substr($data, 2, null, '8bit');
        }

        return $data;
    }
688923
public function read($len = null)
    {
        if ($this->processed === true) {
            return -1; // EOF
        }

        // Read XML
        $php = null;
        while (($buffer = $this->in->read($len)) !== -1) {
            $php .= $buffer;
        }

        if ($php === null) { // EOF?

            return -1;
        }

        if (empty($php)) {
            $this->log("PHP file is empty!", Project::MSG_WARN);

            return ''; // return empty string, don't attempt to strip whitespace
        }

        // write buffer to a temporary file, since php_strip_whitespace() needs a filename
        $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
        file_put_contents($file->getAbsolutePath(), $php);
        $output = php_strip_whitespace($file->getAbsolutePath());
        unlink($file->getAbsolutePath());

        $this->processed = true;

        return $output;
    }
450235
def read_double(self, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.unpack("%sd" % endian, 8)
805567
public static long parseLong(String s, long l) {
		if (s == null) {
			return l;
		}
		try {
			return Long.parseLong(s.trim());
		} catch (NumberFormatException e) {
			return l;
		}
	}