/src/mozilla-central/layout/base/nsBidi.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "nsBidi.h" |
8 | | |
9 | | nsresult |
10 | | nsBidi::CountRuns(int32_t* aRunCount) |
11 | 0 | { |
12 | 0 | UErrorCode errorCode = U_ZERO_ERROR; |
13 | 0 | *aRunCount = ubidi_countRuns(mBiDi, &errorCode); |
14 | 0 | if (U_SUCCESS(errorCode)) { |
15 | 0 | mLength = ubidi_getProcessedLength(mBiDi); |
16 | 0 | mLevels = mLength > 0 ? ubidi_getLevels(mBiDi, &errorCode) : nullptr; |
17 | 0 | } |
18 | 0 | return ICUUtils::UErrorToNsResult(errorCode); |
19 | 0 | } |
20 | | |
21 | | void |
22 | | nsBidi::GetLogicalRun(int32_t aLogicalStart, |
23 | | int32_t* aLogicalLimit, nsBidiLevel* aLevel) |
24 | 0 | { |
25 | 0 | MOZ_ASSERT(mLevels, "CountRuns hasn't been run?"); |
26 | 0 | MOZ_RELEASE_ASSERT(aLogicalStart < mLength, "Out of bound"); |
27 | 0 | // This function implements an alternative approach to get logical |
28 | 0 | // run that is based on levels of characters, which would avoid O(n^2) |
29 | 0 | // performance issue when used in a loop over runs. |
30 | 0 | // Per comment in ubidi_getLogicalRun, that function doesn't use this |
31 | 0 | // approach because levels have special interpretation when reordering |
32 | 0 | // mode is UBIDI_REORDER_RUNS_ONLY. Since we don't use this mode in |
33 | 0 | // Gecko, it should be safe to just use levels for this function. |
34 | 0 | MOZ_ASSERT(ubidi_getReorderingMode(mBiDi) != UBIDI_REORDER_RUNS_ONLY, |
35 | 0 | "Don't support UBIDI_REORDER_RUNS_ONLY mode"); |
36 | 0 |
|
37 | 0 | nsBidiLevel level = mLevels[aLogicalStart]; |
38 | 0 | int32_t limit; |
39 | 0 | for (limit = aLogicalStart + 1; limit < mLength; limit++) { |
40 | 0 | if (mLevels[limit] != level) { |
41 | 0 | break; |
42 | 0 | } |
43 | 0 | } |
44 | 0 | *aLogicalLimit = limit; |
45 | 0 | *aLevel = level; |
46 | 0 | } |