2017-09-15 21:28:44 +02:00
|
|
|
//
|
2018-06-29 23:00:22 +02:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-09-15 21:28:44 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "NSAttributedString+OWS.h"
|
|
|
|
#import "UIView+OWS.h"
|
2020-11-11 01:50:01 +01:00
|
|
|
#import <SignalUtilitiesKit/AppContext.h>
|
2017-09-15 21:28:44 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation NSAttributedString (OWS)
|
|
|
|
|
2018-07-23 19:47:03 +02:00
|
|
|
- (NSAttributedString *)rtlSafeAppend:(NSString *)text attributes:(NSDictionary *)attributes
|
2017-10-11 20:45:02 +02:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(text);
|
|
|
|
OWSAssertDebug(attributes);
|
2017-10-11 20:45:02 +02:00
|
|
|
|
|
|
|
NSAttributedString *substring = [[NSAttributedString alloc] initWithString:text attributes:attributes];
|
2018-06-29 23:00:22 +02:00
|
|
|
return [self rtlSafeAppend:substring];
|
2017-10-11 20:45:02 +02:00
|
|
|
}
|
|
|
|
|
2018-06-29 23:00:22 +02:00
|
|
|
- (NSAttributedString *)rtlSafeAppend:(NSAttributedString *)string
|
2017-09-15 21:28:44 +02:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(string);
|
2017-09-15 21:28:44 +02:00
|
|
|
|
|
|
|
NSMutableAttributedString *result = [NSMutableAttributedString new];
|
2018-06-29 23:00:22 +02:00
|
|
|
if (CurrentAppContext().isRTL) {
|
2017-09-15 21:28:44 +02:00
|
|
|
[result appendAttributedString:string];
|
|
|
|
[result appendAttributedString:self];
|
|
|
|
} else {
|
|
|
|
[result appendAttributedString:self];
|
|
|
|
[result appendAttributedString:string];
|
|
|
|
}
|
|
|
|
return [result copy];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|