OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. |
4 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty())); | 1191 DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty())); |
1192 return emptyString; | 1192 return emptyString; |
1193 } | 1193 } |
1194 | 1194 |
1195 const String& emptyString16Bit() | 1195 const String& emptyString16Bit() |
1196 { | 1196 { |
1197 DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty16Bit())); | 1197 DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty16Bit())); |
1198 return emptyString; | 1198 return emptyString; |
1199 } | 1199 } |
1200 | 1200 |
| 1201 std::ostream& operator<<(std::ostream& out, const String& string) |
| 1202 { |
| 1203 if (string.isNull()) |
| 1204 return out << "<null>"; |
| 1205 |
| 1206 out << '"'; |
| 1207 for (unsigned index = 0; index < string.length(); ++index) { |
| 1208 // Print shorthands for select cases. |
| 1209 UChar character = string[index]; |
| 1210 switch (character) { |
| 1211 case '\t': |
| 1212 out << "\\t"; |
| 1213 break; |
| 1214 case '\n': |
| 1215 out << "\\n"; |
| 1216 break; |
| 1217 case '\r': |
| 1218 out << "\\r"; |
| 1219 break; |
| 1220 case '"': |
| 1221 out << "\\\""; |
| 1222 break; |
| 1223 case '\\': |
| 1224 out << "\\\\"; |
| 1225 break; |
| 1226 default: |
| 1227 if (isASCIIPrintable(character)) { |
| 1228 out << static_cast<char>(character); |
| 1229 } else { |
| 1230 // Print "\uXXXX" for control or non-ASCII characters. |
| 1231 out << "\\u"; |
| 1232 out.width(4); |
| 1233 out.fill('0'); |
| 1234 out.setf(std::ios_base::hex, std::ios_base::basefield); |
| 1235 out.setf(std::ios::uppercase); |
| 1236 out << character; |
| 1237 } |
| 1238 break; |
| 1239 } |
| 1240 } |
| 1241 return out << '"'; |
| 1242 } |
| 1243 |
1201 } // namespace WTF | 1244 } // namespace WTF |
1202 | 1245 |
1203 #ifndef NDEBUG | 1246 #ifndef NDEBUG |
1204 // For use in the debugger | 1247 // For use in the debugger |
1205 String* string(const char*); | 1248 String* string(const char*); |
1206 Vector<char> asciiDebug(StringImpl*); | 1249 Vector<char> asciiDebug(StringImpl*); |
1207 Vector<char> asciiDebug(String&); | 1250 Vector<char> asciiDebug(String&); |
1208 | 1251 |
1209 void String::show() const | 1252 void String::show() const |
1210 { | 1253 { |
(...skipping 27 matching lines...) Expand all Loading... |
1238 buffer.append('\0'); | 1281 buffer.append('\0'); |
1239 return buffer; | 1282 return buffer; |
1240 } | 1283 } |
1241 | 1284 |
1242 Vector<char> asciiDebug(String& string) | 1285 Vector<char> asciiDebug(String& string) |
1243 { | 1286 { |
1244 return asciiDebug(string.impl()); | 1287 return asciiDebug(string.impl()); |
1245 } | 1288 } |
1246 | 1289 |
1247 #endif | 1290 #endif |
OLD | NEW |