Paths are stored without trailing slash so we need to get rid off it if
        needed. Also mercurial keeps filenodes as str so we need to decode
        from unicode to str
431244
def _fix_path(self, path):
        
        if path.endswith('/'):
            path = path.rstrip('/')

        return safe_str(path)
959288
function(filepath) {
    var pieces = _.last(filepath.split('/')).split('.');
    var name   = _(pieces).without(_.last(pieces)).join('.'); // strips file extension
    if (name.charAt(0) === '_') {
      name = name.substr(1, name.length); // strips leading _ character
    }
    return name;
  }
765206
function normalizePath(path, keys, params) {
        for (var name in params) {
            var param = params[name];
            if (typeof param == "string" || param instanceof RegExp)
                params[name] = {type: param};
        }

        path = path
            .concat("/?")
            .replace(/\/:([\w.\-_]+)(\*?)/g, function(match, key, wildcard) {
                keys.push(key);
                if (!params[key]) {
                    params[key] = {};
                }
                // url params default to type string and optional=false
                var param = params[key];
                param.type = param.type || "string";
                param.optional = false;

                if (!param.source) param.source = "url";

                if (param.source !== "url")
                    throw new Error(
                        "Url parameters must have 'url' as source but found '" +
                            param.source +
                            "'"
                    );

                if (wildcard) return "(/*)";
                else return "/([^\\/]+)";
            })
            .replace(/([/.])/g, "\\$1")
            .replace(/\*/g, "(.*)");

        return new RegExp("^" + path + "$");
    }
1104521
function toPathIfFileURL(fileURLOrPath) {
  if (!(fileURLOrPath &&
    fileURLOrPath.protocol &&
    fileURLOrPath.pathname)) {
    return fileURLOrPath;
  }

  if (fileURLOrPath.protocol !== 'file:') {
    throw new Errors.EINVAL('only file: URLs are supported for paths', fileURLOrPath);
  }

  const pathname = fileURLOrPath.pathname;
  for (let n = 0; n < pathname.length; n++) {
    if (pathname[n] === '%') {
      const third = pathname.codePointAt(n + 2) | 0x20;
      if (pathname[n + 1] === '2' && third === 102) {
        throw new Errors.EINVAL('file: URLs must not include encoded / characters', fileURLOrPath);
      }
    }
  }

  return decodeURIComponent(pathname);
}
1216839
function getPathnameFromUrl (u) {
	const pathname = url.parse(u).pathname;
	try {
		return decodeURI(pathname);
	} catch (e) {
		return pathname;
	}
}
756228
function pathStrToPathArr(path) {
	path = path.substr(1).split('/').map(part => {
		// De-tokenize '/' characters in path name
		return part.replace(/~1/g, '/');
	});

	// For some reason, path arrays whose only item is an empty string cause errors.
	// In this case, we replace the path with an empty array, which seems to be fine.
	if (path.length === 1 && path[0] === '') {
		path = [];
	}

	return path;
}
178628
def _normalize_dir(string_):
    '''
    
    '''
    return os.path.normpath(salt.utils.stringutils.to_unicode(string_))
1076021
function serialize(path){
	return path.reduce(function(str, seg){
		return str + seg[0] + seg.slice(1).join(',')
	}, '')
}
827435
function path2FolderName(filePath, keepTailSlash){
		var pathSegs = filePath.split("/");
		pathSegs.splice(pathSegs.length -1, 1);
		return keepTailSlash ? pathSegs.join("/") + "/" : pathSegs.join("/");
	}
914552
def pathencode (path):
    """"""
    if isinstance(path, unicode) and not os.path.supports_unicode_filenames:
        path = path.encode(FSCODING, "replace")
    return path
695720
function normalizePath(fsPath) {
  fsPath = path.normalize(fsPath);

  if (process.platform === 'win32') {
    fsPath = fsPath.replace(backwardSlashRegExp, '/');
  }

  return fsPath;
}
314454
def path_with_slashes(path)
      path = '/' + path unless path.start_with?('/')
      path << '/' unless path.end_with?('/')
      path
    end
