diff --git a/iphone/Maps/Categories/NSString+Categories.h b/iphone/Maps/Categories/NSString+Categories.h new file mode 100644 index 0000000000..5a3cf58c5f --- /dev/null +++ b/iphone/Maps/Categories/NSString+Categories.h @@ -0,0 +1,13 @@ +#include "std/vector.hpp" + +@interface NSString (MapsMeSize) + +- (CGSize)sizeWithDrawSize:(CGSize)size font:(UIFont *)font; + +@end + +@interface NSString (MapsMeRanges) + +- (vector)rangesOfString:(NSString *)aString; + +@end \ No newline at end of file diff --git a/iphone/Maps/Categories/NSString+Categories.mm b/iphone/Maps/Categories/NSString+Categories.mm new file mode 100644 index 0000000000..b78aa1f485 --- /dev/null +++ b/iphone/Maps/Categories/NSString+Categories.mm @@ -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)rangesOfString:(NSString *)aString +{ + vector 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 \ No newline at end of file diff --git a/iphone/Maps/Categories/UIKitCategories.h b/iphone/Maps/Categories/UIKitCategories.h index d0603f2a96..05b83e8062 100644 --- a/iphone/Maps/Categories/UIKitCategories.h +++ b/iphone/Maps/Categories/UIKitCategories.h @@ -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 diff --git a/iphone/Maps/Categories/UIKitCategories.mm b/iphone/Maps/Categories/UIKitCategories.mm index c9c5cc0fa8..d4d80b9233 100644 --- a/iphone/Maps/Categories/UIKitCategories.mm +++ b/iphone/Maps/Categories/UIKitCategories.mm @@ -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 {} diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.mm b/iphone/Maps/Classes/MWMBasePlacePageView.mm index ffc7e92e66..720d137523 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.mm +++ b/iphone/Maps/Classes/MWMBasePlacePageView.mm @@ -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 separatorsLocationInString(NSString * str) -{ - vector 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]; diff --git a/iphone/Maps/Classes/ToastView.mm b/iphone/Maps/Classes/ToastView.mm index a2178c8610..d883618afe 100644 --- a/iphone/Maps/Classes/ToastView.mm +++ b/iphone/Maps/Classes/ToastView.mm @@ -1,3 +1,4 @@ +#import "NSString+Categories.h" #import "ToastView.h" #import "UIColor+MapsMeColor.h" diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 8adbe9851e..6aa6cd4e68 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -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 = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 29B97316FDCFA39411CA2CEA /* main.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = main.mm; sourceTree = ""; }; + 3400A67F1CA29D7D003DA0EC /* NSString+Categories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+Categories.h"; path = "Categories/NSString+Categories.h"; sourceTree = ""; }; + 3400A6801CA29D7D003DA0EC /* NSString+Categories.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "NSString+Categories.mm"; path = "Categories/NSString+Categories.mm"; sourceTree = ""; }; 3401CD641C3C03A80028C6F8 /* MWMEditorTextTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMEditorTextTableViewCell.h; sourceTree = ""; }; 3401CD651C3C03A80028C6F8 /* MWMEditorTextTableViewCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMEditorTextTableViewCell.mm; sourceTree = ""; }; 3401CD661C3C03A80028C6F8 /* MWMEditorTextTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMEditorTextTableViewCell.xib; sourceTree = ""; }; @@ -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 */,