Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include <CoreFoundation/CoreFoundation.h> |
michael@0 | 7 | #include <stdint.h> |
michael@0 | 8 | #include "nsDebug.h" |
michael@0 | 9 | #include "nscore.h" |
michael@0 | 10 | |
michael@0 | 11 | void |
michael@0 | 12 | NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength, |
michael@0 | 13 | uint8_t* aBreakBefore) |
michael@0 | 14 | { |
michael@0 | 15 | NS_ASSERTION(aText, "aText shouldn't be null"); |
michael@0 | 16 | |
michael@0 | 17 | memset(aBreakBefore, 0, aLength * sizeof(uint8_t)); |
michael@0 | 18 | |
michael@0 | 19 | CFStringRef str = ::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(aText), aLength, kCFAllocatorNull); |
michael@0 | 20 | if (!str) { |
michael@0 | 21 | return; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | CFStringTokenizerRef st = ::CFStringTokenizerCreate(kCFAllocatorDefault, str, |
michael@0 | 25 | ::CFRangeMake(0, aLength), |
michael@0 | 26 | kCFStringTokenizerUnitLineBreak, |
michael@0 | 27 | nullptr); |
michael@0 | 28 | if (!st) { |
michael@0 | 29 | ::CFRelease(str); |
michael@0 | 30 | return; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | CFStringTokenizerTokenType tt = ::CFStringTokenizerAdvanceToNextToken(st); |
michael@0 | 34 | while (tt != kCFStringTokenizerTokenNone) { |
michael@0 | 35 | CFRange r = ::CFStringTokenizerGetCurrentTokenRange(st); |
michael@0 | 36 | if (r.location != 0) { // Ignore leading edge |
michael@0 | 37 | aBreakBefore[r.location] = true; |
michael@0 | 38 | } |
michael@0 | 39 | tt = CFStringTokenizerAdvanceToNextToken(st); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | ::CFRelease(st); |
michael@0 | 43 | ::CFRelease(str); |
michael@0 | 44 | } |