| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "app/bidi_line_iterator.h" | 5 #include "base/i18n/bidi_line_iterator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string16.h" | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 namespace base { |
| 10 namespace i18n { |
| 11 |
| 12 BiDiLineIterator::BiDiLineIterator() : bidi_(NULL) { |
| 13 } |
| 10 | 14 |
| 11 BiDiLineIterator::~BiDiLineIterator() { | 15 BiDiLineIterator::~BiDiLineIterator() { |
| 12 if (bidi_) { | 16 if (bidi_) { |
| 13 ubidi_close(bidi_); | 17 ubidi_close(bidi_); |
| 14 bidi_ = NULL; | 18 bidi_ = NULL; |
| 15 } | 19 } |
| 16 } | 20 } |
| 17 | 21 |
| 18 UBool BiDiLineIterator::Open(const string16& text, | 22 bool BiDiLineIterator::Open(const string16& text, |
| 19 bool right_to_left, | 23 bool right_to_left, |
| 20 bool url) { | 24 bool url) { |
| 21 DCHECK(bidi_ == NULL); | 25 DCHECK(bidi_ == NULL); |
| 22 UErrorCode error = U_ZERO_ERROR; | 26 UErrorCode error = U_ZERO_ERROR; |
| 23 bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error); | 27 bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error); |
| 24 if (U_FAILURE(error)) | 28 if (U_FAILURE(error)) |
| 25 return false; | 29 return false; |
| 26 if (right_to_left && url) | 30 if (right_to_left && url) |
| 27 ubidi_setReorderingMode(bidi_, UBIDI_REORDER_RUNS_ONLY); | 31 ubidi_setReorderingMode(bidi_, UBIDI_REORDER_RUNS_ONLY); |
| 28 ubidi_setPara(bidi_, text.data(), static_cast<int>(text.length()), | 32 ubidi_setPara(bidi_, text.data(), static_cast<int>(text.length()), |
| 29 right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, | 33 right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, |
| 30 NULL, &error); | 34 NULL, &error); |
| 31 return U_SUCCESS(error); | 35 return U_SUCCESS(error) ? true : false; |
| 32 } | 36 } |
| 33 | 37 |
| 34 int BiDiLineIterator::CountRuns() { | 38 int BiDiLineIterator::CountRuns() { |
| 35 DCHECK(bidi_ != NULL); | 39 DCHECK(bidi_ != NULL); |
| 36 UErrorCode error = U_ZERO_ERROR; | 40 UErrorCode error = U_ZERO_ERROR; |
| 37 const int runs = ubidi_countRuns(bidi_, &error); | 41 const int runs = ubidi_countRuns(bidi_, &error); |
| 38 return U_SUCCESS(error) ? runs : 0; | 42 return U_SUCCESS(error) ? runs : 0; |
| 39 } | 43 } |
| 40 | 44 |
| 41 UBiDiDirection BiDiLineIterator::GetVisualRun(int index, | 45 UBiDiDirection BiDiLineIterator::GetVisualRun(int index, |
| 42 int* start, | 46 int* start, |
| 43 int* length) { | 47 int* length) { |
| 44 DCHECK(bidi_ != NULL); | 48 DCHECK(bidi_ != NULL); |
| 45 return ubidi_getVisualRun(bidi_, index, start, length); | 49 return ubidi_getVisualRun(bidi_, index, start, length); |
| 46 } | 50 } |
| 47 | 51 |
| 48 void BiDiLineIterator::GetLogicalRun(int start, | 52 void BiDiLineIterator::GetLogicalRun(int start, |
| 49 int* end, | 53 int* end, |
| 50 UBiDiLevel* level) { | 54 UBiDiLevel* level) { |
| 51 DCHECK(bidi_ != NULL); | 55 DCHECK(bidi_ != NULL); |
| 52 ubidi_getLogicalRun(bidi_, start, end, level); | 56 ubidi_getLogicalRun(bidi_, start, end, level); |
| 53 } | 57 } |
| 58 |
| 59 } // namespace i18n |
| 60 } // namespace base |
| OLD | NEW |