[Omit needless words] Fix lowercasing of initialisms with two-letter initial words.

Fixes rdar://problem/26643039.
This commit is contained in:
Doug Gregor
2016-06-13 17:59:14 -07:00
parent 011e306fe8
commit 5bea187b0f
5 changed files with 20 additions and 7 deletions

View File

@@ -857,14 +857,13 @@ camel_case::toLowercaseInitialisms(StringRef string,
// Lowercase until we hit the an uppercase letter followed by a
// non-uppercase letter.
llvm::SmallString<32> scratchStr;
scratchStr.push_back(clang::toLowercase(string[0]));
for (unsigned i = 1, n = string.size(); i != n; ++i) {
for (unsigned i = 0, 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
// to have a plural, we should still lowercase the character
// we're on.
if (!clang::isLetter(string[i+1]) ||
// to have a plural, or we're at the beginning, we should still
// lowercase the character we're on.
if (i == 0 || !clang::isLetter(string[i+1]) ||
isPluralSuffix(camel_case::getFirstWord(string.substr(i+1)))) {
scratchStr.push_back(clang::toLowercase(string[i]));
++i;

View File

@@ -15,7 +15,7 @@ var pp: AutoreleasingUnsafeMutablePointer<AnyObject?>? = nil
var userTypedObj = NSUIntTest()
// Check that the NSUInteger comes across as UInt from user Obj C modules.
var ur: UInt = userTypedObj.myCustomMethodThatOperates(onnsuIntegers: ui)
var ur: UInt = userTypedObj.myCustomMethodThatOperates(onNSUIntegers: ui)
userTypedObj.intProp = ui
userTypedObj.typedefProp = ui

View File

@@ -9,7 +9,8 @@
typedef NS_OPTIONS(NSUInteger, OMWWobbleOptions) {
OMWWobbleSideToSide = 0x01,
OMWWobbleBackAndForth = 0x02
OMWWobbleBackAndForth = 0x02,
OMWWobbleToXMLHex = 0x04
};
@interface OmitNeedlessWords : NSObject

View File

@@ -260,6 +260,11 @@
// CHECK-APPKIT: func add(_: Rect)
// CHECK-APPKIT: class func conjureRect(_: Rect)
// CHECK-OMIT-NEEDLESS-WORDS: struct OMWWobbleOptions
// CHECK-OMIT-NEEDLESS-WORDS: static var sideToSide: OMWWobbleOptions
// CHECK-OMIT-NEEDLESS-WORDS: static var backAndForth: OMWWobbleOptions
// CHECK-OMIT-NEEDLESS-WORDS: static var toXMLHex: OMWWobbleOptions
// CHECK-OMIT-NEEDLESS-WORDS: func jump(to: URL)
// CHECK-OMIT-NEEDLESS-WORDS: func objectIs(compatibleWith: AnyObject) -> Bool
// CHECK-OMIT-NEEDLESS-WORDS: func insetBy(x: Int, y: Int)

View File

@@ -192,6 +192,14 @@ TEST(ToLowercaseTest, Words) {
EXPECT_EQ(camel_case::toLowercaseWord("", scratch), "");
}
TEST(ToLowercaseInitialismsTest, Words) {
llvm::SmallString<64> scratch;
EXPECT_EQ(camel_case::toLowercaseInitialisms("ToXML", scratch), "toXML");
EXPECT_EQ(camel_case::toLowercaseInitialisms("URLsInHand", scratch),
"urlsInHand");
}
TEST(ToSentencecaseTest, Words) {
llvm::SmallString<64> scratch;