1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/i18n/bidi_line_iterator.h"
7 #include "base/logging.h"
12 BiDiLineIterator::BiDiLineIterator() : bidi_(NULL
) {
15 BiDiLineIterator::~BiDiLineIterator() {
22 bool BiDiLineIterator::Open(const string16
& text
,
26 UErrorCode error
= U_ZERO_ERROR
;
27 bidi_
= ubidi_openSized(static_cast<int>(text
.length()), 0, &error
);
30 if (right_to_left
&& url
)
31 ubidi_setReorderingMode(bidi_
, UBIDI_REORDER_RUNS_ONLY
);
32 ubidi_setPara(bidi_
, text
.data(), static_cast<int>(text
.length()),
33 right_to_left
? UBIDI_DEFAULT_RTL
: UBIDI_DEFAULT_LTR
,
35 return (U_SUCCESS(error
) == TRUE
);
38 int BiDiLineIterator::CountRuns() {
39 DCHECK(bidi_
!= NULL
);
40 UErrorCode error
= U_ZERO_ERROR
;
41 const int runs
= ubidi_countRuns(bidi_
, &error
);
42 return U_SUCCESS(error
) ? runs
: 0;
45 UBiDiDirection
BiDiLineIterator::GetVisualRun(int index
,
48 DCHECK(bidi_
!= NULL
);
49 return ubidi_getVisualRun(bidi_
, index
, start
, length
);
52 void BiDiLineIterator::GetLogicalRun(int start
,
55 DCHECK(bidi_
!= NULL
);
56 ubidi_getLogicalRun(bidi_
, start
, end
, level
);