Test whether a length of text is surrounded by alphanumeric characters

@param  integer $pos Start of the text
@param  integer $len Length of the text
@return bool
499984
public function isSurroundedByAlnum($pos, $len)
	{
		return ($pos > 0 && $this->isAlnum($this->text[$pos - 1]) && $this->isAlnum($this->text[$pos + $len]));
	}
356636
public static function getRangeFromPosition(int $pos, int $length, string $text): Range {
        $start = self::getLineCharacterPositionFromPosition($pos, $text);
        $end = self::getLineCharacterPositionFromPosition($pos + $length, $text);

        return new Range($start, $end);
    }
485860
public function skipSpaces($pos)
    {
        
        for ( $max = strlen ($this->src); $pos < $max; $pos++) {
            if (!$this->md->utils->isSpace($this->src[$pos])) { break; }
        }
        return $pos;
    }
14975
private static function extractTilde($text, $pos) {
        if ($text[$pos] === '~') {
            if (isset($text[$pos + 1])) {
                // Do we have a tilde?
                if ($text[$pos + 1] === '~') {
                    return '~~';
                } elseif ($text[$pos + 1] === 'F') {
                    // Do we have a number after?
                    if (isset($text[$pos + 2])) {
                        $v = intval($text[$pos + 2]);
                        if ($v >= 1 && $v <= 4) {
                            return '~F' . $v;
                        } else {
                            throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.');
                        }
                    } else {
                        throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.');
                    }
                } else {
                    throw new CINParseException('code128', 'Wrong code after the ~.');
                }
            } else {
                throw new CINParseException('code128', 'Wrong code after the ~.');
            }
        } else {
            throw new CINParseException('code128', 'There is no ~ at this location.');
        }
    }
1102458
public function parseLinkDestination($str, $pos, $max)
    {
        $lines = 0;
        $start = $pos;
        $result = new \stdClass();
        $result->ok = false;
        $result->pos = 0;
        $result->lines = 0;
        $result->str = '';

        if( $pos === $max ) return $result;

        if ($str[$pos] === '<') {
            $pos++;
            while ($pos < $max) {
                $ch= $str[$pos];
                if ($str[$pos] == "\n" || $this->utils->isSpace($ch)) { return $result; }
                if ($ch === '>') {
                    $result->pos = $pos + 1;
                    $result->str = $this->utils->unescapeAll(substr($str, $start + 1, $pos-($start+1)));
                    $result->ok = true;
                    return $result;
                }
                if ($ch === '\\' && $pos + 1 < $max) {
                    $pos += 2;
                    continue;
                }

                $pos++;
            }

            // no closing '>'
            return $result;
        }

        // this should be ... } else { ... branch

        $level = 0;
        while ($pos < $max) {
            $ch = $str[$pos];

            if ($ch === ' ') { break; }

            // ascii control characters
            $code = ord($ch);
            if ($code < 0x20 || $code === 0x7F) { break; }

            if ($ch === '\\' && $pos + 1 < $max) {
                $pos += 2;
                continue;
            }

            if ($ch === '(' ) {
                $level++;
            }

            if ($ch === ')' ) {
                if ($level === 0) { break; }
                $level--;
            }

            $pos++;
        }

        if ($start === $pos) { return $result; }
        if ($level !== 0) { return $result; }

        $result->str = $this->utils->unescapeAll(substr($str, $start, $pos-$start));
        $result->lines = $lines;
        $result->pos = $pos;
        $result->ok = true;
        return $result;
    }
78074
public function overwrite($pos, $len)
	{
		if ($len > 0)
		{
			$this->text = substr($this->text, 0, $pos) . str_repeat("\x1A", $len) . substr($this->text, $pos + $len);
		}
	}
1169694
protected function get_num_parts($len)
    {
        $min_l = min($len, $this->minPart);
        $max_l = max($len, $this->maxPart);

        $n = $len - $min_l + 1;
        $d = $max_l - $min_l;
        $m = $n - $d;

        $s1 = $m * ($d + 1);
        $s2 = $d * ($d + 1) / 2;
        $s = $s1 + $s2;

        return (int) $s;
    }
870716
public static function len($text, $len)
	{
	    if (is_array($len)) {
	        if (!isset($len['len'])) {
	            throw new \InvalidArgumentException('The $len argument must have "len" key');
	        }
	        $len = $len['minLen'];
	    }

	    return strlen($text) == $len;
	}
