<commit_before>/**
 * @namespace hs.map
 * @memberOf hs
 */
define(['angular', 'app'], function(angular, app) {
    angular.module('hs.utils', ['hs'])

    /**
     * @ngdoc service
     * @name hs.utils.service
     * @memberOf hs.utils
     * @param {object} config - Application configuration
     * @description Service for containing various utility functions
     */
    .service('hs.utils.service', ['config', function(config) {
        var me = this;

        /**
        * @function proxify
        * @memberof hs.utils.service
        * @params {String} url Url to proxify
        * @params {Boolean} toEncoding Optional parameter if UTF-8 encoding shouldn´t be used for non-image Urls.         
        * @returns {String} Encoded Url with path to script 
        * Add path to proxy cgi script (hsproxy.cgi) into Url and encode rest of Url if valid http Url is send and proxy use is allowed.
        */
        this.proxify = function(url, toEncoding) {
            toEncoding = angular.isUndefined(toEncoding) ? true : toEncoding;
            var outUrl = url;
            if (url.substring(0, 4) == 'http' && url.indexOf(window.location.origin) == -1) {
                if (typeof use_proxy === 'undefined' || use_proxy === true) {

                    outUrl = "/cgi-bin/hsproxy.cgi?";
                    if (toEncoding && url.indexOf('FORMAT=image') == -1) outUrl += "toEncoding=utf-8&";
                    outUrl = outUrl + "url=" + encodeURIComponent(url);
                }
            }
            return outUrl;
        }

        /**
        * @function parseXexString
        * @memberof hs.utils.service
        * @params {String} hex 
        * @returns {Array} 
        * DEPRECATED?
        */<commit_msg>Check also port when determining if url needs proxification<commit_after>/**
 * @namespace hs.map
 * @memberOf hs
 */
define(['angular', 'app'], function(angular, app) {
    angular.module('hs.utils', ['hs'])

    /**
     * @ngdoc service
     * @name hs.utils.service
     * @memberOf hs.utils
     * @param {object} config - Application configuration
     * @description Service for containing various utility functions
     */
    .service('hs.utils.service', ['config', function(config) {
        var me = this;

        /**
        * @function proxify
        * @memberof hs.utils.service
        * @params {String} url Url to proxify
        * @params {Boolean} toEncoding Optional parameter if UTF-8 encoding shouldn´t be used for non-image Urls.         
        * @returns {String} Encoded Url with path to script 
        * Add path to proxy cgi script (hsproxy.cgi) into Url and encode rest of Url if valid http Url is send and proxy use is allowed.
        */
        this.proxify = function(url, toEncoding) {
            toEncoding = angular.isUndefined(toEncoding) ? true : toEncoding;
            var outUrl = url;
            if ((url.substring(0, 4) == 'http' && url.indexOf(window.location.origin) == -1) || getPortFromUrl(url) != window.location.port) {
                if (typeof use_proxy === 'undefined' || use_proxy === true) {

                    outUrl = "/cgi-bin/hsproxy.cgi?";
                    if (toEncoding && url.indexOf('FORMAT=image') == -1) outUrl += "toEncoding=utf-8&";
                    outUrl = outUrl + "url=" + encodeURIComponent(url);
                }
            }
            return outUrl;
        }

         /**
        * @function getPortFromUrl
        * @memberof hs.utils.service
        * @params {String} url Url for which to determine port number 
        * @returns {String} 
        */
        function getPortFromUrl(url){
            var link = document.createElement('a');
            link.setAttribute('href', url);
            return link.port;
        }

        /**
        * @function parseXexString
        * @memberof hs.utils.service
        * @params {String} hex 
        * @returns {Array} 
        * DEPRECATED?
        */
{'fraction_non_alphanumeric': 0.12372967479674797, 'fraction_numerical': 0.003048780487804878, 'mean_word_length': 1.949063670411985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4290073', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1085, 'n_words': 311}