1332556
function convertPath(path) {
    function indexOf(ch, startPosition) {
      var pos = path.indexOf(ch, startPosition);
      if (pos === -1)
        return pos;

      var slashNumber = 0;
      while (path.charAt(pos - 1 - slashNumber) === '\\')
        ++slashNumber;

      if (slashNumber % 2 === 0)
        return pos;

      //Skip escaped symbols
      return indexOf(ch, pos + 1);
    }

    var match;

    //RegEx should be inside loop to reset iteration
    while (match = /{([^}:]+):/g.exec(path)) {
      var deleteBegin = match.index + match[0].length - 1;
      var deleteEnd = deleteBegin;

      var unmatched = 1;
      while (unmatched !== 0) {

        var open = indexOf('{', deleteEnd + 1);
        var close = indexOf('}', deleteEnd + 1);

        if (close === -1)
          throw Error('Unmatched curly brackets in path: ' + path);

        if (open !==  -1 && open < close) {
          ++unmatched;
          deleteEnd = open;
        }
        else {
          --unmatched;
          deleteEnd = close;
        }
      }

      //For future use: regex itself is
      //path.substring(deleteBegin + 1, deleteEnd)

      path = path.slice(0, deleteBegin) + path.slice(deleteEnd);
    }

    return path;
  }
473046
function decodeLink(value) {                                // '</1/2>;pmin=10;pmax=60,</1/2/1>,</1/2/2>'
    var allowedAttrs = [ 'pmin', 'pmax', 'gt', 'lt', 'st' ],
        valueArray = value.split(','),                      // ['</1/2>;pmin=10;pmax=60', '</1/2/1>', '</1/2/2>']
        resrcArray = valueArray.slice(1),                   // ['</1/2/1>', '</1/2/2>']
        attrsArray = valueArray[0].split(';').slice(1),     // ['pmin=10', 'pmax=60']
        path = valueArray[0].split(';')[0].slice(1, -1),
        data = {
            path: path
        },
        rid;    

    if (!_.isEmpty(attrsArray)) {
        data.attrs = {};
        _.forEach(attrsArray, function (val) {
            var attr = val.split('=');

            if (_.includes(allowedAttrs, attr[0]))
                data.attrs[attr[0]] = Number(attr[1]);
        });
    }

    if (!_.isEmpty(resrcArray)) {
        data.resrcList = [];
        _.forEach(resrcArray, function (resrc, idx) {     
            data.resrcList.push(resrc.slice(1, -1));  
        });
    }

    return data;     // { path: '/1/2', attrs: { pmin: 10, pmax: 60 }, resrcList: ['/1/2/1', '/1/2/2'] }
}
1045351
private static String encodePath(final String path) {
        // Accept ':' if it is part of a scheme prefix
        int validColonPrefixLen = 0;
        for (final String scheme : SCHEME_PREFIXES) {
            if (path.startsWith(scheme)) {
                validColonPrefixLen = scheme.length();
                break;
            }
        }
        final byte[] pathBytes = path.getBytes(StandardCharsets.UTF_8);
        final StringBuilder encodedPath = new StringBuilder(pathBytes.length * 3);
        for (int i = 0; i < pathBytes.length; i++) {
            final byte pathByte = pathBytes[i];
            final int b = pathByte & 0xff;
            if (safe[b] || (b == ':' && i < validColonPrefixLen)) {
                encodedPath.append((char) b);
            } else {
                encodedPath.append('%');
                encodedPath.append(HEXADECIMAL[(b & 0xf0) >> 4]);
                encodedPath.append(HEXADECIMAL[b & 0x0f]);
            }
        }
        return encodedPath.toString();
    }
362930
function (/*String*/path, /*String?*/encoding) {
            if (encoding === 'utf-8') {
                encoding = 'utf8';
            }
            if (!encoding) {
                encoding = 'utf8';
            }

            var text = fs.readFileSync(path, encoding);

            //Hmm, would not expect to get A BOM, but it seems to happen,
            //remove it just in case.
            if (text.indexOf('\uFEFF') === 0) {
                text = text.substring(1, text.length);
            }

            return text;
        }
830032
function convertToNativePath(path) {
        path = unescape(path);
        if (path.indexOf(":") !== -1 && path[0] === "/") {
            return path.substr(1);
        }

        return path;
    }