+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
Pods/

# Carthage
Carthage/

# OS X Temporary files
#
._*
.DS_Store
*.swp
profile

# AppCode
#
.idea/

8 changes: 4 additions & 4 deletions Inflection Tests/Inflection_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import XCTest
class Inflection_Tests: XCTestCase {

func testRubyToSwift() {
var subjectString = "createdAt".rubyCase()
var expectedString = "created_at"
let subjectString = "createdAt".rubyCase()
let expectedString = "created_at"

XCTAssertEqual(subjectString, expectedString, "New string should be 'created_at'")
}

func testSwiftToRuby() {
var subjectString = "updated_at".swiftCase()
var expectedString = "updatedAt"
let subjectString = "updated_at".swiftCase()
let expectedString = "updatedAt"

XCTAssertEqual(subjectString, expectedString, "New string should be 'createdAt'")
}
Expand Down
2 changes: 1 addition & 1 deletion Inflection Tests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.zenangst.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
49 changes: 44 additions & 5 deletions Inflection.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/* Begin PBXBuildFile section */
BDD8223F1AA4476700E48CEF /* Inflection_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD8223E1AA4476700E48CEF /* Inflection_Tests.swift */; };
BDD822471AA4477E00E48CEF /* Inflection.podspec in Resources */ = {isa = PBXBuildFile; fileRef = BDD822441AA4477E00E48CEF /* Inflection.podspec */; };
BDD822481AA4477E00E48CEF /* LICENSE.md in Sources */ = {isa = PBXBuildFile; fileRef = BDD822451AA4477E00E48CEF /* LICENSE.md */; };
BDD822491AA4477E00E48CEF /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = BDD822461AA4477E00E48CEF /* README.md */; };
BDD8224B1AA447E400E48CEF /* Inflection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD8224A1AA447E400E48CEF /* Inflection.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -106,10 +104,11 @@
BDD8222F1AA4473F00E48CEF /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
LastUpgradeCheck = 0810;
TargetAttributes = {
BDD822381AA4476700E48CEF = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0810;
};
};
};
Expand Down Expand Up @@ -146,8 +145,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BDD822491AA4477E00E48CEF /* README.md in Sources */,
BDD822481AA4477E00E48CEF /* LICENSE.md in Sources */,
BDD8224B1AA447E400E48CEF /* Inflection.swift in Sources */,
BDD8223F1AA4476700E48CEF /* Inflection_Tests.swift in Sources */,
);
Expand All @@ -159,12 +156,49 @@
BDD822331AA4473F00E48CEF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
};
name = Debug;
};
BDD822341AA4473F00E48CEF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand Down Expand Up @@ -212,9 +246,11 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.zenangst.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand Down Expand Up @@ -255,8 +291,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.zenangst.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -280,6 +318,7 @@
BDD822411AA4476700E48CEF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -23,10 +23,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -48,15 +48,18 @@
ReferencedContainer = "container:Inflection.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -71,10 +74,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
60 changes: 30 additions & 30 deletions Source/Inflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public extension NSDictionary {
return self.inflectDictionaryKeys({ (string) -> String in string.rubyCase()})
}

private func inflectDictionaryKeys(closure: (string: String) -> String) -> NSDictionary {
var newDictionary = NSMutableDictionary.new()
map(self) { newDictionary[closure(string: $0 as! String)] = $1 }
fileprivate func inflectDictionaryKeys(_ closure: @escaping (_ string: String) -> String) -> NSDictionary {
let newDictionary = NSMutableDictionary()
self.forEach { newDictionary[closure($0 as! String)] = $1 }

return newDictionary.copy() as! NSDictionary
}
Expand Down Expand Up @@ -82,56 +82,56 @@ public extension String {
}

func humanize() -> String {
return self.replaceIdentifierWithString(" ").capitalizedString
return self.replaceIdentifierWithString(" ").capitalized
}

private func lowerCaseFirstLetter() -> String {
var mutableString = self.mutableCopy() as! NSMutableString
mutableString.replaceCharactersInRange(NSMakeRange(0, 1), withString: self.firstLetter().lowercaseString as String)
fileprivate func lowerCaseFirstLetter() -> String {
let mutableString = self.mutableCopy() as! NSMutableString
mutableString.replaceCharacters(in: NSMakeRange(0, 1), with: self.firstLetter().lowercased() as String)

return mutableString.copy() as! String
}

private func upperCaseFirstLetter() -> String {
var mutableString = self.mutableCopy() as! NSMutableString
mutableString.replaceCharactersInRange(NSMakeRange(0, 1), withString: self.firstLetter().uppercaseString as String)
fileprivate func upperCaseFirstLetter() -> String {
let mutableString = self.mutableCopy() as! NSMutableString
mutableString.replaceCharacters(in: NSMakeRange(0, 1), with: self.firstLetter().uppercased() as String)

return mutableString.copy() as! String
}

private func firstLetter() -> String {
return (self as NSString).substringToIndex(1) as String
fileprivate func firstLetter() -> String {
return (self as NSString).substring(to: 1) as String
}

private func replaceIdentifierWithString(identifier: String) -> String {
fileprivate func replaceIdentifierWithString(_ identifier: String) -> String {

let scanner = NSScanner.init(string: self)
let identifierSet = NSCharacterSet.init(charactersInString: identifier)
let alphaNumericSet = NSCharacterSet.alphanumericCharacterSet()
let uppercaseSet = NSCharacterSet.uppercaseLetterCharacterSet()
let lowercaseSet = NSCharacterSet.lowercaseLetterCharacterSet()
let scanner = Scanner.init(string: self)
let identifierSet = CharacterSet.init(charactersIn: identifier)
let alphaNumericSet = CharacterSet.alphanumerics
let uppercaseSet = CharacterSet.uppercaseLetters
let lowercaseSet = CharacterSet.lowercaseLetters

var buffer: NSString?
var output: NSMutableString = NSMutableString.new()
let output: NSMutableString = NSMutableString()

scanner.caseSensitive = true

while !scanner.atEnd {
if scanner.scanCharactersFromSet(identifierSet, intoString: &buffer) {
while !scanner.isAtEnd {
if scanner.scanCharacters(from: identifierSet, into: &buffer) {
continue
} else if count(identifier) > 0 {
var isUppercase: Bool = scanner.scanCharactersFromSet(uppercaseSet, intoString: &buffer)
} else if !identifier.isEmpty {
let isUppercase: Bool = scanner.scanCharacters(from: uppercaseSet, into: &buffer)
if isUppercase {
output.appendString(identifier)
output.appendString(buffer!.lowercaseString)
output.append(identifier)
output.append(buffer!.lowercased)
}

var isLowercase: Bool = scanner.scanCharactersFromSet(lowercaseSet, intoString: &buffer)
let isLowercase: Bool = scanner.scanCharacters(from: lowercaseSet, into: &buffer)
if isLowercase {
output.appendString(buffer!.lowercaseString)
output.append(buffer!.lowercased)
}
} else if scanner.scanCharactersFromSet(alphaNumericSet, intoString: &buffer) {
output.appendString(buffer!.capitalizedString)
} else if scanner.scanCharacters(from: alphaNumericSet, into: &buffer) {
output.append(buffer!.capitalized)
} else {
scanner.scanLocation = scanner.scanLocation + 1
}
Expand All @@ -141,4 +141,4 @@ public extension String {
return output.copy() as! String
}

}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载