Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Change default short URL length.
Browse files Browse the repository at this point in the history
Fix warnings.

Tests will fail until conformance tests would be updated.
  • Loading branch information
Satoshi Nakagawa committed Nov 7, 2012
1 parent aa9b578 commit 2026773
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions lib/TwitterText.h
Expand Up @@ -23,10 +23,10 @@
+ (NSArray*)mentionsOrListsInText:(NSString*)text;
+ (TwitterTextEntity*)repliedScreenNameInText:(NSString*)text;

+ (int)tweetLength:(NSString*)text;
+ (int)tweetLength:(NSString*)text httpURLLength:(int)httpURLLength httpsURLLength:(int)httpsURLLength;
+ (NSInteger)tweetLength:(NSString*)text;
+ (NSInteger)tweetLength:(NSString*)text httpURLLength:(NSInteger)httpURLLength httpsURLLength:(NSInteger)httpsURLLength;

+ (int)remainingCharacterCount:(NSString*)text;
+ (int)remainingCharacterCount:(NSString*)text httpURLLength:(int)httpURLLength httpsURLLength:(int)httpsURLLength;
+ (NSInteger)remainingCharacterCount:(NSString*)text;
+ (NSInteger)remainingCharacterCount:(NSString*)text httpURLLength:(NSInteger)httpURLLength httpsURLLength:(NSInteger)httpsURLLength;

@end
20 changes: 10 additions & 10 deletions lib/TwitterText.m
Expand Up @@ -282,9 +282,9 @@
@")" \
@")"

static const int MaxTweetLength = 140;
static const int HTTPShortURLLength = 20;
static const int HTTPSShortURLLength = 21;
static const NSInteger MaxTweetLength = 140;
static const NSInteger HTTPShortURLLength = 21;
static const NSInteger HTTPSShortURLLength = 22;

static NSRegularExpression *validURLRegexp;
static NSCharacterSet *invalidURLWithoutProtocolPrecedingCharSet;
Expand Down Expand Up @@ -673,12 +673,12 @@ + (TwitterTextEntity*)repliedScreenNameInText:(NSString*)text
return [TwitterTextEntity entityWithType:TwitterTextEntityScreenName range:replyRange];
}

+ (int)tweetLength:(NSString*)text
+ (NSInteger)tweetLength:(NSString*)text
{
return [self tweetLength:text httpURLLength:HTTPShortURLLength httpsURLLength:HTTPSShortURLLength];
}

