Determines the longest static prefix possible for a route.
975202
private static function determineStaticPrefix(Route $route, array $tokens): string
    {
        if (!$tokens) {
            return '';
        }

        if ('text' !== $tokens[0][0]) {
            return ($route->hasDefault($tokens[0][3]) || '/' === $tokens[0][1]) ? '' : $tokens[0][1];
        }

        $prefix = $tokens[0][1];

        if (isset($tokens[1][1]) && '/' !== $tokens[1][1] && false === $route->hasDefault($tokens[1][3])) {
            $prefix .= $tokens[1][1];
        }

        return $prefix;
    }
653716
def root(options = {})
      if options.is_a?(Symbol)
        if source_route = @set.named_routes.routes[options]
          options = source_route.defaults.merge({ :conditions => source_route.conditions })
        end
      end
      named_route("root", '', options)
    end
81560
function longestCommonPathPrefix(stra, strb) {
  const minlen = min(stra.length, strb.length);
  let common = 0;
  let lastSep = -1;
  for (; common < minlen; ++common) {
    const chr = stra[common];
    if (chr !== strb[common]) {
      break;
    }
    if (chr === sep) {
      lastSep = common;
    }
  }
  if (common === minlen &&
      (stra.length === minlen ?
        strb.length === minlen || strb[minlen] === sep :
        stra[minlen] === sep)) {
    return minlen + 1;
  }
  return lastSep + 1;
}
440706
public long getIPv4PrefixCount(int prefixLength) {
		checkSubnet(this, prefixLength);
		if(isMultiple()) {
			int networkSegmentIndex = getNetworkSegmentIndex(prefixLength, IPv4Address.BYTES_PER_SEGMENT, IPv4Address.BITS_PER_SEGMENT);
			int hostSegmentIndex = getHostSegmentIndex(prefixLength, IPv4Address.BYTES_PER_SEGMENT, IPv4Address.BITS_PER_SEGMENT);
			boolean hasPrefixedSegment = (networkSegmentIndex == hostSegmentIndex);
			return getCount(i -> {
				if(hasPrefixedSegment && i == networkSegmentIndex) {
					return getSegment(i).getPrefixValueCount();
				}
				return getSegment(i).getValueCount();
			}, networkSegmentIndex + 1);
		}
		return 1;
	}
63434
def fast_relpath_optional(path, start):
  
  if len(start) == 0:
    # Empty prefix.
    return path

  # Determine where the matchable prefix ends.
  pref_end = len(start) - 1 if start[-1] == '/' else len(start)
  if pref_end > len(path):
    # The prefix is too long to match.
    return None
  elif path[:pref_end] == start[:pref_end] and (len(path) == pref_end or path[pref_end] == '/'):
    # The prefix matches, and the entries are either identical, or the suffix indicates that
    # the prefix is a directory.
    return path[pref_end+1:]
1000748
private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \stdClass $state, int $prefixLen = 0): string
    {
        $code = '';
        $prevRegex = null;
        $routes = $tree->getRoutes();

        foreach ($routes as $i => $route) {
            if ($route instanceof StaticPrefixCollection) {
                $prevRegex = null;
                $prefix = substr($route->getPrefix(), $prefixLen);
                $state->mark += \strlen($rx = "|{$prefix}(?");
                $code .= "\n                    ." . self::export($rx);
                $state->regex .= $rx;
                $code .= $this->indent($this->compileStaticPrefixCollection($route, $state, $prefixLen + \strlen($prefix)));
                $code .= "\n                    .')'";
                $state->regex .= ')';
                ++$state->markTail;

                continue;
            }

            [$name, $regex, $vars, $route] = $route;
            $compiledRoute = $route->compile();

            if ($compiledRoute->getRegex() === $prevRegex) {
                $state->switch = substr_replace($state->switch, $this->compileRoute($route, $name, false) . "\n", -19, 0);

                continue;
            }

            $state->mark += 3 + $state->markTail + \strlen($regex) - $prefixLen;
            $state->markTail = 2 + \strlen($state->mark);
            $rx = sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark);
            $code .= "\n                    ." . self::export($rx);
            $state->regex .= $rx;
            $vars = array_merge($state->hostVars, $vars);

            if (!$route->getCondition() && (!\is_array($next = $routes[1 + $i] ?? null) || $regex !== $next[1])) {
                $prevRegex = null;
                $defaults = $route->getDefaults();
                if (isset($defaults['_canonical_route'])) {
                    $name = $defaults['_canonical_route'];
                    unset($defaults['_canonical_route']);
                }
                $state->default .= sprintf(
                    "%s => array(%s, %s, %s, %s),\n",
                    $state->mark,
                    self::export(['_route' => $name] + $defaults),
                    self::export($vars),
                    self::export(array_flip($route->getMethods()) ?: null),
                    self::export(array_flip($route->getSchemes()) ?: null)
                );
            } else {
                $prevRegex = $compiledRoute->getRegex();
                $combine = '            $matches = array(';
                foreach ($vars as $j => $m) {
                    $combine .= sprintf('%s => $matches[%d] ?? null, ', self::export($m), 1 + $j);
                }
                $combine = $vars ? substr_replace($combine, ");\n\n", -2) : '';

                $state->switch .= <<<EOF
        case {$state->mark}:
{$combine}{$this->compileRoute($route, $name, false)}
            break;

EOF;
            }
        }

        return $code;
    }
