Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kimziv committed Oct 8, 2013
1 parent a0258a5 commit c9da7c7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ -(IBAction)doClick:(id)sender
[outputFormat setCaseType:CaseTypeLowercase];
NSTimeInterval startTime=[[NSDate date] timeIntervalSince1970];

[PinyinHelper toHanyuPinyinStringWithNSString:sourceText withHanyuPinyinOutputFormat:outputFormat withNSString:@"" outputBlock:^(NSString *pinYin) {
[PinyinHelper toHanyuPinyinStringWithNSString:sourceText withHanyuPinyinOutputFormat:outputFormat withNSString:@" " outputBlock:^(NSString *pinYin) {
NSTimeInterval endTime=[[NSDate date] timeIntervalSince1970];
NSTimeInterval totalTime=endTime-startTime;
_timeLb.text=[NSString stringWithFormat:@"Total Time:%fs",totalTime];
Expand Down
4 changes: 2 additions & 2 deletions PinYin4Objc.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "PinYin4Objc"
s.version = "1.0.2"
s.version = "1.1.0"
s.summary = "PinYin4Objc."
s.description = <<-DESC
PinYin4Objc is a popular objective-c library supporting convertion between Chinese(both Simplified and Tranditional) characters and most popular Pinyin systems, it's performance is very efficient, data cached at first time. The output format of pinyin could be customized.
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.license = {:type => 'Apache',:file => 'LICENSE'}
s.author = { "kimziv" => "[email protected]" }
s.platform = :ios
s.source = { :git => 'https://github.com/kimziv/PinYin4Objc.git', :tag => '1.0.2'}
s.source = { :git => 'https://github.com/kimziv/PinYin4Objc.git', :tag => '1.1.0'}
s.source_files = 'PinYin4Objc/Classes/*.{h,m}'
s.resources = "PinYin4Objc/Resources/*"
s.requires_arc = true
Expand Down
10 changes: 8 additions & 2 deletions PinYin4Objc/Classes/ChineseToPinyinResource.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#define RIGHT_BRACKET @")"
#define COMMA @","

#ifdef DEBUG
#define PYLog(...) NSLog(__VA_ARGS__)
#else
#define PYLog(__unused ...)
#endif

#define kCacheKeyForUnicode2Pinyin @"UnicodeToPinyin"
static inline NSString* cachePathForKey(NSString* directory, NSString* key) {
return [directory stringByAppendingPathComponent:key];
Expand Down Expand Up @@ -38,7 +44,7 @@ - (void)initializeResource {
{
NSError *error=nil;
if (![fileManager createDirectoryAtPath:_directory withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"Error, s is %@, %s, %s, %d",error.description, __FILE__ ,__FUNCTION__, __LINE__);
PYLog(@"Error, s is %@, %s, %s, %d",error.description, __FILE__ ,__FUNCTION__, __LINE__);
}

}
Expand Down Expand Up @@ -83,7 +89,7 @@ -(void)cacheObjec:(id<NSCoding>)obj forKey:(NSString *)key
NSError *error=nil;
[data writeToFile:cachePath options:NSDataWritingAtomic error:&error];
if (error){
NSLog(@"Error, s is %@, %s, %s, %d",error.description, __FILE__ ,__FUNCTION__, __LINE__);
PYLog(@"Error, s is %@, %s, %s, %d",error.description, __FILE__ ,__FUNCTION__, __LINE__);
}
});
}
Expand Down
12 changes: 9 additions & 3 deletions PinYin4Objc/Classes/NSString+PinYin4Cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#import "NSString+PinYin4Cocoa.h"

#ifdef DEBUG
#define PYLog(...) NSLog(__VA_ARGS__)
#else
#define PYLog(__unused ...)
#endif

@implementation NSString (PinYin4Cocoa)


Expand Down Expand Up @@ -70,7 +76,7 @@ -(NSString *) stringByReplacingRegexPattern:(NSString *)regex withString:(NSStri
NSError *error=nil;
NSRegularExpression *pattern = [NSRegularExpression regularExpressionWithPattern:regex options:options error:&error];
if (error) {
NSLog(@"Error creating Regex: %@",[error description]);
PYLog(@"Error creating Regex: %@",[error description]);
return nil;
}

Expand All @@ -94,7 +100,7 @@ -(NSArray *) stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex caseIn
NSError *error=nil;
NSRegularExpression *pattern = [NSRegularExpression regularExpressionWithPattern:regex options:options error:&error];
if (error) {
NSLog(@"Error creating Regex: %@",[error description]);
PYLog(@"Error creating Regex: %@",[error description]);
return nil;
}

Expand Down Expand Up @@ -125,7 +131,7 @@ -(BOOL) matchesPatternRegexPattern:(NSString *)regex caseInsensitive:(BOOL) igno
NSError *error=nil;
NSRegularExpression *pattern = [NSRegularExpression regularExpressionWithPattern:regex options:options error:&error];
if (error) {
NSLog(@"Error creating Regex: %@",[error description]);
PYLog(@"Error creating Regex: %@",[error description]);
return NO; //Can't possibly match an invalid Regex
}

Expand Down
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
PinYin4Objc
===========

PinYin4Objc is a popular objective-c library supporting convertion between Chinese(both Simplified and Tranditional) characters and most popular Pinyin systems, it's performance is very efficient, data cached at first time. The output format of pinyin could be customized.
PinYin4Objc is a popular objective-c library supporting convertion between Chinese(both Simplified and Tranditional) characters and most popular Pinyin systems, it's performance is very efficient, data cached at first time, you can use async method with block, this can avoid ui blocking, and runs smoothly. The output format of pinyin could be customized.

*update

* Usage

2013-10-08, V1.1, add async methods whit block, solve ui blcoking problems and fix some cache bugs;
2013-09-16, V1.0, firt virsion published.

* Usage
*
1.use async method with block, this can avoid ui blocking, and runs smoothly:

NSString *sourceText=@"我爱中文";
HanyuPinyinOutputFormat *outputFormat=[[HanyuPinyinOutputFormat alloc] init];
[outputFormat setToneType:ToneTypeWithoutTone];
[outputFormat setVCharType:VCharTypeWithV];
[outputFormat setCaseType:CaseTypeLowercase];
[PinyinHelper toHanyuPinyinStringWithNSString:sourceText
withHanyuPinyinOutputFormat:outputFormat
withNSString:@" "
outputBlock:^(NSString *pinYin) {
_outputTv.text=pinYin; //update ui

}];
2. use sync method below:

NSString *sourceText=@"我爱中文";
HanyuPinyinOutputFormat *outputFormat=[[HanyuPinyinOutputFormat alloc] init];
[outputFormat setToneType:ToneTypeWithoutTone];
Expand Down

0 comments on commit c9da7c7

Please sign in to comment.