Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改xcode6支持 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
1D40373517E740210061FF18 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1D40373417E740210061FF18 /* [email protected] */; };
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 */; };
Expand Down Expand Up @@ -59,7 +58,6 @@
1D40373917E740210061FF18 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
1D40373A17E740210061FF18 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
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 = "<group>"; };
1D40374C17E740210061FF18 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1D40374E17E740210061FF18 /* PinYin4ObjcExampleTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PinYin4ObjcExampleTests.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -93,7 +91,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1D40374317E740210061FF18 /* SenTestingKit.framework in Frameworks */,
1D40374417E740210061FF18 /* UIKit.framework in Frameworks */,
1D40374517E740210061FF18 /* Foundation.framework in Frameworks */,
);
Expand Down Expand Up @@ -128,7 +125,6 @@
1D40371E17E740210061FF18 /* UIKit.framework */,
1D40372017E740210061FF18 /* Foundation.framework */,
1D40372217E740210061FF18 /* CoreGraphics.framework */,
1D40374217E740210061FF18 /* SenTestingKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -252,14 +248,15 @@
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 */

/* Begin PBXProject section */
1D40371317E740210061FF18 /* Project object */ = {
isa = PBXProject;
attributes = {
LastTestingUpgradeCheck = 0610;
LastUpgradeCheck = 0460;
ORGANIZATIONNAME = kimziv;
};
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright (c) 2013年 kimziv. All rights reserved.
//

#import <SenTestingKit/SenTestingKit.h>
#import <XCTest/XCTest.h>

@interface PinYin4ObjcExampleTests : SenTestCase
@interface PinYin4ObjcExampleTests : XCTestCase

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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
110 changes: 55 additions & 55 deletions PinYin4Objc/Classes/PinyinFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down