intl/lwbrk/src/nsCarbonBreaker.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/lwbrk/src/nsCarbonBreaker.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <CoreFoundation/CoreFoundation.h>
    1.10 +#include <stdint.h>
    1.11 +#include "nsDebug.h"
    1.12 +#include "nscore.h"
    1.13 +
    1.14 +void
    1.15 +NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength,
    1.16 +                        uint8_t* aBreakBefore)
    1.17 +{
    1.18 +  NS_ASSERTION(aText, "aText shouldn't be null");
    1.19 +
    1.20 +  memset(aBreakBefore, 0, aLength * sizeof(uint8_t));
    1.21 +
    1.22 +  CFStringRef str = ::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(aText), aLength, kCFAllocatorNull);
    1.23 +  if (!str) {
    1.24 +    return;
    1.25 +  }
    1.26 +
    1.27 +  CFStringTokenizerRef st = ::CFStringTokenizerCreate(kCFAllocatorDefault, str,
    1.28 +                                                      ::CFRangeMake(0, aLength),
    1.29 +                                                      kCFStringTokenizerUnitLineBreak,
    1.30 +                                                      nullptr);
    1.31 +  if (!st) {
    1.32 +    ::CFRelease(str);
    1.33 +    return;
    1.34 +  }
    1.35 +
    1.36 +  CFStringTokenizerTokenType tt = ::CFStringTokenizerAdvanceToNextToken(st);
    1.37 +  while (tt != kCFStringTokenizerTokenNone) {
    1.38 +    CFRange r = ::CFStringTokenizerGetCurrentTokenRange(st);
    1.39 +    if (r.location != 0) { // Ignore leading edge
    1.40 +      aBreakBefore[r.location] = true;
    1.41 +    }
    1.42 +    tt = CFStringTokenizerAdvanceToNextToken(st);
    1.43 +  }
    1.44 +
    1.45 +  ::CFRelease(st);
    1.46 +  ::CFRelease(str);
    1.47 +}

mercurial