Add reset button for each preference in gesture config UI
[chromium-blink-merge.git] / base / i18n / bidi_line_iterator.cc
blobe81a36b77a5b2e6f7ad5e72c6942edeef44b1ff4
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"
9 namespace base {
10 namespace i18n {
12 BiDiLineIterator::BiDiLineIterator() : bidi_(NULL) {
15 BiDiLineIterator::~BiDiLineIterator() {
16 if (bidi_) {
17 ubidi_close(bidi_);
18 bidi_ = NULL;
22 bool BiDiLineIterator::Open(const string16& text,
23 bool right_to_left,
24 bool url) {
25 DCHECK(!bidi_);
26 UErrorCode error = U_ZERO_ERROR;
27 bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error);
28 if (U_FAILURE(error))
29 return false;
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,
34 NULL, &error);
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,
46 int* start,
47 int* length) {
48 DCHECK(bidi_ != NULL);
49 return ubidi_getVisualRun(bidi_, index, start, length);
52 void BiDiLineIterator::GetLogicalRun(int start,
53 int* end,
54 UBiDiLevel* level) {
55 DCHECK(bidi_ != NULL);
56 ubidi_getLogicalRun(bidi_, start, end, level);
59 } // namespace i18n
60 } // namespace base