mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Omit needless words] Fix lowercasing of initialisms with two-letter initial words.
Fixes rdar://problem/26643039.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
typedef NS_OPTIONS(NSUInteger, OMWWobbleOptions) {
|
||||
OMWWobbleSideToSide = 0x01,
|
||||
OMWWobbleBackAndForth = 0x02
|
||||
OMWWobbleBackAndForth = 0x02,
|
||||
OMWWobbleToXMLHex = 0x04
|
||||
};
|
||||
|
||||
@interface OmitNeedlessWords : NSObject
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user