Bgerstle has uploaded a new change for review. https://gerrit.wikimedia.org/r/208830
Change subject: wmf-ify and rename string categories ...................................................................... wmf-ify and rename string categories Use Apple "stringBy..." convention and/or shorten method names. Change-Id: I59a391cd88a8e77ec96219b829b7425bcd908513 --- M MediaWikiKit/MediaWikiKit/MWKDataStore.m M MediaWikiKit/MediaWikiKit/MWKImageList.m M Wikipedia/Categories/MWKSection+TOC.m M Wikipedia/Categories/NSString+Extras.h M Wikipedia/Categories/NSString+Extras.m M Wikipedia/EventLogging/EventLogger.m M Wikipedia/Networking/Fetchers/NearbyFetcher.m M Wikipedia/Networking/Fetchers/PageHistoryFetcher.m M Wikipedia/Networking/Fetchers/SearchResultFetcher.m M Wikipedia/View Controllers/PageHistory/PageHistoryResultCell.m M Wikipedia/View Controllers/SavedPages/NSAttributedString+WMFSavedPagesAttributedStrings.m M Wikipedia/View Controllers/SearchResults/SearchResultsController.m M Wikipedia/View Controllers/ShareCard/WMFShareCardViewController.m M Wikipedia/View Controllers/ShareCard/WMFShareOptionsViewController.m M Wikipedia/View Controllers/WebView/WebViewController.m M Wikipedia/Web Image Interception/URLCache.m 16 files changed, 49 insertions(+), 60 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/30/208830/1 diff --git a/MediaWikiKit/MediaWikiKit/MWKDataStore.m b/MediaWikiKit/MediaWikiKit/MWKDataStore.m index 6d4abda..49a0841 100644 --- a/MediaWikiKit/MediaWikiKit/MWKDataStore.m +++ b/MediaWikiKit/MediaWikiKit/MWKDataStore.m @@ -100,7 +100,7 @@ } - (NSString*)safeFilenameWithImageURL:(NSString*)str { - str = [str getUrlWithoutScheme]; + str = [str wmf_schemelessURL]; if ([str hasPrefix:MWKDataStoreValidImageSitePrefix]) { NSString* suffix = [str substringFromIndex:[MWKDataStoreValidImageSitePrefix length]]; diff --git a/MediaWikiKit/MediaWikiKit/MWKImageList.m b/MediaWikiKit/MediaWikiKit/MWKImageList.m index f2ae92a..9e90a51 100644 --- a/MediaWikiKit/MediaWikiKit/MWKImageList.m +++ b/MediaWikiKit/MediaWikiKit/MWKImageList.m @@ -47,7 +47,7 @@ } - (void)addImageURL:(NSString*)imageURL { - imageURL = [imageURL getUrlWithoutScheme]; + imageURL = [imageURL wmf_schemelessURL]; [entries addObject:imageURL]; entriesByURL[imageURL] = imageURL; diff --git a/Wikipedia/Categories/MWKSection+TOC.m b/Wikipedia/Categories/MWKSection+TOC.m index 01325f9..f1631a9 100644 --- a/Wikipedia/Categories/MWKSection+TOC.m +++ b/Wikipedia/Categories/MWKSection+TOC.m @@ -15,7 +15,7 @@ NSString* title = isLead ? self.article.title.prefixedText : self.line; - NSString* noHtmlTitle = [title getStringWithoutHTML]; + NSString* noHtmlTitle = [title wmf_stringByRemovingHTML]; id titleToUse = isLead ? [self getLeadSectionAttributedTitleForString : noHtmlTitle] : noHtmlTitle; diff --git a/Wikipedia/Categories/NSString+Extras.h b/Wikipedia/Categories/NSString+Extras.h index bc5b0b8..d7bef31 100644 --- a/Wikipedia/Categories/NSString+Extras.h +++ b/Wikipedia/Categories/NSString+Extras.h @@ -6,24 +6,30 @@ /// @return A substring of the receiver going up to @c index, or @c length, whichever is shorter. - (NSString*)wmf_safeSubstringToIndex:(NSUInteger)index; -- (NSString*)urlEncodedUTF8String; -+ (NSString*)sha1:(NSString*)dataFromString isFile:(BOOL)isFile; -- (NSString*)getUrlWithoutScheme; -- (NSString*)getImageMimeTypeForExtension; +- (NSString*)wmf_UTF8StringWithPercentEscapes; -- (NSDate*) getDateFromIso8601DateString; -- (NSString*)getStringWithoutHTML; +- (NSString*)wmf_schemelessURL; -- (NSString*)randomlyRepeatMaxTimes:(NSUInteger)maxTimes; +- (NSString*)wmf_imageMimeTypeForExtension; -- (NSString*)wikiTitleWithoutUnderscores; -- (NSString*)wikiTitleWithoutSpaces; +- (NSDate*)wmf_iso8601Date; -- (NSString*)capitalizeFirstLetter; +- (NSString*)wmf_stringByRemovingHTML; + +- (NSString*)wmf_randomlyRepeatMaxTimes:(NSUInteger)maxTimes; + +- (NSString*)wmf_stringByReplacingUndrescoresWithSpaces; + +- (NSString*)wmf_stringByReplacingSpacesWithUnderscores; + +- (NSString*)wmf_stringByCapitalizingFirstCharacter; - (BOOL)wmf_containsString:(NSString*)string; + - (BOOL)wmf_caseInsensitiveContainsString:(NSString*)string; + - (BOOL)wmf_containsString:(NSString*)string options:(NSStringCompareOptions)options; + - (BOOL)wmf_isEqualToStringIgnoringCase:(NSString*)string; @end diff --git a/Wikipedia/Categories/NSString+Extras.m b/Wikipedia/Categories/NSString+Extras.m index 2aafb2f..42f90c9 100644 --- a/Wikipedia/Categories/NSString+Extras.m +++ b/Wikipedia/Categories/NSString+Extras.m @@ -14,32 +14,15 @@ return [self substringToIndex:MIN(self.length, index)]; } -- (NSString*)urlEncodedUTF8String { - return (__bridge_transfer id)CFURLCreateStringByAddingPercentEscapes(0, (__bridge CFStringRef)self, 0, - (__bridge CFStringRef)@";/?:@&=$+{}<>,", kCFStringEncodingUTF8); +- (NSString*)wmf_UTF8StringWithPercentEscapes { + return (__bridge_transfer id)CFURLCreateStringByAddingPercentEscapes(0, + (__bridge CFStringRef)self, + 0, + (__bridge CFStringRef)@";/?:@&=$+{}<>,", + kCFStringEncodingUTF8); } -+ (NSString*)sha1:(NSString*)dataFromString isFile:(BOOL)isFile { - NSData* data = nil; - if (isFile) { - data = [NSData dataWithContentsOfFile:dataFromString]; - } else { - const char* cstr = [dataFromString cStringUsingEncoding:NSUTF8StringEncoding]; - data = [NSData dataWithBytes:cstr length:dataFromString.length]; - } - - uint8_t digest[CC_SHA1_DIGEST_LENGTH]; - CC_SHA1(data.bytes, (unsigned int)data.length, digest); - NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; - - for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) { - [output appendFormat:@"%02x", digest[i]]; - } - - return output; -} - -- (NSString*)getUrlWithoutScheme { +- (NSString*)wmf_schemelessURL { NSRange dividerRange = [self rangeOfString:@"://"]; if (dividerRange.location == NSNotFound) { return self; @@ -50,7 +33,7 @@ return path; } -- (NSString*)getImageMimeTypeForExtension { +- (NSString*)wmf_imageMimeTypeForExtension { NSString* lowerCaseSelf = [self lowercaseString]; if ([lowerCaseSelf isEqualToString:@"jpg"]) { return @"image/jpeg"; @@ -67,11 +50,11 @@ return @""; } -- (NSDate*)getDateFromIso8601DateString { +- (NSDate*)wmf_iso8601Date { return [[NSDateFormatter wmf_iso8601Formatter] dateFromString:self]; } -- (NSString*)getStringWithoutHTML { +- (NSString*)wmf_stringByRemovingHTML { // Strips html from string with xpath / hpple. if (!self || (self.length == 0)) { return self; @@ -94,7 +77,7 @@ return result; } -- (NSString*)randomlyRepeatMaxTimes:(NSUInteger)maxTimes; +- (NSString*)wmf_randomlyRepeatMaxTimes:(NSUInteger)maxTimes; { float (^ rnd)() = ^(){ return (float)(rand() % (maxTimes - 1) + 1); @@ -105,15 +88,15 @@ return [NSString stringWithFormat:@"<%@>", [randStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]]; } -- (NSString*)wikiTitleWithoutUnderscores { +- (NSString*)wmf_stringByReplacingUndrescoresWithSpaces { return [self stringByReplacingOccurrencesOfString:@"_" withString:@" "]; } -- (NSString*)wikiTitleWithoutSpaces { +- (NSString*)wmf_stringByReplacingSpacesWithUnderscores { return [self stringByReplacingOccurrencesOfString:@" " withString:@"_"]; } -- (NSString*)capitalizeFirstLetter { +- (NSString*)wmf_stringByCapitalizingFirstCharacter { // Capitalize first character of WikiData description. if (self.length > 1) { NSString* firstChar = [self substringToIndex:1]; diff --git a/Wikipedia/EventLogging/EventLogger.m b/Wikipedia/EventLogging/EventLogger.m index 8a240a5..d9207f9 100644 --- a/Wikipedia/EventLogging/EventLogger.m +++ b/Wikipedia/EventLogging/EventLogger.m @@ -28,7 +28,7 @@ NSData* payloadJsonData = [NSJSONSerialization dataWithJSONObject:payload options:0 error:nil]; NSString* payloadJsonString = [[NSString alloc] initWithData:payloadJsonData encoding:NSUTF8StringEncoding]; //NSLog(@"%@", payloadJsonString); - NSString* encodedPayloadJsonString = [payloadJsonString urlEncodedUTF8String]; + NSString* encodedPayloadJsonString = [payloadJsonString wmf_UTF8StringWithPercentEscapes]; NSString* urlString = [NSString stringWithFormat:@"%@?%@;", LOG_ENDPOINT, encodedPayloadJsonString]; NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]]; [request addValue:[WikipediaAppUtils versionedUserAgent] forHTTPHeaderField:@"User-Agent"]; diff --git a/Wikipedia/Networking/Fetchers/NearbyFetcher.m b/Wikipedia/Networking/Fetchers/NearbyFetcher.m index a2e8c5e..668c5eb 100644 --- a/Wikipedia/Networking/Fetchers/NearbyFetcher.m +++ b/Wikipedia/Networking/Fetchers/NearbyFetcher.m @@ -174,7 +174,7 @@ NSArray* descriptions = terms[@"description"]; if (descriptions && (descriptions.count > 0)) { description = descriptions[0]; - description = [description capitalizeFirstLetter]; + description = [description wmf_stringByCapitalizingFirstCharacter]; } } d[@"description"] = description; diff --git a/Wikipedia/Networking/Fetchers/PageHistoryFetcher.m b/Wikipedia/Networking/Fetchers/PageHistoryFetcher.m index 8569e78..0ea6b90 100644 --- a/Wikipedia/Networking/Fetchers/PageHistoryFetcher.m +++ b/Wikipedia/Networking/Fetchers/PageHistoryFetcher.m @@ -98,7 +98,7 @@ parentSizes[revision[@"revid"]] = revision[@"size"]; NSString* timeStampString = mutableRevision[@"timestamp"]; - NSDate* timeStampDate = [timeStampString getDateFromIso8601DateString]; + NSDate* timeStampDate = [timeStampString wmf_iso8601Date]; NSUInteger distanceInDaysToDate = [timeStampDate distanceInDaysToDate:[NSDate date]]; diff --git a/Wikipedia/Networking/Fetchers/SearchResultFetcher.m b/Wikipedia/Networking/Fetchers/SearchResultFetcher.m index 90fe258..d2625b4 100644 --- a/Wikipedia/Networking/Fetchers/SearchResultFetcher.m +++ b/Wikipedia/Networking/Fetchers/SearchResultFetcher.m @@ -198,7 +198,7 @@ NSString* snippet = prefixPage[@"snippet"] ? prefixPage[@"snippet"] : @""; // Strip HTML and collapse repeating spaces in snippet. if (snippet.length > 0) { - snippet = [snippet getStringWithoutHTML]; + snippet = [snippet wmf_stringByRemovingHTML]; snippet = [self.spaceCollapsingRegex stringByReplacingMatchesInString:snippet options:0 range:NSMakeRange(0, [snippet length]) @@ -206,7 +206,7 @@ } mutablePrefixPage[@"snippet"] = snippet; - mutablePrefixPage[@"title"] = mutablePrefixPage[@"title"] ? [mutablePrefixPage[@"title"] wikiTitleWithoutUnderscores] : @""; + mutablePrefixPage[@"title"] = mutablePrefixPage[@"title"] ? [mutablePrefixPage[@"title"] wmf_stringByReplacingUndrescoresWithSpaces] : @""; mutablePrefixPage[@"searchtype"] = @(self.searchType); mutablePrefixPage[@"searchterm"] = self.searchTerm; @@ -217,7 +217,7 @@ NSArray* descriptions = terms[@"description"]; if (descriptions && (descriptions.count > 0)) { description = descriptions[0]; - description = [description capitalizeFirstLetter]; + description = [description wmf_stringByCapitalizingFirstCharacter]; } [mutablePrefixPage removeObjectForKey:@"terms"]; } diff --git a/Wikipedia/View Controllers/PageHistory/PageHistoryResultCell.m b/Wikipedia/View Controllers/PageHistory/PageHistoryResultCell.m index 2b928f4..04279c5 100644 --- a/Wikipedia/View Controllers/PageHistory/PageHistoryResultCell.m +++ b/Wikipedia/View Controllers/PageHistory/PageHistoryResultCell.m @@ -30,7 +30,7 @@ separator:(BOOL)separator { self.nameLabel.text = name; - self.timeLabel.text = [[NSDateFormatter wmf_shortTimeFormatter] stringFromDate:[time getDateFromIso8601DateString]]; + self.timeLabel.text = [[NSDateFormatter wmf_shortTimeFormatter] stringFromDate:[time wmf_iso8601Date]]; self.deltaLabel.text = [NSString stringWithFormat:@"%@%@", (delta.integerValue > 0) ? @"+" : @"", delta.stringValue]; @@ -54,7 +54,7 @@ [[NSAttributedString alloc] initWithString:icon attributes:iconAttributes]; - self.summaryLabel.text = [summary getStringWithoutHTML]; + self.summaryLabel.text = [summary wmf_stringByRemovingHTML]; self.separatorHeightConstraint.constant = (separator) ? (1.0f / [UIScreen mainScreen].scale) : 0.0f; diff --git a/Wikipedia/View Controllers/SavedPages/NSAttributedString+WMFSavedPagesAttributedStrings.m b/Wikipedia/View Controllers/SavedPages/NSAttributedString+WMFSavedPagesAttributedStrings.m index c87cc1a..d33879b 100644 --- a/Wikipedia/View Controllers/SavedPages/NSAttributedString+WMFSavedPagesAttributedStrings.m +++ b/Wikipedia/View Controllers/SavedPages/NSAttributedString+WMFSavedPagesAttributedStrings.m @@ -26,7 +26,7 @@ + (NSAttributedString*)wmf_attributedStringWithTitle:(NSString*)title description:(NSString*)description language:(NSString*)language { - description = [description capitalizeFirstLetter]; + description = [description wmf_stringByCapitalizingFirstCharacter]; // Shrink super long titles. CGFloat titleSizeMultiplier = 1.0f; diff --git a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m index 29f0c8a..4d53c75 100644 --- a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m +++ b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m @@ -633,7 +633,7 @@ [self saveSearchTermToRecentList]; // Set CurrentArticleTitle so web view knows what to load. - title = [title wikiTitleWithoutUnderscores]; + title = [title wmf_stringByReplacingUndrescoresWithSpaces]; [NAV loadArticleWithTitle:[[SessionSingleton sharedInstance].searchSite titleWithString:title] animated:YES diff --git a/Wikipedia/View Controllers/ShareCard/WMFShareCardViewController.m b/Wikipedia/View Controllers/ShareCard/WMFShareCardViewController.m index 6d14137..73e22bc 100644 --- a/Wikipedia/View Controllers/ShareCard/WMFShareCardViewController.m +++ b/Wikipedia/View Controllers/ShareCard/WMFShareCardViewController.m @@ -53,9 +53,9 @@ self.shareSelectedText.textAlignment = snippetAlignment; NSTextAlignment subtextAlignment = [WikipediaAppUtils rtlSafeAlignment]; - self.shareArticleTitle.text = [article.displaytitle getStringWithoutHTML]; + self.shareArticleTitle.text = [article.displaytitle wmf_stringByRemovingHTML]; self.shareArticleTitle.textAlignment = subtextAlignment; - self.shareArticleDescription.text = [[article.entityDescription getStringWithoutHTML] capitalizeFirstLetter]; + self.shareArticleDescription.text = [[article.entityDescription wmf_stringByRemovingHTML] wmf_stringByCapitalizingFirstCharacter]; self.shareArticleDescription.textAlignment = subtextAlignment; NSData* leadImageData = [article.image.largestCachedVariant asNSData]; diff --git a/Wikipedia/View Controllers/ShareCard/WMFShareOptionsViewController.m b/Wikipedia/View Controllers/ShareCard/WMFShareOptionsViewController.m index 2e07b0e..3e89cfe 100644 --- a/Wikipedia/View Controllers/ShareCard/WMFShareOptionsViewController.m +++ b/Wikipedia/View Controllers/ShareCard/WMFShareOptionsViewController.m @@ -108,7 +108,7 @@ // fall back to something with less treatment if (!heuristicText) { for (MWKSection* section in sections) { - heuristicText = [section.text getStringWithoutHTML]; + heuristicText = [section.text wmf_stringByRemovingHTML]; if (heuristicText) { break; } diff --git a/Wikipedia/View Controllers/WebView/WebViewController.m b/Wikipedia/View Controllers/WebView/WebViewController.m index 2fbf833..30defcd 100644 --- a/Wikipedia/View Controllers/WebView/WebViewController.m +++ b/Wikipedia/View Controllers/WebView/WebViewController.m @@ -1275,7 +1275,7 @@ label.lineBreakMode = NSLineBreakByWordWrapping; label.font = [UIFont systemFontOfSize:30]; label.textAlignment = NSTextAlignmentCenter; - title = [title getStringWithoutHTML]; + title = [title wmf_stringByRemovingHTML]; label.text = title; [views addObject:label]; } @@ -1551,7 +1551,7 @@ } NSString* title = article.displaytitle; - NSString* description = article.entityDescription ? [[article.entityDescription getStringWithoutHTML] capitalizeFirstLetter] : @""; + NSString* description = article.entityDescription ? [[article.entityDescription wmf_stringByRemovingHTML] wmf_stringByCapitalizingFirstCharacter] : @""; BOOL hasImage = article.imageURL ? YES : NO; CGFloat fontMultiplier = [self leadImageGetSizeReductionMultiplierForTitleOfLength:title.length]; diff --git a/Wikipedia/Web Image Interception/URLCache.m b/Wikipedia/Web Image Interception/URLCache.m index 2c5579a..c180ff0 100644 --- a/Wikipedia/Web Image Interception/URLCache.m +++ b/Wikipedia/Web Image Interception/URLCache.m @@ -118,7 +118,7 @@ - (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request { //URLCacheLog(@"Default Cache.db usage:\n\tcurrentDiskUsage: %lu\n\tdiskCapacity = %lu\n\tcurrentMemoryUsage = %lu\n\tmemoryCapacity = %lu", (unsigned long)self.currentDiskUsage, (unsigned long)self.diskCapacity, (unsigned long)self.currentMemoryUsage, (unsigned long)self.memoryCapacity); - if (![self isMIMETypeRerouted:[request.URL.pathExtension getImageMimeTypeForExtension]]) { + if (![self isMIMETypeRerouted:[request.URL.pathExtension wmf_imageMimeTypeForExtension]]) { return [super cachedResponseForRequest:request]; } if (![self isURLRerouted:request.URL]) { -- To view, visit https://gerrit.wikimedia.org/r/208830 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I59a391cd88a8e77ec96219b829b7425bcd908513 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Bgerstle <bgers...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits