Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change default short URL length.

Fix warnings.

Tests will fail until conformance tests would be updated.
  • Loading branch information...
commit 2026773e94c4a2033595519af876a82ee121a6fd 1 parent aa9b578
@psychs psychs authored
View
8 lib/TwitterText.h
@@ -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
View
20 lib/TwitterText.m
@@ -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;
@@ -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];
@@ -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];
@@ -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
@@ -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];
}
View
40 testproject/TwitterTextTests.m
@@ -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];
@@ -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"];
@@ -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"];
@@ -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];
@@ -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"];
@@ -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];
@@ -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"];
@@ -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];
@@ -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"];
@@ -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);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.