Converts a given package name to a valid/parseable package name (without reserved words)
338888
public static String toValidPackageName(String pkg)
   {
      if (pkg == null)
      {
         throw new IllegalArgumentException("Package should not be null");
      }
      // Sanitizing package name
      StringBuilder sb = new StringBuilder(pkg.length());
      for (int i = 0; i < pkg.length(); i++)
      {
         char c = pkg.charAt(i);
         // remove dots from the beginning and the end of the package
         if (c == '.' && (i == 0 || i == pkg.length() - 1))
         {
            continue;
         }
         if (c == '.' || Character.isJavaIdentifierPart(c))
         {
            sb.append(c);
         }
      }
      String packageName = sb.toString();
      StringBuilder result = new StringBuilder();
      String[] tokens = packageName.split("[.]");
      for (String token : tokens)
      {
         if (result.length() > 0 && result.charAt(result.length() - 1) != '.')
         {
            result.append('.');
         }
         if (JLSValidator.isReservedWord(token))
         {
            result.append(token).append('_');
         }
         else if (isNumber(token))
         {
            // skip tokens as numbers and remove the appended '.' if exist
            if (result.length() > 0)
               result.deleteCharAt(result.length() - 1);
         }
         else
         {
            result.append(token);
         }
      }
      return result.toString();
   }
1369992
private function fixPackageName($name)
    {
        $name = str_replace(
            ['à', 'á', 'â', 'ä', 'æ', 'ã', 'å', 'ā', 'é', 'è', 'ê', 'ë', 'ę', 'ė', 'ē', 'ī', 'į', 'í', 'ì', 'ï', 'î', 'ō', 'ø', 'œ', 'õ', 'ó', 'ò', 'ö', 'ô', 'ū', 'ú', 'ù', 'ü', 'û', 'ç', 'ć', 'č', 'ł', 'ñ', 'ń', 'ß', 'ś', 'š', 'ŵ', 'ŷ', 'ÿ', 'ź', 'ž', 'ż'],
            ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'u', 'c', 'c', 'c', 'l', 'n', 'n', 's', 's', 's', 'w', 'y', 'y', 'z', 'z', 'z'],
            $name
        );
        $name = preg_replace('#[^A-Za-z0-9_./-]+#', '', $name);

        return strtolower($name);
    }
123273
private String parseOuterClassName() {
		StringBuilder sb = new StringBuilder();
		sb.append(lexer.nextToken(TokenType.JAVA_ID).text);
		Token token = lexer.peekToken(0);
		boolean isFullyQualifiedName = false;
		while (token.tokenType == TokenType.PACKAGE_SEPARATOR) {
			isFullyQualifiedName = true;
			token = lexer.nextToken();
			sb.append('.');
			token = lexer.nextToken(TokenType.JAVA_ID);
			sb.append(token.text);
			token = lexer.peekToken(0);
		}
		if (!isFullyQualifiedName) {
			return getFullyQualifiedName(sb.toString());
		} else {
			return sb.toString();
		}
	}
175287
def resolve_name(name, package):
    """"""
    if not name.startswith('.'):
        return name
    elif not package:
        raise ValueError('{!r} is not a relative name '
                         '(no leading dot)'.format(name))
    level = 0
    for character in name:
        if character != '.':
            break
        level += 1
    return _resolve_name(name[level:], package, level)
944382
def parse_package_name(self):  # type: () -> Optional[str]
        
        if not self.setup_source:
            return None
        for row in self.setup_source.split("\n"):
            simplified_row = row.replace(" ", "").replace("'", '"').strip(" \t\n")
            if "name=" in simplified_row:
                if '"' in simplified_row:
                    return simplified_row.split('"')[1]

        name = self.execute_setup_name()
        if name:
            return name

        return ""
1359763
def convert_requirement(req):
    
    pkg_name = convert_name(req.project_name)
    if not req.specs:
        return [pkg_name]

    req_strs = []
    for spec in req.specs:
        op, ver = spec
        ver = convert_version(ver)
        if op == "<":
            r = "%s-0+<%s" % (pkg_name, ver)
            req_strs.append(r)
        elif op == "<=":
            r = "%s-0+<%s|%s" % (pkg_name, ver, ver)
            req_strs.append(r)
        elif op == "==":
            r = "%s-%s" % (pkg_name, ver)
            req_strs.append(r)
        elif op == ">=":
            r = "%s-%s+" % (pkg_name, ver)
            req_strs.append(r)
        elif op == ">":
            r1 = "%s-%s+" % (pkg_name, ver)
            r2 = "!%s-%s" % (pkg_name, ver)
            req_strs.append(r1)
            req_strs.append(r2)
        elif op == "!=":
            r = "!%s-%s" % (pkg_name, ver)
            req_strs.append(r)
        else:
            print >> sys.stderr, \
                "Warning: Can't understand op '%s', just depending on unversioned package..." % op
            req_strs.append(pkg_name)

    return req_strs
