| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
| 34 #include <ostream> // NOLINT | 34 #include <ostream> // NOLINT |
| 35 | 35 |
| 36 namespace WTF { | 36 namespace WTF { |
| 37 | 37 |
| 38 std::ostream& operator<<(std::ostream& out, const String& string) | 38 std::ostream& operator<<(std::ostream& out, const String& string) { |
| 39 { | 39 if (string.isNull()) |
| 40 if (string.isNull()) | 40 return out << "<null>"; |
| 41 return out << "<null>"; | |
| 42 | 41 |
| 43 out << '"'; | 42 out << '"'; |
| 44 for (unsigned index = 0; index < string.length(); ++index) { | 43 for (unsigned index = 0; index < string.length(); ++index) { |
| 45 // Print shorthands for select cases. | 44 // Print shorthands for select cases. |
| 46 UChar character = string[index]; | 45 UChar character = string[index]; |
| 47 switch (character) { | 46 switch (character) { |
| 48 case '\t': | 47 case '\t': |
| 49 out << "\\t"; | 48 out << "\\t"; |
| 50 break; | 49 break; |
| 51 case '\n': | 50 case '\n': |
| 52 out << "\\n"; | 51 out << "\\n"; |
| 53 break; | 52 break; |
| 54 case '\r': | 53 case '\r': |
| 55 out << "\\r"; | 54 out << "\\r"; |
| 56 break; | 55 break; |
| 57 case '"': | 56 case '"': |
| 58 out << "\\\""; | 57 out << "\\\""; |
| 59 break; | 58 break; |
| 60 case '\\': | 59 case '\\': |
| 61 out << "\\\\"; | 60 out << "\\\\"; |
| 62 break; | 61 break; |
| 63 default: | 62 default: |
| 64 if (character >= 0x20 && character < 0x7F) { | 63 if (character >= 0x20 && character < 0x7F) { |
| 65 out << static_cast<char>(character); | 64 out << static_cast<char>(character); |
| 66 } else { | 65 } else { |
| 67 // Print "\uXXXX" for control or non-ASCII characters. | 66 // Print "\uXXXX" for control or non-ASCII characters. |
| 68 out << "\\u"; | 67 out << "\\u"; |
| 69 out.width(4); | 68 out.width(4); |
| 70 out.fill('0'); | 69 out.fill('0'); |
| 71 out.setf(std::ios_base::hex, std::ios_base::basefield); | 70 out.setf(std::ios_base::hex, std::ios_base::basefield); |
| 72 out.setf(std::ios::uppercase); | 71 out.setf(std::ios::uppercase); |
| 73 out << character; | 72 out << character; |
| 74 } | |
| 75 break; | |
| 76 } | 73 } |
| 74 break; |
| 77 } | 75 } |
| 78 return out << '"'; | 76 } |
| 77 return out << '"'; |
| 79 } | 78 } |
| 80 | 79 |
| 81 } // namespace WTF | 80 } // namespace WTF |
| OLD | NEW |