Calculate maximum distance for specified word length

@param  integer $prefixLength
@param  integer $termLength
@param  integer $length
@return integer
350473
private function _calculateMaxDistance($prefixLength, $termLength, $length)
    {
        $this->_maxDistances[$length] = (int) ((1 - $this->_minimumSimilarity)*(min($termLength, $length) + $prefixLength));
        return $this->_maxDistances[$length];
    }
434033
public function getStringValue($key, $maxlength = null)
    {
        $value = $this->get($key);
        if ($value === null) {
            return null;
        }
        return ($maxlength === null) ? $value : substr($value, 0, $maxlength);
    }
473632
public static function randomNumber($prefix = '4', $length = 8)
    {
        if (function_exists('random_int')) {
            $length = $length - strlen($prefix);
            $result = $prefix;
            while ($length > 0) {
                $result .= static::randomNumberUsingRandomInt('', $length > 9 ? 9 : $length);
                $length -= 9;
            }
            return $result;
        }
        $key = "";
        $pattern = '1234567890';
        for ($i = 0; $i < $length - strlen($prefix); $i++)
        {
            $key .= $pattern[mt_rand(0, 9)];
        }
        return $prefix . $key;
    }
701554
public void setMaxLength(int length) {
		maxCharacter = length;
		if (value.length() > maxCharacter) {
			value = value.substring(0, maxCharacter);
		}
	}
483675
public function withMaxLength(int $length): self
    {
        $obj = clone $this;
        $obj->_maxLength = $length;
        return $obj;
    }
785119
public function randHashStr($length = 16, $prefix = '')
    {
        $size = $length - strlen($prefix);
        $offset = intval(32 - $size) / 2;
        return $prefix . substr(md5(microtime(true) . mt_rand(1000, 9999)), $offset, $size);
    }
1210909
public function hasMinLength($minLength)
    {
        $this->isString();

        $this->doCheck(function ($value) use ($minLength) {
            $this->throwExceptionIfFalse(
                mb_strlen($value) >= $minLength,
                'Failed assertion that %s has at least %s characters', $value, $minLength
            );
        });

        return $this;
    }
1070671
public static function truncate($str, $maxlength=20)
    {

        if(strlen($str) > $maxlength){
            $str = substr($str, 0, $maxlength-3).'...';
        }

        return $str;
    }
746043
public void setMaxExcerptLength(String maxExcerptLength) {

        try {
            setMaxExcerptLength(Integer.parseInt(maxExcerptLength));
        } catch (Exception e) {
            LOG.error(
                Messages.get().getBundle().key(
                    Messages.LOG_PARSE_EXCERPT_LENGTH_FAILED_2,
                    maxExcerptLength,
                    new Integer(DEFAULT_EXCERPT_LENGTH)),
                e);
            setMaxExcerptLength(DEFAULT_EXCERPT_LENGTH);
        }
    }
938120
def length_prefix(length, offset):
    
    if length < 56:
        return ALL_BYTES[offset + length]
    elif length < LONG_LENGTH:
        length_string = int_to_big_endian(length)
        return ALL_BYTES[offset + 56 - 1 + len(length_string)] + length_string
    else:
        raise ValueError('Length greater than 256**8')
965534
public function length($length = null)
    {
        if (!is_null($length)) {
            $this->length = (int) $length;
        }

        return $this->length;
    }
221820
private static int maxLength(List<String> coll) {
		int max = 0;
		for (String e : coll) {
			int length = e.length();
			if (length > max) {
				max = length;
			}
		}
		return max;
	}
1090245
def get_matching_prefix(self, namespace, stream):
    
    validate_stream(stream)
    default_prefix = ''
    longest_prefix = default_prefix
    for prefix in self.prefix_confs[namespace]:
      if prefix == default_prefix:
        continue
      if not stream.startswith(prefix):
        continue
      if len(prefix) <= len(longest_prefix):
        continue
      longest_prefix = prefix
    return longest_prefix
879867
public function calcN1N3($length)
        {
            $demerit = 0;

            for($i=0; $i<$length; $i++) {
                
                if($this->runLength[$i] >= 5) {
                    $demerit += (N1 + ($this->runLength[$i] - 5));
                }
                if($i & 1) {
                    if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
                        $fact = (int)($this->runLength[$i] / 3);
                        if(($this->runLength[$i-2] == $fact) &&
                           ($this->runLength[$i-1] == $fact) &&
                           ($this->runLength[$i+1] == $fact) &&
                           ($this->runLength[$i+2] == $fact)) {
                            if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
                                $demerit += N3;
                            } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
                                $demerit += N3;
                            }
                        }
                    }
                }
            }
            return $demerit;
        }
1050849
public static function rangeLength($value, int $minLength, int $maxLength, string $encoding = 'UTF-8'): bool
    {
        if (!static::isStringCastable($value)) {
            return false;
        }

        $strlen = (int) mb_strlen((string) $value, $encoding);

        if ($strlen < $minLength) {
            return false;
        }
        if ($strlen > $maxLength) {
            return false;
        }

        return true;
    }
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;
    }
1253463
public function setMaxLength(string $maxLength)
    {
        $this->getTag()->setAttribute('maxlength', $maxLength);
        $this->removeValidators(StringValidator::class);

        if ($maxLength !== '') {
            $validator = new StringValidator(0, (int) $maxLength);
            $this->addValidator($validator);
        }

        return $this;
    }