<commit_before>goog.provide('treesaver.uri');

// URI parser, based on parseUri by <NAME> <<EMAIL>> (MIT License)
treesaver.uri._parserRegex = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
treesaver.uri._keys = ["source", "scheme", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"];

treesaver.uri.parse = function (str) {
    var i = treesaver.uri._keys.length,
        m = treesaver.uri._parserRegex.exec(str),
        result = {};

    while (i--) {
        result[treesaver.uri._keys[i]] = m[i] || null;
    }
    return result;
};

treesaver.uri.stringify = function (o) {
    var result = '';

    if (o['scheme']) {
        result += o['scheme'] + ':';
    }

    if (o['source'] && /^(?:[^:\/?#]+:)?\/\//.test(o['source'])) {
        result += '//';
    }

    if (o['authority']) {
        if (o['userInfo']) {
            result += o['user'] || '';
            if (o['userInfo'].indexOf(':') !== -1) {
                result += ':';
            }
            result += o['password'] || '';
            result += '@';
        }
        result += o['host'] || '';

        if (o['port'] !== null) {
            result += ':' + o['port'];
        }
    }

    if (o['relative']) {
        if (o['path']) {
            result += o['directory'] || '';
            result += o['file'] || '';
        }

        if (o['query']) {
            result += '?' + o['query'];
        }

        if (o['anchor']) {
            result += '#' + o['anchor'];
        }
    }
    return result;
};

treesaver.uri.isIndex = function (str) {
  var url = treesaver.uri.parse(str);

  if (url.file) {
    return (/^(index|default)\.(html?|php|asp|aspx)$/i.test(url.file) || (treesaver.ui.ArticleManager.index.get('DirectoryIndex', 'index.html') === url.file));
  } else {
    return false;
  }
};

treesaver.uri.stripHash = function (str) {
  var tmp = treesaver.uri.parse(str);
  tmp.anchor = null;
  return treesaver.uri.stringify(tmp);
};

treesaver.uri.stripFile = function (str) {
  var tmp = treesaver.uri.parse(str);
  tmp.file = null;
  return treesaver.uri.stringify(tmp);
};<commit_msg>Check if ArticleManager has an index before reading its settings.<commit_after>goog.provide('treesaver.uri');

// URI parser, based on parseUri by <NAME> <<EMAIL>> (MIT License)
treesaver.uri._parserRegex = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
treesaver.uri._keys = ["source", "scheme", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"];

treesaver.uri.parse = function (str) {
    var i = treesaver.uri._keys.length,
        m = treesaver.uri._parserRegex.exec(str),
        result = {};

    while (i--) {
        result[treesaver.uri._keys[i]] = m[i] || null;
    }
    return result;
};

treesaver.uri.stringify = function (o) {
    var result = '';

    if (o['scheme']) {
        result += o['scheme'] + ':';
    }

    if (o['source'] && /^(?:[^:\/?#]+:)?\/\//.test(o['source'])) {
        result += '//';
    }

    if (o['authority']) {
        if (o['userInfo']) {
            result += o['user'] || '';
            if (o['userInfo'].indexOf(':') !== -1) {
                result += ':';
            }
            result += o['password'] || '';
            result += '@';
        }
        result += o['host'] || '';

        if (o['port'] !== null) {
            result += ':' + o['port'];
        }
    }

    if (o['relative']) {
        if (o['path']) {
            result += o['directory'] || '';
            result += o['file'] || '';
        }

        if (o['query']) {
            result += '?' + o['query'];
        }

        if (o['anchor']) {
            result += '#' + o['anchor'];
        }
    }
    return result;
};

treesaver.uri.isIndex = function (str) {
  var url = treesaver.uri.parse(str);

  if (url.file) {
    return (/^(index|default)\.(html?|php|asp|aspx)$/i.test(url.file) || (treesaver.ui.ArticleManager.index && treesaver.ui.ArticleManager.index.get('DirectoryIndex', 'index.html') === url.file));
  } else {
    return false;
  }
};

treesaver.uri.stripHash = function (str) {
  var tmp = treesaver.uri.parse(str);
  tmp.anchor = null;
  return treesaver.uri.stringify(tmp);
};

treesaver.uri.stripFile = function (str) {
  var tmp = treesaver.uri.parse(str);
  tmp.file = null;
  return treesaver.uri.stringify(tmp);
};
{'fraction_non_alphanumeric': 0.26913849509269355, 'fraction_numerical': 0.0004362050163576881, 'mean_word_length': 2.3770250368188512, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6764017', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1562, 'n_words': 272}