+ (int)tweetLength:(NSString*)text httpURLLength:(int)httpURLLength httpsURLLength:(int)httpsURLLength
+ (NSInteger)tweetLength:(NSString*)text httpURLLength:(NSInteger)httpURLLength httpsURLLength:(NSInteger)httpsURLLength
{
text = [text precomposedStringWithCanonicalMapping];

Expand All @@ -694,7 +694,7 @@ + (int)tweetLength:(NSString*)text httpURLLength:(int)httpURLLength httpsURLLeng

int urlLengthOffset = 0;
NSArray *urlEntities = [self URLsInText:text];
for (int i=urlEntities.count-1; i>=0; i--) {
for (NSInteger i=urlEntities.count-1; i>=0; i--) {
TwitterTextEntity *entity = [urlEntities objectAtIndex:i];
NSRange urlRange = entity.range;
NSString *url = [string substringWithRange:urlRange];
Expand All @@ -706,8 +706,8 @@ + (int)tweetLength:(NSString*)text httpURLLength:(int)httpURLLength httpsURLLeng
[string deleteCharactersInRange:urlRange];
}

int len = string.length;
int charCount = len + urlLengthOffset;
NSInteger len = string.length;
NSInteger charCount = len + urlLengthOffset;

if (len > 0) {
// Adjust count for non-BMP characters
Expand All @@ -731,12 +731,12 @@ + (int)tweetLength:(NSString*)text httpURLLength:(int)httpURLLength httpsURLLeng
return charCount;
}

+ (int)remainingCharacterCount:(NSString*)text
+ (NSInteger)remainingCharacterCount:(NSString*)text
{
return [self remainingCharacterCount:text httpURLLength:HTTPShortURLLength httpsURLLength:HTTPSShortURLLength];
}

+ (int)remainingCharacterCount:(NSString*)text httpURLLength:(int)httpURLLength httpsURLLength:(int)httpsURLLength
+ (NSInteger)remainingCharacterCount:(NSString*)text httpURLLength:(NSInteger)httpURLLength httpsURLLength:(NSInteger)httpsURLLength
{
return MaxTweetLength - [self tweetLength:text httpURLLength:httpURLLength httpsURLLength:httpsURLLength];
}
Expand Down
40 changes: 20 additions & 20 deletions testproject/TwitterTextTests.m
Expand Up @@ -64,8 +64,8 @@ - (void)testExtract

NSArray *results = [TwitterText mentionsOrListsInText:text];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSString *expectedText = [expected objectAtIndex:i];

TwitterTextEntity *entity = [results objectAtIndex:i];
Expand All @@ -91,8 +91,8 @@ - (void)testExtract

NSArray *results = [TwitterText mentionsOrListsInText:text];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSDictionary *expectedDic = [expected objectAtIndex:i];
NSString *expectedText = [expectedDic objectForKey:@"screen_name"];
NSArray *indices = [expectedDic objectForKey:@"indices"];
Expand Down Expand Up @@ -125,8 +125,8 @@ - (void)testExtract

NSArray *results = [TwitterText mentionsOrListsInText:text];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSDictionary *expectedDic = [expected objectAtIndex:i];
NSString *expectedText = [expectedDic objectForKey:@"screen_name"];
NSString *expectedListSlug = [expectedDic objectForKey:@"list_slug"];
Expand Down Expand Up @@ -186,8 +186,8 @@ - (void)testExtract

NSArray *results = [TwitterText URLsInText:text];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSString *expectedText = [expected objectAtIndex:i];

TwitterTextEntity *entity = [results objectAtIndex:i];
Expand All @@ -211,8 +211,8 @@ - (void)testExtract

NSArray *results = [TwitterText URLsInText:text];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSDictionary *expectedDic = [expected objectAtIndex:i];
NSString *expectedUrl = [expectedDic objectForKey:@"url"];
NSArray *expectedIndices = [expectedDic objectForKey:@"indices"];
Expand Down Expand Up @@ -242,8 +242,8 @@ - (void)testExtract

NSArray *results = [TwitterText hashtagsInText:text checkingURLOverlap:YES];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSString *expectedText = [expected objectAtIndex:i];

TwitterTextEntity *entity = [results objectAtIndex:i];
Expand All @@ -269,8 +269,8 @@ - (void)testExtract

NSArray *results = [TwitterText hashtagsInText:text checkingURLOverlap:YES];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSDictionary *expectedDic = [expected objectAtIndex:i];
NSString *expectedHashtag = [expectedDic objectForKey:@"hashtag"];
NSArray *expectedIndices = [expectedDic objectForKey:@"indices"];
Expand Down Expand Up @@ -303,8 +303,8 @@ - (void)testExtract

NSArray *results = [TwitterText cashtagsInText:text checkingURLOverlap:YES];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSString *expectedText = [expected objectAtIndex:i];

TwitterTextEntity *entity = [results objectAtIndex:i];
Expand All @@ -330,8 +330,8 @@ - (void)testExtract

NSArray *results = [TwitterText cashtagsInText:text checkingURLOverlap:YES];
if (results.count == expected.count) {
int count = results.count;
for (int i=0; i<count; i++) {
NSInteger count = results.count;
for (NSInteger i=0; i<count; i++) {
NSDictionary *expectedDic = [expected objectAtIndex:i];
NSString *expectedCashtag = [expectedDic objectForKey:@"cashtag"];
NSArray *expectedIndices = [expectedDic objectForKey:@"indices"];
Expand Down Expand Up @@ -376,8 +376,8 @@ - (void)testValidate

for (NSDictionary *testCase in lengths) {
NSString *text = [testCase objectForKey:@"text"];
int expected = [[testCase objectForKey:@"expected"] intValue];
int len = [TwitterText tweetLength:text];
NSInteger expected = [[testCase objectForKey:@"expected"] intValue];
NSInteger len = [TwitterText tweetLength:text];
STAssertTrue(len == expected, @"Length should be %d (%d)", expected, len);
}
}
Expand Down

0 comments on commit 2026773

Please sign in to comment.