644529
def source_debianize_name(name):
    ""
    name = name.replace('_','-')
    name = name.replace('.','-')
    name = name.lower()
    return name
1172880
function normalizePackageName (name) {
  if (name.startsWith('@')) {
    name = name.slice(1)
  }
  return name.replace(/(^|-|\/)(.)/g, (match, s1, s2) => {
    return s2.toUpperCase()
  })
}
468646
def _safe_name(file_name, sep):
    """"""
    file_name = stringify(file_name)
    if file_name is None:
        return
    file_name = ascii_text(file_name)
    file_name = category_replace(file_name, UNICODE_CATEGORIES)
    file_name = collapse_spaces(file_name)
    if file_name is None or not len(file_name):
        return
    return file_name.replace(WS, sep)
114077
function fixDependencyKey(key, packageName){
		// support `requires: /SomethingInThisPackage`
		if (key.indexOf('/') == 0) key = packageName + key;
		// support `requires: SomethingInThisPackage`
		if (key.indexOf('/') == -1) key = packageName + '/' + key;
		return key;
	}
196304
def get_name_variants(pkg):
    # type: (STRING_TYPE) -> Set[STRING_TYPE]
    

    if not isinstance(pkg, six.string_types):
        raise TypeError("must provide a string to derive package names")
    from pkg_resources import safe_name
    from packaging.utils import canonicalize_name

    pkg = pkg.lower()
    names = {safe_name(pkg), canonicalize_name(pkg), pkg.replace("-", "_")}
    return names
669949
def convert_package_names(package_names):
    

    results = []
    errors = []

    for name in (
            package_names.split()
            if hasattr(package_names, 'split') else package_names):
        try:
            Requirement.parse(name)
        except ValueError:
            errors.append(name)
        else:
            results.append(name)

    return results, errors
709812
def package_name(package):
    # type: (str) -> str
    
    if not package:
        return ""

    lastdot = package.rfind(".")
    if lastdot == -1:
        return package

    return package[:lastdot]
1289188
public static ValidationResult validatePackageName(String packageName)
   {
      if (Strings.isNullOrEmpty(packageName))
         return new ValidationResult(ERROR, Messages.notNullOrEmpty(PACKAGE_NAME));
      int indexOfDot = packageName.indexOf(".");
      if (indexOfDot == -1)
      {
         return validateIdentifier(packageName, PACKAGE_NAME);
      }
      else if (indexOfDot == 0)
      {
         return new ValidationResult(ERROR, "The package name must not start with a '.'");
      }
      else if (packageName.charAt(packageName.length() - 1) == '.')
      {
         return new ValidationResult(ERROR, "The package name must not end with a '.'");
      }
      else
      {
         String[] names = packageName.split("[.]");
         for (String name : names)
         {
            if (Strings.isNullOrEmpty(name))
            {
               return new ValidationResult(ERROR, Messages.isInvalidPackageName(packageName));
            }
            ValidationResult result = validateIdentifier(name, PACKAGE_NAME);
            if (!result.getType().equals(ResultType.INFO))
            {
               return result;
            }
         }
      }
      return new ValidationResult(INFO);
   }
523116
def case_sensitive_name(self, package_name):
        
        if len(self.environment[package_name]):
            return self.environment[package_name][0].project_name
180280
public String getFullyQualifiedName() {
        StringBuilder sb = new StringBuilder();
        if (packageName != null && !packageName.isEmpty()) {
            sb.append(getPackageName()).append(".");
        }

        if (outerType != null) {
            sb.append(outerType.getName()).append(".");
        }
        sb.append(getName());

        return sb.toString();
    }
526760
function encodePackageName(packageName) {
  // Thanks https://github.com/unpkg/npm-http-server/blob/master/modules/RegistryUtils.js
  // for scoped modules help
  let encodedPackageName;
  if (packageName[0] === "@") {
    // For the registry URL, the @ doesn't get URL encoded for some reason
    encodedPackageName = `@${encodeURIComponent(packageName.substring(1))}`;
  } else {
    encodedPackageName = encodeURIComponent(packageName);
  }
  return encodedPackageName;
}