mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Clang importer] After stripping a prefix, lowercase initialisms as well.
This commit is contained in:
@@ -752,9 +752,8 @@ static bool isPluralSuffix(StringRef word) {
|
||||
return word == "s" || word == "es" || word == "ies";
|
||||
}
|
||||
|
||||
/// A form of toLowercaseWord that also lowercases acronyms.
|
||||
static StringRef toLowercaseWordAndAcronym(StringRef string,
|
||||
StringScratchSpace &scratch) {
|
||||
StringRef camel_case::toLowercaseInitialisms(StringRef string,
|
||||
StringScratchSpace &scratch) {
|
||||
if (string.empty())
|
||||
return string;
|
||||
|
||||
@@ -765,7 +764,8 @@ static StringRef toLowercaseWordAndAcronym(StringRef string,
|
||||
// Lowercase until we hit the an uppercase letter followed by a
|
||||
// non-uppercase letter.
|
||||
llvm::SmallString<32> scratchStr;
|
||||
for (unsigned i = 0, n = string.size(); i != n; ++i) {
|
||||
scratchStr.push_back(clang::toLowercase(string[0]));
|
||||
for (unsigned i = 1, n = string.size(); i != n; ++i) {
|
||||
// If the next character is not uppercase, stop.
|
||||
if (i < n - 1 && !clang::isUppercase(string[i+1])) {
|
||||
// If the next non-uppercase character was not a letter, we seem
|
||||
@@ -802,14 +802,14 @@ bool swift::omitNeedlessWords(StringRef &baseName,
|
||||
/// Local function that lowercases all of the base names and
|
||||
/// argument names before returning.
|
||||
auto lowercaseAcronymsForReturn = [&] {
|
||||
StringRef newBaseName = toLowercaseWordAndAcronym(baseName, scratch);
|
||||
StringRef newBaseName = toLowercaseInitialisms(baseName, scratch);
|
||||
if (baseName.data() != newBaseName.data()) {
|
||||
baseName = newBaseName;
|
||||
anyChanges = true;
|
||||
}
|
||||
|
||||
for (StringRef &argName : argNames) {
|
||||
StringRef newArgName = toLowercaseWordAndAcronym(argName, scratch);
|
||||
StringRef newArgName = toLowercaseInitialisms(argName, scratch);
|
||||
if (argName.data() != newArgName.data()) {
|
||||
argName = newArgName;
|
||||
anyChanges = true;
|
||||
|
||||
Reference in New Issue
Block a user