Parse length-value structure.

@param &string $p
@param int $l number of length bytes.
@param bool $nul Null-terminated, defaults to false.
@param bool $lrev Little-endian, default to false.
@return string
17446
public static function getLV(&$p, $l = 1, $nul = false, $lrev = false)
    {
        $s = static::b2i(static::binarySubstr($p, 0, $l), !!$lrev);
        $p = static::binarySubstr($p, $l);

        if ($s == 0) {
            return '';
        }

        $r = '';

        if (strlen($p) < $s) {
            echo("getLV error: buf length (" . strlen($p) . "): " . Debug::exportBytes($p) . ", must be >= string length (" . $s . ")\n");

        } else if ($nul) {
            if ($p{$s - 1} != "\x00") {
                echo("getLV error: Wrong end of NUL-string (" . Debug::exportBytes($p{$s - 1}) . "), len " . $s . "\n");
            } else {
                $d = $s - 1;
                if ($d < 0)
                {
                    $d = 0;
                }
                $r = static::binarySubstr($p, 0, $d);
                $p = static::binarySubstr($p, $s);
            }

        } else {
            $r = static::binarySubstr($p, 0, $s);
            $p = static::binarySubstr($p, $s);
        }

        return $r;
    }
1288648
public final String prn(final Map<String, Object> pAddParam,
    final BigDecimal pVal) {
    return this.srvNumberToString.print(pVal.toString(),
      (String) pAddParam.get("decSepv"),
        (String) pAddParam.get("decGrSepv"),
          (Integer) pAddParam.get("reportDp"),
            (Integer) pAddParam.get("digInGr"));
  }
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;
    }
577632
def p_expr(self, p):
        
        if len(p) == 2:
            p[0] = p[1]
        else:
            p[0] = ast.Comma(left=p[1], right=p[3])
1031479
public function parseEncodedBinary(&$s, &$p)
    {
        $f = ord(mb_orig_substr($s, $p, 1));
        ++$p;

        if ($f <= 250) {
            return $f;
        }

        if ($s === 251) {
            return null;
        }

        if ($s === 255) {
            return false;
        }

        if ($f === 252) {
            $o = $p;
            $p += 2;

            return $this->bytes2int(mb_orig_substr($s, $o, 2));
        }

        if ($f === 253) {
            $o = $p;
            $p += 3;

            return $this->bytes2int(mb_orig_substr($s, $o, 3));
        }

        $o = $p;
        $p = +8;

        return $this->bytes2int(mb_orig_substr($s, $o, 8));
    }
804328
private int parseLength() throws IOException {
        int curLen = 0;
        if (dataPos == dataSize)
            return curLen;
        int lenByte = data[dataPos++] & 0xff;
        if (isIndefinite(lenByte)) {
            ndefsList.add(new Integer(dataPos));
            unresolved++;
            return curLen;
        }
        if (isLongForm(lenByte)) {
            lenByte &= LEN_MASK;
            if (lenByte > 4) {
                throw new IOException("Too much data");
            }
            if ((dataSize - dataPos) < (lenByte + 1)) {
                throw new IOException("Too little data");
            }
            for (int i = 0; i < lenByte; i++) {
                curLen = (curLen << 8) + (data[dataPos++] & 0xff);
            }
            if (curLen < 0) {
                throw new IOException("Invalid length bytes");
            }
        } else {
           curLen = (lenByte & LEN_MASK);
        }
        return curLen;
    }
1053382
public static function lengthSort($val_1, $val_2)
    {
        // initialize the return value to zero
        $retVal = 0;

        // compare lengths
        $firstVal = strlen($val_1);
        $secondVal = strlen($val_2);

        if ($firstVal > $secondVal) {
            $retVal = 1;
        } elseif ($firstVal < $secondVal) {
            $retVal = -1;
        }

        return $retVal;
    }
1192886
function getLengthOfLength(lenValue, indefiniteLength) {
  var lenOfLen;
  
  if (indefiniteLength) {
    lenOfLen = 3;
  } else if (lenValue > 0x00FFFFFF) {
    lenOfLen = 5;
  } else if (lenValue > 0x0000FFFF) {
    lenOfLen = 4;
  } else if (lenValue > 0x000000FF) {
    lenOfLen = 3;
  } else if (lenValue > 0x0000007F) {
    lenOfLen = 2; 
  } else {
    lenOfLen = 1;
  }
  
  return lenOfLen
}
1126587
protected function _validate_length($value, $parameter)
    {
        $len = mb_strlen($value);
        if (preg_match('#^(\d+)-(\d+)$#', $parameter, $match)) {
            return $len >= $match[1] && $len <= $match[2] ? $value : null;
        } else {
            throw new InvalidValueException(['length validator `:parameter` parameters is not {minLength}-{maxLength} format', 'parameter' => $parameter]);
        }
    }
