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. 4 5 #ifndef BASE_I18N_BIDI_LINE_ITERATOR_H_ 6 #define BASE_I18N_BIDI_LINE_ITERATOR_H_ 7 8 #include "base/i18n/base_i18n_export.h" 9 #include "base/i18n/rtl.h" 10 #include "base/macros.h" 11 #include "base/strings/string16.h" 12 #include "third_party/icu/source/common/unicode/ubidi.h" 13 #include "third_party/icu/source/common/unicode/uchar.h" 14 15 namespace base { 16 namespace i18n { 17 18 // A simple wrapper class for the bidirectional iterator of ICU. 19 // This class uses the bidirectional iterator of ICU to split a line of 20 // bidirectional texts into visual runs in its display order. 21 class BASE_I18N_EXPORT BiDiLineIterator { 22 public: 23 // Specifies some alternative iteration behavior. 24 enum class CustomBehavior { 25 // No special behavior. 26 NONE, 27 // Treat URL delimiter characters as strong LTR. This is a special treatment 28 // for URLs that purposefully violates the URL Standard, as an experiment. 29 // It should only be used behind a flag. 30 AS_URL 31 }; 32 33 BiDiLineIterator(); 34 ~BiDiLineIterator(); 35 36 // Initializes the bidirectional iterator with the specified text. Returns 37 // whether initialization succeeded. 38 bool Open(const string16& text, 39 TextDirection direction, 40 CustomBehavior behavior); 41 42 // Returns the number of visual runs in the text, or zero on error. 43 int CountRuns() const; 44 45 // Gets the logical offset, length, and direction of the specified visual run. 46 UBiDiDirection GetVisualRun(int index, int* start, int* length) const; 47 48 // Given a start position, figure out where the run ends (and the BiDiLevel). 49 void GetLogicalRun(int start, int* end, UBiDiLevel* level) const; 50 51 private: 52 UBiDi* bidi_; 53 54 DISALLOW_COPY_AND_ASSIGN(BiDiLineIterator); 55 }; 56 57 } // namespace i18n 58 } // namespace base 59 60 #endif // BASE_I18N_BIDI_LINE_ITERATOR_H_ 61