<commit_before><?php
$default = "en-gb";

header('Content-Type: text/plain');

function p($s) {
  print("$s\n");
}

function sanitise($lang) {
  $lang = strtolower($lang);

  $sane = "";
  for ($i = 0; $i < strlen($lang); $i++) {
    $c = $lang[$i];
    if ($c === ';') {
      break;
    }
    if ($c === '-') {
      $sane .= '-';
      continue;
    }
    if (ord($c) > ord('a') and ord($c) < ord('z')) {
      $sane .= $c;
      continue;
    }
  }
  return $sane;
}

/**
 * Given a string listing acceptable languages as defined in RFC2616, return an
 * array of sanitised versions of each language tag.
 * @author <NAME> <<EMAIL>>
 * @param string $langs
 */
function sanitise_langs($langs) {
  $langs = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  $langs = explode(',', $langs);
  $sanitised = array();
  foreach ($langs as $lang) {
    $lang = sanitise($lang);
    if (strlen($lang) > 0) {
      array_push($sanitised, $lang);
    }
  }
  return $sanitised;
}

function redirect($url, $statusCode = 303)
{
  $url = trim($url, "/");
  header('Location: ' . $url, true, $statusCode);
  exit();
}


if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  $langs = sanitise_langs($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  $request = $_SERVER[REQUEST_URI];
  foreach ($langs as $lang) {
    if (is_dir($lang)) {
      redirect($lang . '/' . $request);
    }
  }
  redirect($default . '/' . $request);
}
?><commit_msg>Format code to meet PEAR guidelines.<commit_after><?php
$default = "en-gb";

header('Content-Type: text/plain');

function p($s)
{
    print("$s\n");
}

function sanitise($lang)
{
    $lang = strtolower($lang);

    $sane = "";
    for ($i = 0; $i < strlen($lang); $i++) {
        $c = $lang[$i];
        if ($c === ';') {
            break;
        }
        if ($c === '-') {
            $sane .= '-';
            continue;
        }
        if (ord($c) > ord('a') and ord($c) < ord('z')) {
            $sane .= $c;
            continue;
        }
    }
    return $sane;
}

/**
 * Given a string listing acceptable languages as defined in RFC2616, return an
 * array of sanitised versions of each language tag.
 * @author <NAME> <<EMAIL>>
 * @param string $langs
 */
function sanitise_langs($langs)
{
    $langs     = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    $langs     = explode(',', $langs);
    $sanitised = array();
    foreach ($langs as $lang) {
        $lang = sanitise($lang);
        if (strlen($lang) > 0) {
            array_push($sanitised, $lang);
        }
    }
    return $sanitised;
}

function redirect($url, $statusCode = 303)
{
    $url = trim($url, "/");
    header('Location: ' . $url, true, $statusCode);
    exit();
}


if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    $langs   = sanitise_langs($_SERVER['HTTP_ACCEPT_LANGUAGE']);
    $request = $_SERVER[REQUEST_URI];
    foreach ($langs as $lang) {
        if (is_dir($lang)) {
            redirect($lang . '/' . $request);
        }
    }
    redirect($default . '/' . $request);
}
?>
{'fraction_non_alphanumeric': 0.20229652144545762, 'fraction_numerical': 0.0060790273556231, 'mean_word_length': 2.5643802647412755, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6901319', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1064, 'n_words': 233}