Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: Source/core/platform/text/LineBreakIteratorPoolICU.h

Issue 23618052: TextBreakIterator should use the C++ icu API instead of the C one (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2011 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 30 matching lines...) Expand all
41 WTF_MAKE_NONCOPYABLE(LineBreakIteratorPool); 41 WTF_MAKE_NONCOPYABLE(LineBreakIteratorPool);
42 public: 42 public:
43 static LineBreakIteratorPool& sharedPool() 43 static LineBreakIteratorPool& sharedPool()
44 { 44 {
45 static WTF::ThreadSpecific<LineBreakIteratorPool>* pool = new WTF::Threa dSpecific<LineBreakIteratorPool>; 45 static WTF::ThreadSpecific<LineBreakIteratorPool>* pool = new WTF::Threa dSpecific<LineBreakIteratorPool>;
46 return **pool; 46 return **pool;
47 } 47 }
48 48
49 static PassOwnPtr<LineBreakIteratorPool> create() { return adoptPtr(new Line BreakIteratorPool); } 49 static PassOwnPtr<LineBreakIteratorPool> create() { return adoptPtr(new Line BreakIteratorPool); }
50 50
51 UBreakIterator* take(const AtomicString& locale) 51 icu::BreakIterator* take(const AtomicString& locale)
52 { 52 {
53 UBreakIterator* iterator = 0; 53 icu::BreakIterator* iterator = 0;
54 for (size_t i = 0; i < m_pool.size(); ++i) { 54 for (size_t i = 0; i < m_pool.size(); ++i) {
55 if (m_pool[i].first == locale) { 55 if (m_pool[i].first == locale) {
56 iterator = m_pool[i].second; 56 iterator = m_pool[i].second;
57 m_pool.remove(i); 57 m_pool.remove(i);
58 break; 58 break;
59 } 59 }
60 } 60 }
61 61
62 if (!iterator) { 62 if (!iterator) {
63 UErrorCode openStatus = U_ZERO_ERROR; 63 UErrorCode openStatus = U_ZERO_ERROR;
64 bool localeIsEmpty = locale.isEmpty(); 64 bool localeIsEmpty = locale.isEmpty();
65 iterator = ubrk_open(UBRK_LINE, localeIsEmpty ? currentTextBreakLoca leID() : locale.string().utf8().data(), 0, 0, &openStatus); 65 iterator = icu::BreakIterator::createLineInstance(localeIsEmpty ? cu rrentTextBreakLocaleID() : locale.string().utf8().data(), openStatus);
66 // locale comes from a web page and it can be invalid, leading ICU 66 // locale comes from a web page and it can be invalid, leading ICU
67 // to fail, in which case we fall back to the default locale. 67 // to fail, in which case we fall back to the default locale.
68 if (!localeIsEmpty && U_FAILURE(openStatus)) { 68 if (!localeIsEmpty && U_FAILURE(openStatus)) {
69 openStatus = U_ZERO_ERROR; 69 openStatus = U_ZERO_ERROR;
70 iterator = ubrk_open(UBRK_LINE, currentTextBreakLocaleID(), 0, 0 , &openStatus); 70 iterator = icu::BreakIterator::createLineInstance(currentTextBre akLocaleID(), openStatus);
71 } 71 }
72 72
73 if (U_FAILURE(openStatus)) { 73 if (U_FAILURE(openStatus)) {
74 LOG_ERROR("ubrk_open failed with status %d", openStatus); 74 LOG_ERROR("BreakIterator construction failed with status %d", op enStatus);
75 return 0; 75 return 0;
76 } 76 }
77 } 77 }
78 78
79 ASSERT(!m_vendedIterators.contains(iterator)); 79 ASSERT(!m_vendedIterators.contains(iterator));
80 m_vendedIterators.set(iterator, locale); 80 m_vendedIterators.set(iterator, locale);
81 return iterator; 81 return iterator;
82 } 82 }
83 83
84 void put(UBreakIterator* iterator) 84 void put(icu::BreakIterator* iterator)
85 { 85 {
86 ASSERT_ARG(iterator, m_vendedIterators.contains(iterator)); 86 ASSERT_ARG(iterator, m_vendedIterators.contains(iterator));
87 87
88 if (m_pool.size() == capacity) { 88 if (m_pool.size() == capacity) {
89 ubrk_close(m_pool[0].second); 89 delete m_pool[0].second;
90 m_pool.remove(0); 90 m_pool.remove(0);
91 } 91 }
92 92
93 m_pool.append(Entry(m_vendedIterators.take(iterator), iterator)); 93 m_pool.append(Entry(m_vendedIterators.take(iterator), iterator));
94 } 94 }
95 95
96 private: 96 private:
97 LineBreakIteratorPool() { } 97 LineBreakIteratorPool() { }
98 98
99 static const size_t capacity = 4; 99 static const size_t capacity = 4;
100 100
101 typedef pair<AtomicString, UBreakIterator*> Entry; 101 typedef pair<AtomicString, icu::BreakIterator*> Entry;
102 typedef Vector<Entry, capacity> Pool; 102 typedef Vector<Entry, capacity> Pool;
103 Pool m_pool; 103 Pool m_pool;
104 HashMap<UBreakIterator*, AtomicString> m_vendedIterators; 104 HashMap<icu::BreakIterator*, AtomicString> m_vendedIterators;
105 105
106 friend WTF::ThreadSpecific<LineBreakIteratorPool>::operator LineBreakIterato rPool*(); 106 friend WTF::ThreadSpecific<LineBreakIteratorPool>::operator LineBreakIterato rPool*();
107 }; 107 };
108 108
109 } 109 }
110 110
111 #endif 111 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698