0

Remove cr_string* functions from NSString+CrStringDrawing.h

These were added in https://codereview.chromium.org/974913006, last used
in https://codereview.chromium.org/974913006 and do not seem to have
been used since https://codereview.chromium.org/1707603002.

Furthermore, cr_stringByElidingToFitSize uses API that is not available
on tvOS (labelFontSize), so getting rid of it also avoids another tvOS
ifdef in the code.

Bug: 391914246
Change-Id: Iad56c1030deb76f1f7a9e48c914fa9ecad076969
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6308565
Commit-Queue: Raphael Kubo da Costa <kubo@igalia.com>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1425790}
This commit is contained in:
Raphael Kubo da Costa
2025-02-27 09:17:01 -08:00
committed by Chromium LUCI CQ
parent eb1a1dca88
commit 4fe6963039
3 changed files with 0 additions and 61 deletions

@ -50,16 +50,6 @@
// sizeWithAttributes: (crbug.com/364419).
- (CGSize)cr_sizeWithFont:(UIFont*)font;
// If |index| is 0, returns an empty string.
// If |index| is >= than self.length, returns self.
// Otherwise, returns string cut to have |index| characters with an
// ellipsis at the end.
- (NSString*)cr_stringByCuttingToIndex:(NSUInteger)index;
// Returns an elided version of string that fits in |bounds|.
// System font of Label size is used for determining the string drawing size.
- (NSString*)cr_stringByElidingToFitSize:(CGSize)bounds;
@end
#endif // UI_GFX_IOS_NSSTRING_CRSTRINGDRAWING_H_

@ -41,35 +41,4 @@
return CGSizeMake(ceil(size.width), ceil(size.height));
}
- (NSString*)cr_stringByCuttingToIndex:(NSUInteger)index {
if (index == 0)
return @"";
if (index >= self.length) {
return self;
}
return [[self substringToIndex:(index - 1)] stringByAppendingString:@"…"];
}
- (NSString*)cr_stringByElidingToFitSize:(CGSize)bounds {
CGSize sizeForGuess = CGSizeMake(bounds.width, CGFLOAT_MAX);
// Use binary search on the string's length.
size_t lo = 0;
size_t hi = self.length;
size_t guess = 0;
for (guess = (lo + hi) / 2; lo < hi; guess = (lo + hi) / 2) {
NSString* tempString = [self cr_stringByCuttingToIndex:guess];
UIFont* font = [UIFont systemFontOfSize:UIFont.labelFontSize];
CGSize sizeGuess =
[tempString cr_boundingSizeWithSize:sizeForGuess font:font];
if (sizeGuess.height > bounds.height) {
hi = guess - 1;
if (hi < lo)
hi = lo;
} else {
lo = guess + 1;
}
}
return [self cr_stringByCuttingToIndex:lo];
}
@end

@ -150,24 +150,4 @@ TEST_F(NSStringCrStringDrawing, PixelAlignedSizeWithFont) {
}
}
TEST_F(NSStringCrStringDrawing, CutString) {
EXPECT_NSEQ(@"foo", [@"foo" cr_stringByCuttingToIndex:4]);
EXPECT_NSEQ(@"bar", [@"bar" cr_stringByCuttingToIndex:3]);
EXPECT_NSEQ(@"f…", [@"foo" cr_stringByCuttingToIndex:2]);
EXPECT_NSEQ(@"…", [@"bar" cr_stringByCuttingToIndex:1]);
EXPECT_NSEQ(@"", [@"foo" cr_stringByCuttingToIndex:0]);
}
TEST_F(NSStringCrStringDrawing, ElideStringToFitInRect) {
NSString* result =
[@"lorem ipsum dolores" cr_stringByElidingToFitSize:CGSizeZero];
EXPECT_NSEQ(@"", result);
result = [@"lorem ipsum dolores"
cr_stringByElidingToFitSize:CGSizeMake(1000, 1000)];
EXPECT_NSEQ(@"lorem ipsum dolores", result);
result =
[@"lorem ipsum dolores" cr_stringByElidingToFitSize:CGSizeMake(30, 50)];
EXPECT_TRUE([@"lorem ipsum dolores" length] > [result length]);
}
} // namespace