1003747
function (route) {
        var staticPrefix = null;
        var hostVariables = [];
        var pathVariables = [];
        var variables = [];
        var tokens = [];
        var regex = null;
        var hostRegex = null;
        var hostTokens = [];
        var host;

        if ('' !== (host = route.domain())) {
            var result = compilePattern(route, host, true);

            hostVariables = result['variables'];
            variables = variables.concat(hostVariables);

            hostTokens = result['tokens'];
            hostRegex = result['regex'];
        }

        var path = route.getPath();

        result = compilePattern(route, path, false);

        staticPrefix = result['staticPrefix'];

        pathVariables = result['variables'];
        variables = variables.concat(pathVariables);

        tokens = result['tokens'];
        regex = result['regex'];

        return new CompiledRoute(
            staticPrefix,
            regex,
            tokens,
            pathVariables,
            hostRegex,
            hostTokens,
            hostVariables,
            _.uniq(variables)
        );
    }
373020
def longest_unique_prefix(query, targets, remove_self=True):
    
    query = op.basename(query)
    targets = [op.basename(x) for x in targets]
    prefix_lengths = [len(op.commonprefix([query, name])) for name in targets]
    if remove_self and len(query) in prefix_lengths:
        prefix_lengths.remove(len(query))
    longest_length = max(prefix_lengths)
    return query[:longest_length + 1]
1268336
def _mangle_prefix(res):
    
    # fugly cast from large numbers to string to deal with XML-RPC
    res['total_addresses'] = unicode(res['total_addresses'])
    res['used_addresses'] = unicode(res['used_addresses'])
    res['free_addresses'] = unicode(res['free_addresses'])

    # postgres has notion of infinite while datetime hasn't, if expires
    # is equal to the max datetime we assume it is infinity and instead
    # represent that as None
    if res['expires'].tzinfo is None:
        res['expires'] = pytz.utc.localize(res['expires'])
    if res['expires'] == pytz.utc.localize(datetime.datetime.max):
        res['expires'] = None

    return res
731858
public function prefixRoute($name)
    {
        $prefix = $this->config('route.name-prefix');

        return starts_with($name, $prefix) ? $name : $prefix . $name;
    }
1334100
def trim(self, prefixes):
        ""
        _prefixes, prefixes = set(map(lambda k:self._prepare_key(k), prefixes)), list()
        for t in lookahead(sorted(_prefixes)):
            if t[1] is not None:
                if t[0] == commonprefix(t):
                    continue
            prefixes.append(t[0])
        length = 0
        for prefix in prefixes:
            length += self._trim(prefix)
        return length
1279156
def is_prefix(pre_path, path):
    """"""
    pre_path = pre_path.strip('.')
    path = path.strip('.')
    return not pre_path or path.startswith(pre_path + '.')
1071736
def setup_versioned_routes(routes, version=None):
    """"""
    prefix = '/' + version if version else ""
    for r in routes:
        path, method = r
        route(prefix + path, method, routes[r])
180437
def with_prefix(self, root_path):
        """"""
        return Conflict(self.conflict_type, root_path + self.path, self.body)
573120
def get_prefix():
  

  name = os.environ.get('NCLUSTER_PREFIX', DEFAULT_PREFIX)
  if name != DEFAULT_PREFIX:
    validate_prefix(name)
  return name
529468
def find_best_match(path, prefixes):
    """"""
    path_parts = path.split('.')
    for p in prefixes:
        if len(p) <= len(path_parts) and p == path_parts[:len(p)]:
            return '.'.join(p), '.'.join(path_parts[len(p):])
    return '', path
555011
public static void get(@NotNull String path, @NotNull Handler handler) {
        staticInstance().get(prefixPath(path), handler);
    }