132872
public static function isXhtmlLength($length)
    {
        if (is_int($length) === true) {
            return $length >= 0;
        } elseif (is_string($length) === true) {
            return preg_match("/[0-9]+%/", $length) === 1;
        } else {
            return false;
        }
    }
360515
public function length($len, $msg)
    {
        if(strlen(trim($this->_value)) != $len) {
            $this->_errors[] = $msg;
        }
        return $this;
    }
320981
public function read($length)
    {
        if ($this->currentPos >= $this->charCount) {
            return false;
        }
        $ret = false;
        $length = ($this->currentPos + $length > $this->charCount) ? $this->charCount - $this->currentPos : $length;
        switch ($this->mapType) {
            case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
                $len = $length * $this->map;
                $ret = substr($this->datas,
                        $this->currentPos * $this->map,
                        $len);
                $this->currentPos += $length;
                break;

            case Swift_CharacterReader::MAP_TYPE_INVALID:
                $ret = '';
                for (; $this->currentPos < $length; ++$this->currentPos) {
                    if (isset($this->map[$this->currentPos])) {
                        $ret .= '?';
                    } else {
                        $ret .= $this->datas[$this->currentPos];
                    }
                }
                break;

            case Swift_CharacterReader::MAP_TYPE_POSITIONS:
                $end = $this->currentPos + $length;
                $end = $end > $this->charCount ? $this->charCount : $end;
                $ret = '';
                $start = 0;
                if ($this->currentPos > 0) {
                    $start = $this->map['p'][$this->currentPos - 1];
                }
                $to = $start;
                for (; $this->currentPos < $end; ++$this->currentPos) {
                    if (isset($this->map['i'][$this->currentPos])) {
                        $ret .= substr($this->datas, $start, $to - $start).'?';
                        $start = $this->map['p'][$this->currentPos];
                    } else {
                        $to = $this->map['p'][$this->currentPos];
                    }
                }
                $ret .= substr($this->datas, $start, $to - $start);
                break;
        }

        return $ret;
    }
1234663
static function maxLengthByWords($str, $len = 50)
    {
        $str = self::removeHTMLSpecialChars($str);
        $cut = "\x1\x2\x3";
        $str = strip_tags($str);
        list($str) = explode($cut, wordwrap($str, $len, $cut));

        return $str;
    }
1146490
static public function UnpackStringWithLength($str, &$pos)
    {
        $length = self::ExtractUShort($str, $pos);

        $data = substr($str, $pos, $length);
        $pos += $length;

        return $data;
    }
690451
static function End($string, $length = 0)
    {    
        self::InitEncoding();
        $pos = max(0, self::Length($string) - $length);
        return self::Part($string, $pos);
    }
