-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-Implementation of reverse string via CFString #2479
Changes from all commits
4e72b6b
3bf160d
c98940e
afcfbad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,46 @@ | |
|
||
#import <CoreText/CTLine.h> | ||
#import <StubReturn.h> | ||
#import "NSStringInternal.h" | ||
#import "CoreTextInternal.h" | ||
#import "CGContextInternal.h" | ||
#import "DWriteWrapper_CoreText.h" | ||
#import <CoreText/CTTypesetter.h> | ||
#import <CoreFoundation/CFString.h> | ||
|
||
#include <memory> | ||
#import <algorithm> | ||
#import <numeric> | ||
#import <cwchar> | ||
#import <vector> | ||
|
||
static CFStringRef __CTCreateReversedString(CFStringRef string) { | ||
if (string == nullptr) { | ||
return nullptr; | ||
} | ||
|
||
CFIndex length = CFStringGetLength(string); | ||
CFIndex usedBufLen; | ||
CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingUTF16, 0, false, nullptr, length, &usedBufLen); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems kind of expensive for this purpose (unless CFStringGetBytes has a fastpath here?) I wonder if CFStringGetMaximumSizeForEncoding() would be faster/would still work? #ByDesign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it does take a faster way than if you provide a buffer. |
||
|
||
if (length < 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: move this above CFStringGetBytes call |
||
return CFStringCreateCopy(kCFAllocatorDefault, string); | ||
} | ||
|
||
CFIndex bufLen = (usedBufLen / sizeof(UniChar)); | ||
std::unique_ptr<UniChar[]> characters(new UniChar[bufLen + 1]); | ||
characters[bufLen] = L'\0'; | ||
|
||
CFStringGetBytes( | ||
string, CFRangeMake(0, length), kCFStringEncodingUTF16, 0, false, reinterpret_cast<UInt8*>(characters.get()), usedBufLen, nullptr); | ||
|
||
wchar_t* result = _wcsrev(reinterpret_cast<wchar_t*>(characters.get())); | ||
if (result == nullptr) { | ||
return nullptr; | ||
} | ||
|
||
return CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, characters.release(), bufLen, nullptr); | ||
} | ||
|
||
static NSMutableAttributedString* _getTruncatedStringFromSourceLine(CTLineRef line, | ||
CTLineTruncationType truncationType, | ||
double widthToExtract); | ||
|
@@ -187,8 +217,9 @@ CTLineRef CTLineCreateTruncatedLine(CTLineRef sourceLine, double width, CTLineTr | |
CFDictionaryRef attribs = CTRunGetAttributes(run); | ||
|
||
if (truncationType == kCTLineTruncationStart) { | ||
NSString* reverse = [runString _reverseString]; | ||
NSAttributedString* string = [[NSAttributedString alloc] initWithString:reverse attributes:(NSDictionary*)attribs]; | ||
auto reverse = woc::MakeStrongCF<CFStringRef>(__CTCreateReversedString(static_cast<CFStringRef>(runString))); | ||
NSAttributedString* string = | ||
[[NSAttributedString alloc] initWithString:static_cast<NSString*>(reverse.get()) attributes:(NSDictionary*)attribs]; | ||
[ret insertAttributedString:string atIndex:0]; | ||
[string release]; | ||
} else if (truncationType == kCTLineTruncationEnd) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//****************************************************************************** | ||
// | ||
// Copyright (c) 2015 Microsoft Corporation. All rights reserved. | ||
// Copyright (c) Microsoft. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These clean-ups, though nice, seem unrelated to this PR. Just revert these files? |
||
// | ||
// This code is licensed under the MIT License (MIT). | ||
// | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this change being tested? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnitTests
In reply to: 111007038 [](ancestors = 111007038)