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

Side by Side Diff: third_party/WebKit/Source/wtf/text/icu/CollatorICU.cpp

Issue 2585673002: Replace ASSERT, ENABLE(ASSERT), and ASSERT_NOT_REACHED in wtf (Closed)
Patch Set: Fix an Asan issue with LinkedHashSetNodeBase::unlink Created 4 years 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) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const UChar* rhs, 72 const UChar* rhs,
73 size_t rhsLength) const { 73 size_t rhsLength) const {
74 if (!m_collator) 74 if (!m_collator)
75 createCollator(); 75 createCollator();
76 76
77 return static_cast<Result>( 77 return static_cast<Result>(
78 ucol_strcoll(m_collator, lhs, lhsLength, rhs, rhsLength)); 78 ucol_strcoll(m_collator, lhs, lhsLength, rhs, rhsLength));
79 } 79 }
80 80
81 void Collator::createCollator() const { 81 void Collator::createCollator() const {
82 ASSERT(!m_collator); 82 DCHECK(!m_collator);
83 UErrorCode status = U_ZERO_ERROR; 83 UErrorCode status = U_ZERO_ERROR;
84 84
85 { 85 {
86 Locker<Mutex> lock(cachedCollatorMutex()); 86 Locker<Mutex> lock(cachedCollatorMutex());
87 if (cachedCollator) { 87 if (cachedCollator) {
88 UColAttributeValue cachedCollatorLowerFirst = 88 UColAttributeValue cachedCollatorLowerFirst =
89 ucol_getAttribute(cachedCollator, UCOL_CASE_FIRST, &status); 89 ucol_getAttribute(cachedCollator, UCOL_CASE_FIRST, &status);
90 ASSERT(U_SUCCESS(status)); 90 DCHECK(U_SUCCESS(status));
91 91
92 if (0 == strcmp(cachedEquivalentLocale, m_equivalentLocale) && 92 if (0 == strcmp(cachedEquivalentLocale, m_equivalentLocale) &&
93 ((UCOL_LOWER_FIRST == cachedCollatorLowerFirst && m_lowerFirst) || 93 ((UCOL_LOWER_FIRST == cachedCollatorLowerFirst && m_lowerFirst) ||
94 (UCOL_UPPER_FIRST == cachedCollatorLowerFirst && !m_lowerFirst))) { 94 (UCOL_UPPER_FIRST == cachedCollatorLowerFirst && !m_lowerFirst))) {
95 m_collator = cachedCollator; 95 m_collator = cachedCollator;
96 cachedCollator = 0; 96 cachedCollator = 0;
97 cachedEquivalentLocale[0] = 0; 97 cachedEquivalentLocale[0] = 0;
98 return; 98 return;
99 } 99 }
100 } 100 }
101 } 101 }
102 102
103 m_collator = ucol_open(m_locale, &status); 103 m_collator = ucol_open(m_locale, &status);
104 if (U_FAILURE(status)) { 104 if (U_FAILURE(status)) {
105 status = U_ZERO_ERROR; 105 status = U_ZERO_ERROR;
106 m_collator = 106 m_collator =
107 ucol_open("", &status); // Fallback to Unicode Collation Algorithm. 107 ucol_open("", &status); // Fallback to Unicode Collation Algorithm.
108 } 108 }
109 ASSERT(U_SUCCESS(status)); 109 DCHECK(U_SUCCESS(status));
110 110
111 ucol_setAttribute(m_collator, UCOL_CASE_FIRST, 111 ucol_setAttribute(m_collator, UCOL_CASE_FIRST,
112 m_lowerFirst ? UCOL_LOWER_FIRST : UCOL_UPPER_FIRST, 112 m_lowerFirst ? UCOL_LOWER_FIRST : UCOL_UPPER_FIRST,
113 &status); 113 &status);
114 ASSERT(U_SUCCESS(status)); 114 DCHECK(U_SUCCESS(status));
115 115
116 ucol_setAttribute(m_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); 116 ucol_setAttribute(m_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
117 ASSERT(U_SUCCESS(status)); 117 DCHECK(U_SUCCESS(status));
118 } 118 }
119 119
120 void Collator::releaseCollator() { 120 void Collator::releaseCollator() {
121 { 121 {
122 Locker<Mutex> lock(cachedCollatorMutex()); 122 Locker<Mutex> lock(cachedCollatorMutex());
123 if (cachedCollator) 123 if (cachedCollator)
124 ucol_close(cachedCollator); 124 ucol_close(cachedCollator);
125 cachedCollator = m_collator; 125 cachedCollator = m_collator;
126 strncpy(cachedEquivalentLocale, m_equivalentLocale, ulocFullnameCapacity); 126 strncpy(cachedEquivalentLocale, m_equivalentLocale, ulocFullnameCapacity);
127 m_collator = 0; 127 m_collator = 0;
128 } 128 }
129 m_collator = 0; 129 m_collator = 0;
130 } 130 }
131 131
132 void Collator::setEquivalentLocale(const char* locale, char* equivalentLocale) { 132 void Collator::setEquivalentLocale(const char* locale, char* equivalentLocale) {
133 UErrorCode status = U_ZERO_ERROR; 133 UErrorCode status = U_ZERO_ERROR;
134 UBool isAvailable; 134 UBool isAvailable;
135 ucol_getFunctionalEquivalent(equivalentLocale, ulocFullnameCapacity, 135 ucol_getFunctionalEquivalent(equivalentLocale, ulocFullnameCapacity,
136 "collation", locale, &isAvailable, &status); 136 "collation", locale, &isAvailable, &status);
137 if (U_FAILURE(status)) 137 if (U_FAILURE(status))
138 strcpy(equivalentLocale, "root"); 138 strcpy(equivalentLocale, "root");
139 } 139 }
140 140
141 } // namespace WTF 141 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/WTFString.cpp ('k') | third_party/WebKit/Source/wtf/typed_arrays/ArrayBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698