1049199
float  parseNumber(String input, int startpos, int len)
   {
      boolean  isNegative = false;
      long     significand = 0;
      int      numDigits = 0;
      int      numLeadingZeroes = 0;
      int      numTrailingZeroes = 0;
      boolean  decimalSeen = false;
      int      sigStart;
      int      decimalPos = 0;
      int      exponent;

      long     TOO_BIG = Long.MAX_VALUE / 10;

      pos = startpos;

      if (pos >= len)
        return Float.NaN;  // String is empty - no number found

      char  ch = input.charAt(pos);
      switch (ch) {
         case '-': isNegative = true;
                   // fall through
         case '+': pos++;
      }

      sigStart = pos;

      while (pos < len)
      {
         ch = input.charAt(pos);
         if (ch == '0')
         {
            if (numDigits == 0) {
               numLeadingZeroes++;
            } else {
               // We potentially skip trailing zeroes. Keep count for now.
               numTrailingZeroes++;
            }
         }
         else if (ch >= '1' && ch <= '9')
         {
            // Multiply any skipped zeroes into buffer
            numDigits += numTrailingZeroes;
            while (numTrailingZeroes > 0) {
               if (significand > TOO_BIG) {
                  //Log.e("Number is too large");
                  return Float.NaN;
               }
               significand *= 10;
               numTrailingZeroes--;
            }

            if (significand > TOO_BIG) {
               // We will overflow if we continue...
               //Log.e("Number is too large");
               return Float.NaN;
            }
            significand = significand * 10 + ((int)ch - (int)'0');
            numDigits++;
            
            if (significand < 0)
               return Float.NaN;  // overflowed from +ve to -ve
         }
         else if (ch == '.')
         {
            if (decimalSeen) {
               // Stop parsing here.  We may be looking at a new number.
               break;
            }
            decimalPos = pos - sigStart;
            decimalSeen = true;
         }
         else
            break;
         pos++;
      }

      if (decimalSeen && pos == (decimalPos + 1)) {
         // No digits following decimal point (eg. "1.")
         //Log.e("Missing fraction part of number");
         return Float.NaN;
      }

      // Have we seen anything number-ish at all so far?
      if (numDigits == 0) {
         if (numLeadingZeroes == 0) {
            //Log.e("Number not found");
            return Float.NaN;
         }
         // Leading zeroes have been seen though, so we
         // treat that as a '0'.
         numDigits = 1;
      }

      if (decimalSeen) {
         exponent = decimalPos - numLeadingZeroes - numDigits;
      } else {
         exponent = numTrailingZeroes;
      }

      // Now look for exponent
      if (pos < len)
      {
         ch = input.charAt(pos);
         if (ch == 'E' || ch == 'e')
         {
            boolean  expIsNegative = false;
            int      expVal = 0;
            boolean  abortExponent = false;

            pos++;
            if (pos == len) {
               // Incomplete exponent.
               //Log.e("Incomplete exponent of number");
               return Float.NaN;
            }

            switch (input.charAt(pos)) {
               case '-': expIsNegative = true;
                  // fall through
               case '+': pos++;
                  break;
               case '0': case '1': case '2': case '3': case '4':
               case '5': case '6': case '7': case '8': case '9':
                   break; // acceptable next char
               default:
                  // any other character is a failure, ie no exponent.
                  // Could be something legal like "em" though.
                  abortExponent = true;
                  pos--;  // reset pos to position of 'E'/'e'
            }

            if (!abortExponent)
            {
               int  expStart = pos;

               while (pos < len)
               {
                  ch = input.charAt(pos);
                  if (ch >= '0' && ch <= '9')
                  {
                     if (expVal > TOO_BIG) {
                        // We will overflow if we continue...
                        //Log.e("Exponent of number is too large");
                        return Float.NaN;
                     }
                     expVal = expVal * 10 + ((int)ch - (int)'0');
                     pos++;
                  }
                  else
                     break;
               }

               // Check that at least some exponent digits were read
               if (pos == expStart) {
                  //Log.e(""Incomplete exponent of number"");
                  return Float.NaN;
               }

               if (expIsNegative)
                  exponent -= expVal;
               else
                  exponent += expVal;
            }
         }
      }

      // Quick check to eliminate huge exponents.
      // Biggest float is (2 - 2^23) . 2^127 ~== 3.4e38
      // Biggest negative float is 2^-149 ~== 1.4e-45
      // Some numbers that will overflow will get through the scan
      // and be returned as 'valid', yet fail when value() is called.
      // However they will be very rare and not worth slowing down
      // the parse for.
      if ((exponent + numDigits) > 39 || (exponent + numDigits) < -44)
         return Float.NaN;

      float  f = (float) significand;

      if (significand != 0)
      {
         // Do exponents > 0
         if (exponent > 0)
         {
            f *= positivePowersOf10[exponent];
         }
         else if (exponent < 0)
         {
            // Some valid numbers can have an exponent greater than the max (ie. < -38)
            // for a float.  For example, significand=123, exponent=-40
            // If that's the case, we need to apply the exponent in two steps.
            if (exponent < -38) {
               // Long.MAX_VALUE is 19 digits, so taking 20 off the exponent should be enough. 
               f *= 1e-20;
               exponent += 20;
            }
            // Do exponents < 0
            f *= negativePowersOf10[-exponent];
         }
      }

      return (isNegative) ? -f : f;
   }
1028802
protected function parseShortForm($pos)
	{
		preg_match_all($this->shortRegexp, $this->text, $matches, PREG_OFFSET_CAPTURE, $pos);
		foreach ($matches[0] as list($match, $matchPos))
		{
			$matchLen = strlen($match);
			$startPos = $matchPos;
			$endLen   = (substr($match, -1) === $this->syntaxChar) ? 1 : 0;
			$endPos   = $matchPos + $matchLen - $endLen;

			$this->parser->addTagPair($this->tagName, $startPos, 1, $endPos, $endLen);
		}
	}
876255
public static function length($len, $str, $compare = null)
    {
        $actualLen = strlen($str);
        switch ($compare) {
            case 'lte':
            case '<=':
                return $actualLen <= $len;
            case 'gte':
            case '>=':
                return $actualLen >= $len;
            case 'lt':
            case '<':
                return $actualLen < $len;
            case 'gt':
            case '>':
                return $actualLen > $len;
            default:
                return $actualLen == $len;
        }
    }