Strip whitespace characters from the beginning and the end of the url
    and add a default scheme.
777409
def fix_url(url):
    
    if url is None:
        return None

    url = url.strip()

    if url and not urlparse(url).scheme:
        url = "http://" + url

    return url
35690
private static String replaceChars(String str)
  {
    StringBuffer buf = new StringBuffer(str);
    int length = buf.length();
    for (int i = 0; i < length; i++)
    {
      char currentChar = buf.charAt(i);
      // Replace space with "%20"
      if (currentChar == ' ')
      {
        buf.setCharAt(i, '%');
        buf.insert(i+1, "20");
        length = length + 2;
        i = i + 2;
      }
      // Replace backslash with forward slash
      else if (currentChar == '\\')
      {
        buf.setCharAt(i, '/');
      }
    }

    return buf.toString();
  }
183080
public static String stripURLScheme(String url) {
		String lcUrl = url.toLowerCase();
		for(String scheme : ALL_SCHEMES) {
			if(lcUrl.startsWith(scheme)) {
				return url.substring(scheme.length());
			}
		}
		return url;
	}
845782
def strip_block_whitespace(string_list):
    """"""
    min_ws = min([(len(x) - len(x.lstrip())) for x in string_list if x != '\n'])
    return [x[min_ws:] if x != '\n' else x for x in string_list]
684213
def url_fix_common_typos (url):
    """"""
    if url.startswith("http//"):
        url = "http://" + url[6:]
    elif url.startswith("https//"):
        url = "https://" + url[7:]
    return url
415542
function strip(start, end) {
        const before = template.slice(0, start)
        const target = template.slice(start, end)
        const after = template.slice(end)
        template = before + target.replace(/\S/gu, " ") + after
        stripedRanges.push([start, end])
    }
796430
def fix_whitespace(tokens, start, result):
    """"""
    for e in result:
        for child in e.iter():
            child.text = child.text.replace(' , ', ', ')
            for hyphen in HYPHENS:
                child.text = child.text.replace(' %s ' % hyphen, '%s' % hyphen)
            child.text = re.sub(r'- (.) -', r'-\1-', child.text)
    return result
938227
public function normalize() {
		// remove whitespace from the beginning
		$this->str = ltrim($this->str);

		// ensure that there is exactly one forward slash at the beginning
		$this->str = '/'.ltrim($this->str, '/');

		// remove whitespace from the end
		$this->str = rtrim($this->str);


		return $this;
	}
480500
protected static URL normalizeToEndWithSlash(URL url) {
        if(url.getPath().endsWith("/"))
            return url;

        // normalize
        String q = url.getQuery();
        q = q!=null?('?'+q):"";
        try {
            return new URL(url,url.getPath()+'/'+q);
        } catch (MalformedURLException e) {
            // impossible
            throw new Error(e);
        }
    }
490896
def remove_unnecessary_whitespace(css):
    """"""

    def pseudoclasscolon(css):

        """
        Prevents 'p :link' from becoming 'p:link'.

        Translates 'p :link' into 'p ___PSEUDOCLASSCOLON___link'; this is
        translated back again later.
        """

        regex = re.compile(r"(^|\})(([^\{\:])+\:)+([^\{]*\{)")
        match = regex.search(css)
        while match:
            css = ''.join([
                css[:match.start()],
                match.group().replace(":", "___PSEUDOCLASSCOLON___"),
                css[match.end():]])
            match = regex.search(css)
        return css

    css = pseudoclasscolon(css)
    # Remove spaces from before things.
    css = re.sub(r"\s+([!{};:>+\(\)\],])", r"\1", css)

    # If there is a `@charset`, then only allow one, and move to the beginning.
    css = re.sub(r"^(.*)(@charset \"[^\"]*\";)", r"\2\1", css)
    css = re.sub(r"^(\s*@charset [^;]+;\s*)+", r"\1", css)

    # Put the space back in for a few cases, such as `@media screen` and
    # `(-webkit-min-device-pixel-ratio:0)`.
    css = re.sub(r"\band\(", "and (", css)

    # Put the colons back.
    css = css.replace('___PSEUDOCLASSCOLON___', ':')

    # Remove spaces from after things.
    css = re.sub(r"([!{}:;>+\(\[,])\s+", r"\1", css)

    return css
841687
def clean_url(url):
        """"""
        if not url.startswith(('http://', 'https://')):
            url = f'http://{url}'

        if not URL_RE.match(url):
            raise BadURLException(f'{url} is not valid')

        return url
267516
function formatParamUrl (url) {
  var start = url.indexOf('/:')
  if (start === -1) return url

  var end = url.indexOf('/', ++start)

  if (end === -1) {
    return url.slice(0, start) + '{' + url.slice(++start) + '}'
  } else {
    return formatParamUrl(url.slice(0, start) + '{' + url.slice(++start, end) + '}' + url.slice(end))
  }
}
623756
function stripTrailingSlash(url) {
        var arr = url.split('/');
        if (arr[arr.length - 1] === '') {
            arr.pop();
        }
        return arr.join('/');
    }
882935
def endswith_strip(s, endswith='.txt', ignorecase=True):
    
    if ignorecase:
        if s.lower().endswith(endswith.lower()):
            return s[:-len(endswith)]
    else:
        if s.endswith(endswith):
            return s[:-len(endswith)]
    return s
1167772
def replace_whitespace(text, SAFE_SPACE='|<^>|', insert=True):
    
    if insert:
        # replace whitespace with safe space chr
        args = (' ', SAFE_SPACE)
    else:
        # replace safe space chr with whitespace
        args = (SAFE_SPACE, ' ')

    return '\n'.join(line.strip().replace(*args)
                     for line in str.splitlines(text))
172958
private String urlPrefix(URL url) {
        StringBuilder result = new StringBuilder();
        result.append(url.getProtocol());
        String[] splits = StringUtils.split(url.getHost(), '.');
        if (splits.length > 0) {
            for (String split : splits) {
                result.append(split);
            }
        }
        if (url.getPort() > -1) {
            result.append(Integer.toString(url.getPort()));
        }
        return result.toString();
    }
853506
function replace(match, start, end, snippet) {
        var unroll = '';
        // Try to treat as define
        if (isNaN(start)) {
            if (start in defines) {
                start = defines[start];
            }
            else {
                start = lightNumberDefines[start];
            }
        }
        if (isNaN(end)) {
            if (end in defines) {
                end = defines[end];
            }
            else {
                end = lightNumberDefines[end];
            }
        }
        // TODO Error checking

        for (var idx = parseInt(start); idx < parseInt(end); idx++) {
            // PENDING Add scope?
            unroll += '{'
                + snippet
                    .replace(/float\s*\(\s*_idx_\s*\)/g, idx.toFixed(1))
                    .replace(/_idx_/g, idx)
            + '}';
        }

        return unroll;
    }