| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <unicode/regex.h> | 9 #include <unicode/regex.h> |
| 10 #include <unicode/ucnv.h> | 10 #include <unicode/ucnv.h> |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 // An alternative is negative-listing (languages using Greek and | 506 // An alternative is negative-listing (languages using Greek and |
| 507 // Cyrillic letters), but it can be more dangerous. | 507 // Cyrillic letters), but it can be more dangerous. |
| 508 return !lang.substr(0, 2).compare("zh") || | 508 return !lang.substr(0, 2).compare("zh") || |
| 509 !lang.substr(0, 2).compare("ja") || | 509 !lang.substr(0, 2).compare("ja") || |
| 510 !lang.substr(0, 2).compare("ko"); | 510 !lang.substr(0, 2).compare("ko"); |
| 511 } | 511 } |
| 512 | 512 |
| 513 typedef std::map<std::string, icu::UnicodeSet*> LangToExemplarSetMap; | 513 typedef std::map<std::string, icu::UnicodeSet*> LangToExemplarSetMap; |
| 514 | 514 |
| 515 class LangToExemplarSet { | 515 class LangToExemplarSet { |
| 516 public: |
| 517 static LangToExemplarSet* GetInstance() { |
| 518 return Singleton<LangToExemplarSet>::get(); |
| 519 } |
| 520 |
| 516 private: | 521 private: |
| 517 LangToExemplarSetMap map; | 522 LangToExemplarSetMap map; |
| 518 LangToExemplarSet() { } | 523 LangToExemplarSet() { } |
| 519 ~LangToExemplarSet() { | 524 ~LangToExemplarSet() { |
| 520 STLDeleteContainerPairSecondPointers(map.begin(), map.end()); | 525 STLDeleteContainerPairSecondPointers(map.begin(), map.end()); |
| 521 } | 526 } |
| 522 | 527 |
| 523 friend class Singleton<LangToExemplarSet>; | 528 friend class Singleton<LangToExemplarSet>; |
| 524 friend struct DefaultSingletonTraits<LangToExemplarSet>; | 529 friend struct DefaultSingletonTraits<LangToExemplarSet>; |
| 525 friend bool GetExemplarSetForLang(const std::string&, icu::UnicodeSet**); | 530 friend bool GetExemplarSetForLang(const std::string&, icu::UnicodeSet**); |
| 526 friend void SetExemplarSetForLang(const std::string&, icu::UnicodeSet*); | 531 friend void SetExemplarSetForLang(const std::string&, icu::UnicodeSet*); |
| 527 | 532 |
| 528 DISALLOW_COPY_AND_ASSIGN(LangToExemplarSet); | 533 DISALLOW_COPY_AND_ASSIGN(LangToExemplarSet); |
| 529 }; | 534 }; |
| 530 | 535 |
| 531 bool GetExemplarSetForLang(const std::string& lang, | 536 bool GetExemplarSetForLang(const std::string& lang, |
| 532 icu::UnicodeSet** lang_set) { | 537 icu::UnicodeSet** lang_set) { |
| 533 const LangToExemplarSetMap& map = Singleton<LangToExemplarSet>()->map; | 538 const LangToExemplarSetMap& map = LangToExemplarSet::GetInstance()->map; |
| 534 LangToExemplarSetMap::const_iterator pos = map.find(lang); | 539 LangToExemplarSetMap::const_iterator pos = map.find(lang); |
| 535 if (pos != map.end()) { | 540 if (pos != map.end()) { |
| 536 *lang_set = pos->second; | 541 *lang_set = pos->second; |
| 537 return true; | 542 return true; |
| 538 } | 543 } |
| 539 return false; | 544 return false; |
| 540 } | 545 } |
| 541 | 546 |
| 542 void SetExemplarSetForLang(const std::string& lang, | 547 void SetExemplarSetForLang(const std::string& lang, |
| 543 icu::UnicodeSet* lang_set) { | 548 icu::UnicodeSet* lang_set) { |
| 544 LangToExemplarSetMap& map = Singleton<LangToExemplarSet>()->map; | 549 LangToExemplarSetMap& map = LangToExemplarSet::GetInstance()->map; |
| 545 map.insert(std::make_pair(lang, lang_set)); | 550 map.insert(std::make_pair(lang, lang_set)); |
| 546 } | 551 } |
| 547 | 552 |
| 548 static Lock lang_set_lock; | 553 static Lock lang_set_lock; |
| 549 | 554 |
| 550 // Returns true if all the characters in component_characters are used by | 555 // Returns true if all the characters in component_characters are used by |
| 551 // the language |lang|. | 556 // the language |lang|. |
| 552 bool IsComponentCoveredByLang(const icu::UnicodeSet& component_characters, | 557 bool IsComponentCoveredByLang(const icu::UnicodeSet& component_characters, |
| 553 const std::string& lang) { | 558 const std::string& lang) { |
| 554 static const icu::UnicodeSet kASCIILetters(0x61, 0x7a); // [a-z] | 559 static const icu::UnicodeSet kASCIILetters(0x61, 0x7a); // [a-z] |
| (...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 } | 2053 } |
| 2049 | 2054 |
| 2050 int GetPortFromAddrinfo(const struct addrinfo* info) { | 2055 int GetPortFromAddrinfo(const struct addrinfo* info) { |
| 2051 uint16* port_field = GetPortFieldFromAddrinfo(info); | 2056 uint16* port_field = GetPortFieldFromAddrinfo(info); |
| 2052 if (!port_field) | 2057 if (!port_field) |
| 2053 return -1; | 2058 return -1; |
| 2054 return ntohs(*port_field); | 2059 return ntohs(*port_field); |
| 2055 } | 2060 } |
| 2056 | 2061 |
| 2057 } // namespace net | 2062 } // namespace net |
| OLD | NEW |