Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 14444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14455 return TwoByteString::EscapeSpecialCharacters( | 14455 return TwoByteString::EscapeSpecialCharacters( |
| 14456 String::Handle(TwoByteString::New(str, Heap::kNew))); | 14456 String::Handle(TwoByteString::New(str, Heap::kNew))); |
| 14457 } | 14457 } |
| 14458 | 14458 |
| 14459 | 14459 |
| 14460 static bool IsPercent(int32_t c) { | 14460 static bool IsPercent(int32_t c) { |
| 14461 return c == '%'; | 14461 return c == '%'; |
| 14462 } | 14462 } |
| 14463 | 14463 |
| 14464 | 14464 |
| 14465 static bool IsHexCharacter(int32_t c) { | |
| 14466 if (c >= '0' && c <= '9') { | |
| 14467 return true; | |
| 14468 } | |
| 14469 if (c >= 'A' && c <= 'F') { | |
| 14470 return true; | |
| 14471 } | |
| 14472 return false; | |
| 14473 } | |
| 14474 | |
| 14475 | |
| 14465 static bool IsURISafeCharacter(int32_t c) { | 14476 static bool IsURISafeCharacter(int32_t c) { |
| 14466 if ((c >= '0') && (c <= '9')) { | 14477 if ((c >= '0') && (c <= '9')) { |
| 14467 return true; | 14478 return true; |
| 14468 } | 14479 } |
| 14469 if ((c >= 'a') && (c <= 'z')) { | 14480 if ((c >= 'a') && (c <= 'z')) { |
| 14470 return true; | 14481 return true; |
| 14471 } | 14482 } |
| 14472 if ((c >= 'A') && (c <= 'Z')) { | 14483 if ((c >= 'A') && (c <= 'Z')) { |
| 14473 return true; | 14484 return true; |
| 14474 } | 14485 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14538 return dststr.raw(); | 14549 return dststr.raw(); |
| 14539 } | 14550 } |
| 14540 | 14551 |
| 14541 | 14552 |
| 14542 RawString* String::DecodeURI(const String& str) { | 14553 RawString* String::DecodeURI(const String& str) { |
| 14543 // URI encoding is only specified for one byte strings. | 14554 // URI encoding is only specified for one byte strings. |
| 14544 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString()); | 14555 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString()); |
| 14545 CodePointIterator cpi(str); | 14556 CodePointIterator cpi(str); |
| 14546 intptr_t num_escapes = 0; | 14557 intptr_t num_escapes = 0; |
| 14547 intptr_t len = str.Length(); | 14558 intptr_t len = str.Length(); |
| 14559 bool valid = true; | |
| 14548 { | 14560 { |
| 14549 CodePointIterator cpi(str); | 14561 CodePointIterator cpi(str); |
| 14550 while (cpi.Next()) { | 14562 while (valid && cpi.Next()) { |
| 14551 int32_t code_point = cpi.Current(); | 14563 int32_t code_point = cpi.Current(); |
| 14552 if (IsPercent(code_point)) { | 14564 if (IsPercent(code_point)) { |
| 14565 // Verify that the two characters following the % are hex digits. | |
| 14566 if (!cpi.Next()) { | |
| 14567 valid = false; | |
| 14568 break; | |
| 14569 } | |
| 14570 int32_t code_point = cpi.Current(); | |
| 14571 if (!IsHexCharacter(code_point)) { | |
| 14572 valid = false; | |
| 14573 break; | |
| 14574 } | |
| 14575 if (!cpi.Next()) { | |
| 14576 valid = false; | |
| 14577 break; | |
| 14578 } | |
| 14579 code_point = cpi.Current(); | |
| 14580 if (!IsHexCharacter(code_point)) { | |
| 14581 valid = false; | |
| 14582 break; | |
| 14583 } | |
| 14553 num_escapes += 2; | 14584 num_escapes += 2; |
| 14554 } | 14585 } |
| 14555 } | 14586 } |
| 14556 } | 14587 } |
| 14588 if (!valid) { | |
| 14589 // Invalid, return original string. | |
| 14590 return str.raw(); | |
| 14591 } | |
|
siva
2013/12/21 00:10:36
You seem to always break out of the while loop if
turnidge
2014/01/06 20:34:47
Agree with Siva that the code could be simpler.
I
| |
| 14557 ASSERT(len - num_escapes > 0); | 14592 ASSERT(len - num_escapes > 0); |
| 14558 const String& dststr = String::Handle( | 14593 const String& dststr = String::Handle( |
| 14559 OneByteString::New(len - num_escapes, Heap::kNew)); | 14594 OneByteString::New(len - num_escapes, Heap::kNew)); |
| 14560 { | 14595 { |
| 14561 intptr_t index = 0; | 14596 intptr_t index = 0; |
| 14562 CodePointIterator cpi(str); | 14597 CodePointIterator cpi(str); |
| 14563 while (cpi.Next()) { | 14598 while (cpi.Next()) { |
| 14564 int32_t code_point = cpi.Current(); | 14599 int32_t code_point = cpi.Current(); |
| 14565 if (IsPercent(code_point)) { | 14600 if (IsPercent(code_point)) { |
| 14566 ASSERT(cpi.Next()); | 14601 cpi.Next(); |
| 14567 int32_t ch1 = cpi.Current(); | 14602 int32_t ch1 = cpi.Current(); |
| 14568 cpi.Next(); | 14603 cpi.Next(); |
| 14569 int32_t ch2 = cpi.Current(); | 14604 int32_t ch2 = cpi.Current(); |
| 14570 int32_t merged = MergeHexCharacters(ch1, ch2); | 14605 int32_t merged = MergeHexCharacters(ch1, ch2); |
| 14571 OneByteString::SetCharAt(dststr, index, merged); | 14606 OneByteString::SetCharAt(dststr, index, merged); |
| 14572 } else { | 14607 } else { |
| 14573 OneByteString::SetCharAt(dststr, index, code_point); | 14608 OneByteString::SetCharAt(dststr, index, code_point); |
| 14574 } | 14609 } |
| 14575 index++; | 14610 index++; |
| 14576 } | 14611 } |
| (...skipping 2179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16756 return "_MirrorReference"; | 16791 return "_MirrorReference"; |
| 16757 } | 16792 } |
| 16758 | 16793 |
| 16759 | 16794 |
| 16760 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16795 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16761 Instance::PrintToJSONStream(stream, ref); | 16796 Instance::PrintToJSONStream(stream, ref); |
| 16762 } | 16797 } |
| 16763 | 16798 |
| 16764 | 16799 |
| 16765 } // namespace dart | 16800 } // namespace dart |
| OLD | NEW |