[ios] Refactored NSString categories.

This commit is contained in:
Ilya Grechuhin 2016-03-23 13:03:34 +03:00 committed by Sergey Yershov
parent 63046840e2
commit 65c54349ab
7 changed files with 58 additions and 38 deletions

View file

@ -0,0 +1,13 @@
#include "std/vector.hpp"
@interface NSString (MapsMeSize)
- (CGSize)sizeWithDrawSize:(CGSize)size font:(UIFont *)font;
@end
@interface NSString (MapsMeRanges)
- (vector<NSRange>)rangesOfString:(NSString *)aString;
@end

View file

@ -0,0 +1,34 @@
#import "NSString+Categories.h"
@implementation NSString (MapsMeSize)
- (CGSize)sizeWithDrawSize:(CGSize)drawSize font:(UIFont *)font
{
CGRect rect = [self boundingRectWithSize:drawSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font} context:nil];
return CGRectIntegral(rect).size;
}
@end
@implementation NSString (MapsMeRanges)
- (vector<NSRange>)rangesOfString:(NSString *)aString
{
vector<NSRange> r;
if (self.length == 0)
return r;
NSRange searchRange = {0, self.length};
while (searchRange.location < self.length)
{
searchRange.length = self.length - searchRange.location;
NSRange const foundRange = [self rangeOfString:aString options:NSCaseInsensitiveSearch range:searchRange];
if (foundRange.location == NSNotFound)
break;
searchRange.location = foundRange.location + foundRange.length;
r.push_back(foundRange);
}
return r;
}
@end

View file

@ -72,14 +72,6 @@ static inline CGFloat LengthCGPoint(CGPoint point)
@end
@interface NSString (Size)
- (CGSize)sizeWithDrawSize:(CGSize)size font:(UIFont *)font;
@end
@interface SolidTouchView : UIView
@end

View file

@ -146,16 +146,6 @@
@end
@implementation NSString (Size)
- (CGSize)sizeWithDrawSize:(CGSize)drawSize font:(UIFont *)font
{
CGRect rect = [self boundingRectWithSize:drawSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font} context:nil];
return CGRectIntegral(rect).size;
}
@end
@implementation SolidTouchView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}

View file

@ -9,6 +9,7 @@
#import "MWMPlacePageInfoCell.h"
#import "MWMPlacePageOpeningHoursCell.h"
#import "MWMPlacePageViewManager.h"
#import "NSString+Categories.h"
#import "Statistics.h"
#import "UIColor+MapsMeColor.h"
@ -83,25 +84,6 @@ CGFloat placePageWidth()
return IPAD ? kMaximumWidth : (size.width > size.height ? MIN(kMaximumWidth, size.height) : size.width);
}
vector<NSRange> separatorsLocationInString(NSString * str)
{
vector<NSRange> r;
if (str.length == 0)
return r;
NSRange searchRange = {0, str.length};
while (searchRange.location < str.length)
{
searchRange.length = str.length - searchRange.location;
NSRange const foundRange = [str rangeOfString:@(place_page::Info::kSubtitleSeparator) options:NSCaseInsensitiveSearch range:searchRange];
if (foundRange.location == NSNotFound)
break;
searchRange.location = foundRange.location + foundRange.length;
r.push_back(foundRange);
}
return r;
}
enum class AttributePosition
{
Title,
@ -183,7 +165,7 @@ enum class AttributePosition
else
{
self.titleLabel.text = entity.title;
auto const ranges = separatorsLocationInString(entity.category);
auto const ranges = [entity.category rangesOfString:@(place_page::Info::kSubtitleSeparator)];
if (!ranges.empty())
{
NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:entity.category];

View file

@ -1,3 +1,4 @@
#import "NSString+Categories.h"
#import "ToastView.h"
#import "UIColor+MapsMeColor.h"

View file

@ -12,6 +12,8 @@
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; settings = {ATTRIBUTES = (Required, ); }; };
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; settings = {ATTRIBUTES = (Required, ); }; };
288765080DF74369002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765070DF74369002DB57D /* CoreGraphics.framework */; };
3400A6811CA29D7D003DA0EC /* NSString+Categories.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */; };
3400A6821CA29D7D003DA0EC /* NSString+Categories.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */; };
3401CD671C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3401CD651C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm */; };
3401CD681C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3401CD651C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm */; };
3401CD691C3C03A80028C6F8 /* MWMEditorTextTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3401CD661C3C03A80028C6F8 /* MWMEditorTextTableViewCell.xib */; };
@ -840,6 +842,8 @@
288765070DF74369002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
28A0AB4B0D9B1048005BE974 /* Maps_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = Maps_Prefix.pch; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
29B97316FDCFA39411CA2CEA /* main.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = main.mm; sourceTree = "<group>"; };
3400A67F1CA29D7D003DA0EC /* NSString+Categories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+Categories.h"; path = "Categories/NSString+Categories.h"; sourceTree = "<group>"; };
3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "NSString+Categories.mm"; path = "Categories/NSString+Categories.mm"; sourceTree = "<group>"; };
3401CD641C3C03A80028C6F8 /* MWMEditorTextTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMEditorTextTableViewCell.h; sourceTree = "<group>"; };
3401CD651C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMEditorTextTableViewCell.mm; sourceTree = "<group>"; };
3401CD661C3C03A80028C6F8 /* MWMEditorTextTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMEditorTextTableViewCell.xib; sourceTree = "<group>"; };
@ -2452,6 +2456,8 @@
974726401832306C006B7CB7 /* Categories */ = {
isa = PBXGroup;
children = (
3400A67F1CA29D7D003DA0EC /* NSString+Categories.h */,
3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */,
342AD7701B53D32F00E0B997 /* UIView+RuntimeAttributes.h */,
342AD7711B53D32F00E0B997 /* UIView+RuntimeAttributes.mm */,
342AD76D1B53D30C00E0B997 /* UIButton+RuntimeAttributes.h */,
@ -3691,6 +3697,7 @@
341F99D51C6B1165001C67B8 /* MWMMapDownloaderLargeCountryTableViewCell.mm in Sources */,
347FD86F1C60B2CE002FB65E /* MWMOpeningHoursAllDayTableViewCell.mm in Sources */,
F6ED13541B1643900095C6DE /* MWMDirectionView.mm in Sources */,
3400A6811CA29D7D003DA0EC /* NSString+Categories.mm in Sources */,
F63774EA1B59376F00BCF54D /* MWMRoutingDisclaimerAlert.mm in Sources */,
34E273211C737A4100463965 /* MWMMigrationViewController.mm in Sources */,
F64F19A31AB81A00006EAF7E /* MWMDownloadTransitMapAlert.mm in Sources */,
@ -3906,6 +3913,7 @@
347FD8701C60B2CE002FB65E /* MWMOpeningHoursAllDayTableViewCell.mm in Sources */,
6741AA1F1BF340DE002C974C /* MWMSearchBookmarksCell.mm in Sources */,
34E273221C737A4100463965 /* MWMMigrationViewController.mm in Sources */,
3400A6821CA29D7D003DA0EC /* NSString+Categories.mm in Sources */,
341F99E91C6B119E001C67B8 /* MWMMapDownloaderDefaultDataSource.mm in Sources */,
6741AA221BF340DE002C974C /* MWMNavigationView.mm in Sources */,
6741AA231BF340DE002C974C /* UIFont+MapsMeFonts.mm in Sources */,