session-ios/SignalUtilitiesKit/Utilities/NSAttributedString+OWS.m

40 lines
1,022 B
Mathematica
Raw Permalink Normal View History

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