[ios] Fixed crash with highlighted range.

This commit is contained in:
VladiMihaylenko 2016-04-05 18:38:29 +03:00 committed by Alex Zolotarev
parent be1e163758
commit c15e6392e7

View file

@ -1,8 +1,11 @@
#import "MWMSearchCell.h"
#import "Statistics.h"
#import "UIColor+MapsMeColor.h"
#include "Framework.h"
#include "base/logging.hpp"
@interface MWMSearchCell ()
@property (weak, nonatomic) IBOutlet UILabel * titleLabel;
@ -45,9 +48,19 @@
size_t const rangesCount = result.GetHighlightRangesCount();
for (size_t i = 0; i < rangesCount; ++i)
{
pair<uint16_t, uint16_t> const range = result.GetHighlightRange(i);
[attributedTitle addAttributes:selectedTitleAttributes
range:NSMakeRange(range.first, range.second)];
pair<uint16_t, uint16_t> const & range = result.GetHighlightRange(i);
if (range.first + range.second <= title.length)
{
[attributedTitle addAttributes:selectedTitleAttributes range:NSMakeRange(range.first, range.second)];
}
else
{
[Statistics logEvent:@"Incorrect_highlight_range" withParametrs:@{@"range.first" : @(range.first),
@"range.second" : @(range.second),
@"string" : title}];
LOG(LERROR, ("Incorrect range: ", range, " for string: ", result.GetString()));
}
}
self.titleLabel.attributedText = attributedTitle;
[self.titleLabel sizeToFit];