155420
def p_length(self, p):
        ''
        p[0] = Length(p[2], p[4], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
819147
private static function _decodeLongFormLength(int $length, string $data,
        int &$offset): string
    {
        // first octet must not be 0xff (spec 8.1.3.5c)
        if ($length == 127) {
            throw new DecodeException("Invalid number of length octets.");
        }
        $num = gmp_init(0, 10);
        while (--$length >= 0) {
            $byte = ord($data[$offset++]);
            $num <<= 8;
            $num |= $byte;
        }
        return gmp_strval($num);
    }
526814
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $buffer = $this->in->read($len);

        if ($buffer === -1) {
            return -1;
        }

        $lines = explode("\n", $buffer);
        $filtered = [];

        $commentsSize = count($this->_comments);

        foreach ($lines as $line) {
            for ($i = 0; $i < $commentsSize; $i++) {
                $comment = $this->_comments[$i]->getValue();
                if (StringHelper::startsWith($comment, ltrim($line))) {
                    $line = null;
                    break;
                }
            }
            if ($line !== null) {
                $filtered[] = $line;
            }
        }

        $filtered_buffer = implode("\n", $filtered);

        return $filtered_buffer;
    }
822747
public static function getQword(&$p, $l = false)
    {
        $r = static::bytes2int(mb_orig_substr($p, 0, 8), !!$l);
        $p = mb_orig_substr($p, 8);
        return (int)$r;
    }
774102
static public function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8')
        {
            static::string($value, $message);

            if (mb_strlen($value, $encoding) < $minLength) {
                $message = $message ?: sprintf(
                    'Value "%s" is too short, it should have more than %d characters, but only has %d characters.',
                    static::stringify($value),
                    $minLength,
                    mb_strlen($value, $encoding)
                );

                $constraints = array('min_length' => $minLength, 'encoding' => $encoding);

                throw static::createException($value, $message, static::INVALID_MIN_LENGTH, $propertyPath, $constraints);
            }
        }
530310
public function parseEncodedString(&$s, &$p)
    {
        $l = $this->parseEncodedBinary($s, $p);

        if ($l === null || $l === false) {
            return $l;
        }

        $o = $p;
        $p += $l;

        return mb_orig_substr($s, $o, $l);
    }
46129
def p_string_expr_lp(p):
    
    if p[2].type_ != TYPE.string:
        syntax_error(p.lexer.lineno,
                     "Expected a string type expression. "
                     "Got %s type instead" % TYPE.to_string(p[2].type_))
        p[0] = None
    else:
        p[0] = make_strslice(p.lexer.lineno, p[2], p[4][0], p[4][1])
543008
function load($lpData, &$hdrLen)
	{
		$hdrLen = 0;

		$this->m_lpVer = substr($lpData, 0, 6);
		if(($this->m_lpVer <> "GIF87a") && ($this->m_lpVer <> "GIF89a")) {
			return false;
		}

		$this->m_nWidth  = $this->w2i(substr($lpData, 6, 2));
		$this->m_nHeight = $this->w2i(substr($lpData, 8, 2));
		if(!$this->m_nWidth || !$this->m_nHeight) {
			return false;
		}

		$b = ord(substr($lpData, 10, 1));
		$this->m_bGlobalClr  = ($b & 0x80) ? true : false;
		$this->m_nColorRes   = ($b & 0x70) >> 4;
		$this->m_bSorted     = ($b & 0x08) ? true : false;
		$this->m_nTableSize  = 2 << ($b & 0x07);
		$this->m_nBgColor    = ord(substr($lpData, 11, 1));
		$this->m_nPixelRatio = ord(substr($lpData, 12, 1));
		$hdrLen = 13;

		if($this->m_bGlobalClr) {
			$this->m_colorTable = new CGIFCOLORTABLE();
			if(!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
				return false;
			}
			$hdrLen += 3 * $this->m_nTableSize;
		}

		return true;
	}