string_compare.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2014 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#include "cpp/src/util/string_compare.h" 6 7#include "base/i18n/string_compare.h" 8#include "base/logging.h" 9#include "base/strings/utf_string_conversions.h" 10#include "cpp/include/libaddressinput/util/scoped_ptr.h" 11#include "third_party/icu/source/i18n/unicode/coll.h" 12 13namespace i18n { 14namespace addressinput { 15 16bool LooseStringCompare(const std::string& a, const std::string& b) { 17 UErrorCode error_code = U_ZERO_ERROR; 18 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); 19 // Differences in diacriticals and case are ignored. 20 collator->setStrength(icu::Collator::PRIMARY); 21 DCHECK(U_SUCCESS(error_code)); 22 UCollationResult result = base::i18n::CompareString16WithCollator( 23 collator.get(), 24 base::UTF8ToUTF16(a), 25 base::UTF8ToUTF16(b)); 26 DCHECK(U_SUCCESS(error_code)); 27 return result == UCOL_EQUAL; 28} 29 30} // namespace addressinput 31} // namespace i18n 32