From 64f5512eeae568d574f0072e5f8f851d0ab2260e Mon Sep 17 00:00:00 2001 From: lijunjie Date: Thu, 5 Feb 2015 19:00:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9xcode6=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改警告。 --- .../project.pbxproj | 19 ++- .../PinYin4ObjcExample/ViewController.m | 2 +- .../PinYin4ObjcExampleTests.h | 4 +- .../PinYin4ObjcExampleTests.m | 2 +- PinYin4Objc/Classes/PinyinFormatter.m | 110 +++++++++--------- 5 files changed, 67 insertions(+), 70 deletions(-) diff --git a/Example/PinYin4ObjcExample/PinYin4ObjcExample.xcodeproj/project.pbxproj b/Example/PinYin4ObjcExample/PinYin4ObjcExample.xcodeproj/project.pbxproj index ba8f947..0fb2188 100644 --- a/Example/PinYin4ObjcExample/PinYin4ObjcExample.xcodeproj/project.pbxproj +++ b/Example/PinYin4ObjcExample/PinYin4ObjcExample.xcodeproj/project.pbxproj @@ -18,7 +18,6 @@ 1D40373517E740210061FF18 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D40373417E740210061FF18 /* Default-568h@2x.png */; }; 1D40373817E740210061FF18 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1D40373617E740210061FF18 /* MainStoryboard.storyboard */; }; 1D40373B17E740210061FF18 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D40373A17E740210061FF18 /* ViewController.m */; }; - 1D40374317E740210061FF18 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D40374217E740210061FF18 /* SenTestingKit.framework */; }; 1D40374417E740210061FF18 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D40371E17E740210061FF18 /* UIKit.framework */; }; 1D40374517E740210061FF18 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D40372017E740210061FF18 /* Foundation.framework */; }; 1D40374D17E740210061FF18 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1D40374B17E740210061FF18 /* InfoPlist.strings */; }; @@ -59,7 +58,6 @@ 1D40373917E740210061FF18 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 1D40373A17E740210061FF18 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 1D40374117E740210061FF18 /* PinYin4ObjcExampleTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PinYin4ObjcExampleTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; - 1D40374217E740210061FF18 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; 1D40374A17E740210061FF18 /* PinYin4ObjcExampleTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PinYin4ObjcExampleTests-Info.plist"; sourceTree = ""; }; 1D40374C17E740210061FF18 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 1D40374E17E740210061FF18 /* PinYin4ObjcExampleTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PinYin4ObjcExampleTests.h; sourceTree = ""; }; @@ -93,7 +91,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 1D40374317E740210061FF18 /* SenTestingKit.framework in Frameworks */, 1D40374417E740210061FF18 /* UIKit.framework in Frameworks */, 1D40374517E740210061FF18 /* Foundation.framework in Frameworks */, ); @@ -128,7 +125,6 @@ 1D40371E17E740210061FF18 /* UIKit.framework */, 1D40372017E740210061FF18 /* Foundation.framework */, 1D40372217E740210061FF18 /* CoreGraphics.framework */, - 1D40374217E740210061FF18 /* SenTestingKit.framework */, ); name = Frameworks; sourceTree = ""; @@ -252,7 +248,7 @@ name = PinYin4ObjcExampleTests; productName = PinYin4ObjcExampleTests; productReference = 1D40374117E740210061FF18 /* PinYin4ObjcExampleTests.octest */; - productType = "com.apple.product-type.bundle"; + productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -260,6 +256,7 @@ 1D40371317E740210061FF18 /* Project object */ = { isa = PBXProject; attributes = { + LastTestingUpgradeCheck = 0610; LastUpgradeCheck = 0460; ORGANIZATIONNAME = kimziv; }; @@ -410,7 +407,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 6.1; ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos6.1; + SDKROOT = iphoneos; }; name = Debug; }; @@ -434,7 +431,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 6.1; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; - SDKROOT = iphoneos6.1; + SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; @@ -446,7 +443,7 @@ GCC_PREFIX_HEADER = "PinYin4ObjcExample/PinYin4ObjcExample-Prefix.pch"; INFOPLIST_FILE = "PinYin4ObjcExample/PinYin4ObjcExample-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos6.1; + SDKROOT = iphoneos; WRAPPER_EXTENSION = app; }; name = Debug; @@ -458,7 +455,7 @@ GCC_PREFIX_HEADER = "PinYin4ObjcExample/PinYin4ObjcExample-Prefix.pch"; INFOPLIST_FILE = "PinYin4ObjcExample/PinYin4ObjcExample-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = iphoneos6.1; + SDKROOT = iphoneos; WRAPPER_EXTENSION = app; }; name = Release; @@ -470,13 +467,13 @@ FRAMEWORK_SEARCH_PATHS = ( "\"$(SDKROOT)/Developer/Library/Frameworks\"", "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", + "$(inherited)", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PinYin4ObjcExample/PinYin4ObjcExample-Prefix.pch"; INFOPLIST_FILE = "PinYin4ObjcExampleTests/PinYin4ObjcExampleTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; - WRAPPER_EXTENSION = octest; }; name = Debug; }; @@ -487,13 +484,13 @@ FRAMEWORK_SEARCH_PATHS = ( "\"$(SDKROOT)/Developer/Library/Frameworks\"", "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", + "$(inherited)", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PinYin4ObjcExample/PinYin4ObjcExample-Prefix.pch"; INFOPLIST_FILE = "PinYin4ObjcExampleTests/PinYin4ObjcExampleTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; - WRAPPER_EXTENSION = octest; }; name = Release; }; diff --git a/Example/PinYin4ObjcExample/PinYin4ObjcExample/ViewController.m b/Example/PinYin4ObjcExample/PinYin4ObjcExample/ViewController.m index 184eb0d..6076c1a 100644 --- a/Example/PinYin4ObjcExample/PinYin4ObjcExample/ViewController.m +++ b/Example/PinYin4ObjcExample/PinYin4ObjcExample/ViewController.m @@ -39,7 +39,7 @@ -(IBAction)doClick:(id)sender NSTimeInterval endTime=[[NSDate date] timeIntervalSince1970]; NSTimeInterval totalTime=endTime-startTime; _timeLb.text=[NSString stringWithFormat:@"Total Time:%fs",totalTime]; - _wordsLb.text=[NSString stringWithFormat:@"Total Words:%i characters",sourceText.length]; + _wordsLb.text=[NSString stringWithFormat:@"Total Words:%lu characters",(unsigned long)sourceText.length]; _outputTv.text=pinYin; }]; diff --git a/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.h b/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.h index 8c59463..ddf3d27 100644 --- a/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.h +++ b/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.h @@ -6,8 +6,8 @@ // Copyright (c) 2013年 kimziv. All rights reserved. // -#import +#import -@interface PinYin4ObjcExampleTests : SenTestCase +@interface PinYin4ObjcExampleTests : XCTestCase @end diff --git a/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.m b/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.m index aa00263..a491e43 100644 --- a/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.m +++ b/Example/PinYin4ObjcExample/PinYin4ObjcExampleTests/PinYin4ObjcExampleTests.m @@ -26,7 +26,7 @@ - (void)tearDown - (void)testExample { - STFail(@"Unit tests are not implemented yet in PinYin4ObjcExampleTests"); + XCTFail(@"Unit tests are not implemented yet in PinYin4ObjcExampleTests"); } @end diff --git a/PinYin4Objc/Classes/PinyinFormatter.m b/PinYin4Objc/Classes/PinyinFormatter.m index 7c9f2c1..77af45f 100644 --- a/PinYin4Objc/Classes/PinyinFormatter.m +++ b/PinYin4Objc/Classes/PinyinFormatter.m @@ -76,65 +76,65 @@ + (NSString *)formatHanyuPinyinWithNSString:(NSString *)pinyinStr } + (NSString *)convertToneNumber2ToneMarkWithNSString:(NSString *)pinyinStr { - NSString *lowerCasePinyinStr = [pinyinStr lowercaseString]; - if ([lowerCasePinyinStr matchesPatternRegexPattern:@"[a-z]*[1-5]?"]) { - unichar defautlCharValue = '$'; - int defautlIndexValue = -1; - unichar unmarkedVowel = defautlCharValue; - int indexOfUnmarkedVowel = defautlIndexValue; - unichar charA = 'a'; - unichar charE = 'e'; - NSString *ouStr = @"ou"; - NSString *allUnmarkedVowelStr = @"aeiouv"; - NSString *allMarkedVowelStr = @"āáăàaēéĕèeīíĭìiōóŏòoūúŭùuǖǘǚǜü"; - if ([lowerCasePinyinStr matchesPatternRegexPattern:@"[a-z]*[1-5]"]) { - int tuneNumber = [PinyinFormatter getNumericValue:[lowerCasePinyinStr characterAtIndex:lowerCasePinyinStr.length -1]]; - int indexOfA = [lowerCasePinyinStr indexOf:charA]; - int indexOfE = [lowerCasePinyinStr indexOf:charE]; - int ouIndex = [lowerCasePinyinStr indexOfString:ouStr]; - if (-1 != indexOfA) { - indexOfUnmarkedVowel = indexOfA; - unmarkedVowel = charA; - } - else if (-1 != indexOfE) { - indexOfUnmarkedVowel = indexOfE; - unmarkedVowel = charE; - } - else if (-1 != ouIndex) { - indexOfUnmarkedVowel = ouIndex; - unmarkedVowel = [ouStr characterAtIndex:0]; - } - else { - for (int i = [lowerCasePinyinStr length] - 1; i >= 0; i--) { - if ([[NSString valueOfChar:[lowerCasePinyinStr characterAtIndex:i]] matchesPatternRegexPattern:@"[aeiouv]"]) { - indexOfUnmarkedVowel = i; - unmarkedVowel = [lowerCasePinyinStr characterAtIndex:i]; - break; - } + NSString *lowerCasePinyinStr = [pinyinStr lowercaseString]; + if ([lowerCasePinyinStr matchesPatternRegexPattern:@"[a-z]*[1-5]?"]) { + unichar defautlCharValue = '$'; + NSInteger defautlIndexValue = -1; + unichar unmarkedVowel = defautlCharValue; + NSInteger indexOfUnmarkedVowel = defautlIndexValue; + unichar charA = 'a'; + unichar charE = 'e'; + NSString *ouStr = @"ou"; + NSString *allUnmarkedVowelStr = @"aeiouv"; + NSString *allMarkedVowelStr = @"āáăàaēéĕèeīíĭìiōóŏòoūúŭùuǖǘǚǜü"; + if ([lowerCasePinyinStr matchesPatternRegexPattern:@"[a-z]*[1-5]"]) { + NSInteger tuneNumber = [PinyinFormatter getNumericValue:[lowerCasePinyinStr characterAtIndex:lowerCasePinyinStr.length -1]]; + NSInteger indexOfA = [lowerCasePinyinStr indexOf:charA]; + NSInteger indexOfE = [lowerCasePinyinStr indexOf:charE]; + NSInteger ouIndex = [lowerCasePinyinStr indexOfString:ouStr]; + if (-1 != indexOfA) { + indexOfUnmarkedVowel = indexOfA; + unmarkedVowel = charA; + } + else if (-1 != indexOfE) { + indexOfUnmarkedVowel = indexOfE; + unmarkedVowel = charE; + } + else if (-1 != ouIndex) { + indexOfUnmarkedVowel = ouIndex; + unmarkedVowel = [ouStr characterAtIndex:0]; + } + else { + for (NSInteger i = [lowerCasePinyinStr length] - 1; i >= 0; i--) { + if ([[NSString valueOfChar:[lowerCasePinyinStr characterAtIndex:i]] matchesPatternRegexPattern:@"[aeiouv]"]) { + indexOfUnmarkedVowel = i; + unmarkedVowel = [lowerCasePinyinStr characterAtIndex:i]; + break; + } + } + } + if ((defautlCharValue != unmarkedVowel) && (defautlIndexValue != indexOfUnmarkedVowel)) { + NSInteger rowIndex = [allUnmarkedVowelStr indexOf:unmarkedVowel]; + NSInteger columnIndex = tuneNumber - 1; + NSInteger vowelLocation = rowIndex * 5 + columnIndex; + unichar markedVowel = [allMarkedVowelStr characterAtIndex:vowelLocation]; + NSMutableString *resultBuffer = [[NSMutableString alloc] init]; + [resultBuffer appendString:[[lowerCasePinyinStr substringToIndex:indexOfUnmarkedVowel+1] stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]]; + [resultBuffer appendFormat:@"%C",markedVowel]; + [resultBuffer appendString:[[lowerCasePinyinStr substringWithRange:NSMakeRange(indexOfUnmarkedVowel + 1, lowerCasePinyinStr.length-indexOfUnmarkedVowel)] stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]]; + return [resultBuffer description]; + } + else { + return lowerCasePinyinStr; + } + } + else { + return [lowerCasePinyinStr stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]; } - } - if ((defautlCharValue != unmarkedVowel) && (defautlIndexValue != indexOfUnmarkedVowel)) { - int rowIndex = [allUnmarkedVowelStr indexOf:unmarkedVowel]; - int columnIndex = tuneNumber - 1; - int vowelLocation = rowIndex * 5 + columnIndex; - unichar markedVowel = [allMarkedVowelStr characterAtIndex:vowelLocation]; - NSMutableString *resultBuffer = [[NSMutableString alloc] init]; - [resultBuffer appendString:[[lowerCasePinyinStr substringToIndex:indexOfUnmarkedVowel+1] stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]]; - [resultBuffer appendFormat:@"%C",markedVowel]; - [resultBuffer appendString:[[lowerCasePinyinStr substringWithRange:NSMakeRange(indexOfUnmarkedVowel + 1, lowerCasePinyinStr.length-indexOfUnmarkedVowel)] stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]]; - return [resultBuffer description]; - } - else { - return lowerCasePinyinStr; - } } else { - return [lowerCasePinyinStr stringByReplacingOccurrencesOfString:@"v" withString:@"ü"]; + return lowerCasePinyinStr; } - } - else { - return lowerCasePinyinStr; - } } +(NSInteger)getNumericValue:(unichar)c