url_idna_icu_alternatives_ios.mm 808 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2016 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. #include <string.h>
  5. #include <ostream>
  6. #include <string>
  7. #include "base/strings/string_piece.h"
  8. #include "base/strings/string_util.h"
  9. #include "base/strings/utf_string_conversions.h"
  10. #include "url/url_canon_internal.h"
  11. namespace url {
  12. // Only allow ASCII to avoid ICU dependency. Use NSString+IDN
  13. // to convert non-ASCII URL prior to passing to API.
  14. bool IDNToASCII(const char16_t* src, int src_len, CanonOutputW* output) {
  15. if (base::IsStringASCII(base::StringPiece16(src, src_len))) {
  16. output->Append(src, src_len);
  17. return true;
  18. }
  19. DCHECK(false) << "IDN URL support is not available.";
  20. return false;
  21. }
  22. } // namespace url