diff --git a/Frameworks/CoreText/CTLine.mm b/Frameworks/CoreText/CTLine.mm index b98b875e0f..2068f6e64e 100644 --- a/Frameworks/CoreText/CTLine.mm +++ b/Frameworks/CoreText/CTLine.mm @@ -16,16 +16,46 @@ #import #import -#import "NSStringInternal.h" #import "CoreTextInternal.h" #import "CGContextInternal.h" #import "DWriteWrapper_CoreText.h" #import +#import +#include #import #import +#import #import +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); + + if (length < 2) { + return CFStringCreateCopy(kCFAllocatorDefault, string); + } + + CFIndex bufLen = (usedBufLen / sizeof(UniChar)); + std::unique_ptr characters(new UniChar[bufLen + 1]); + characters[bufLen] = L'\0'; + + CFStringGetBytes( + string, CFRangeMake(0, length), kCFStringEncodingUTF16, 0, false, reinterpret_cast(characters.get()), usedBufLen, nullptr); + + wchar_t* result = _wcsrev(reinterpret_cast(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(__CTCreateReversedString(static_cast(runString))); + NSAttributedString* string = + [[NSAttributedString alloc] initWithString:static_cast(reverse.get()) attributes:(NSDictionary*)attribs]; [ret insertAttributedString:string atIndex:0]; [string release]; } else if (truncationType == kCTLineTruncationEnd) { diff --git a/Frameworks/CoreText/CTUtilities.mm b/Frameworks/CoreText/CTUtilities.mm index b5ce11e246..2d7fb5392c 100644 --- a/Frameworks/CoreText/CTUtilities.mm +++ b/Frameworks/CoreText/CTUtilities.mm @@ -1,6 +1,6 @@ //****************************************************************************** // -// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // // This code is licensed under the MIT License (MIT). // @@ -23,4 +23,4 @@ */ uint32_t CTGetCoreTextVersion() { return kCTVersionNumber10_5; -} +} \ No newline at end of file diff --git a/Frameworks/Foundation/NSString.mm b/Frameworks/Foundation/NSString.mm index a7d6f0c8ef..7b64e73fc5 100644 --- a/Frameworks/Foundation/NSString.mm +++ b/Frameworks/Foundation/NSString.mm @@ -1,6 +1,6 @@ //****************************************************************************** // -// Copyright (c) 2015 Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // // This code is licensed under the MIT License (MIT). // @@ -2200,25 +2200,4 @@ - (int)_versionStringCompare:(NSString*)compStrAddr { return result; } - -- (NSString*)_reverseString { - NSUInteger length = [self length]; - if (length < 2) { - return self; - } - - std::vector characters(length + 1); - [self getCString:&characters[0] maxLength:length]; - for (int i = 0; i < length / 2; ++i) { - char character = characters[length - i - 1]; - characters[length - i - 1] = characters[i]; - characters[i] = character; - } - characters[length] = '\0'; - - NSString* ret = [[[NSString alloc] initWithCString:&characters[0]] autorelease]; - - return ret; -} - @end diff --git a/Frameworks/include/CFFoundationInternal.h b/Frameworks/include/CFFoundationInternal.h index 6d8c4fc835..ee6c711ed3 100644 --- a/Frameworks/include/CFFoundationInternal.h +++ b/Frameworks/include/CFFoundationInternal.h @@ -1,6 +1,6 @@ //****************************************************************************** // -// Copyright (c) 2015 Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // // This code is licensed under the MIT License (MIT). // diff --git a/Frameworks/include/NSStringInternal.h b/Frameworks/include/NSStringInternal.h index bb615df6f8..84e85aa9fd 100644 --- a/Frameworks/include/NSStringInternal.h +++ b/Frameworks/include/NSStringInternal.h @@ -1,6 +1,6 @@ //****************************************************************************** // -// Copyright (c) 2015 Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // // This code is licensed under the MIT License (MIT). // @@ -22,7 +22,6 @@ @interface NSString () - (int)_versionStringCompare:(NSString*)compStrAddr; -- (NSString*)_reverseString; @end @interface NSString (WinObjCHSTRINGAdditions) diff --git a/build/Tests/UnitTests/Foundation.WindowsOnly/Foundation.WindowsOnly.UnitTests.vcxproj b/build/Tests/UnitTests/Foundation.WindowsOnly/Foundation.WindowsOnly.UnitTests.vcxproj index bb5f17f0cf..1cb20fa348 100644 --- a/build/Tests/UnitTests/Foundation.WindowsOnly/Foundation.WindowsOnly.UnitTests.vcxproj +++ b/build/Tests/UnitTests/Foundation.WindowsOnly/Foundation.WindowsOnly.UnitTests.vcxproj @@ -237,7 +237,6 @@ - diff --git a/include/CoreText/CTUtilities.h b/include/CoreText/CTUtilities.h index f43ab0d7bb..f0831a85ef 100644 --- a/include/CoreText/CTUtilities.h +++ b/include/CoreText/CTUtilities.h @@ -1,6 +1,6 @@ //****************************************************************************** // -// Copyright (c) 2016 Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // // This code is licensed under the MIT License (MIT). // @@ -16,8 +16,7 @@ #pragma once #import - -#include +#import CORETEXT_EXPORT uint32_t CTGetCoreTextVersion(); @@ -25,4 +24,4 @@ CORETEXT_EXPORT uint32_t CTGetCoreTextVersion(); #define kCTVersionNumber10_5_2 0x00020001 #define kCTVersionNumber10_5_3 0x00020002 #define kCTVersionNumber10_5_5 0x00020003 -#define kCTVersionNumber10_6 0x00030000 +#define kCTVersionNumber10_6 0x00030000 \ No newline at end of file diff --git a/tests/unittests/Foundation/WindowsOnly/NSStringInternalTests.mm b/tests/unittests/Foundation/WindowsOnly/NSStringInternalTests.mm deleted file mode 100644 index b60500675a..0000000000 --- a/tests/unittests/Foundation/WindowsOnly/NSStringInternalTests.mm +++ /dev/null @@ -1,45 +0,0 @@ -//****************************************************************************** -// -// Copyright (c) 2015 Microsoft Corporation. All rights reserved. -// -// This code is licensed under the MIT License (MIT). -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -//****************************************************************************** - -// Windows-only: -// NSString _reverseString - -#import -#import -#import "NSStringInternal.h" - -TEST(Foundation, ReverseString) { - NSString* str = @"hello"; - NSString* reverse = [str _reverseString]; - ASSERT_TRUE_MSG(reverse != nil, "FAILED: String should not be nil"); - - NSString* expectedValue = @"olleh"; - ASSERT_TRUE_MSG([reverse isEqualToString:expectedValue], "FAILED: ReverseString Invalid output"); - - str = @""; - reverse = [str _reverseString]; - ASSERT_TRUE_MSG(reverse != nil, "FAILED: String should not be nil"); - - expectedValue = @""; - ASSERT_TRUE_MSG([reverse isEqualToString:expectedValue], "FAILED: ReverseString Invalid output"); - - str = @"e"; - reverse = [str _reverseString]; - ASSERT_TRUE_MSG(reverse != nil, "FAILED: String should not be nil"); - - expectedValue = @"e"; - ASSERT_TRUE_MSG([reverse isEqualToString:expectedValue], "FAILED: ReverseString Invalid output"); -} \ No newline at end of file