Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Side by Side Diff: third_party/WebKit/Source/wtf/text/WTFString.cpp

Issue 2636083002: WTF: Put String::show()'s definition into the WTF namespace. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/WTFString.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * Copyright (C) 2007-2009 Torch Mobile, Inc. 5 * Copyright (C) 2007-2009 Torch Mobile, Inc.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 24 matching lines...) Expand all
35 #include "wtf/text/IntegerToStringConversion.h" 35 #include "wtf/text/IntegerToStringConversion.h"
36 #include "wtf/text/UTF8.h" 36 #include "wtf/text/UTF8.h"
37 #include "wtf/text/Unicode.h" 37 #include "wtf/text/Unicode.h"
38 #include <algorithm> 38 #include <algorithm>
39 #include <stdarg.h> 39 #include <stdarg.h>
40 40
41 namespace WTF { 41 namespace WTF {
42 42
43 using namespace Unicode; 43 using namespace Unicode;
44 44
45 namespace {
46
47 Vector<char> asciiDebug(StringImpl* impl) {
48 if (!impl)
49 return asciiDebug(String("[null]").impl());
50
51 Vector<char> buffer;
52 for (unsigned i = 0; i < impl->length(); ++i) {
53 UChar ch = (*impl)[i];
54 if (isASCIIPrintable(ch)) {
55 if (ch == '\\')
56 buffer.push_back('\\');
57 buffer.push_back(static_cast<char>(ch));
58 } else {
59 buffer.push_back('\\');
60 buffer.push_back('u');
61 appendUnsignedAsHexFixedSize(ch, buffer, 4);
62 }
63 }
64 buffer.push_back('\0');
65 return buffer;
66 }
67
68 } // namespace
69
45 // Construct a string with UTF-16 data. 70 // Construct a string with UTF-16 data.
46 String::String(const UChar* characters, unsigned length) 71 String::String(const UChar* characters, unsigned length)
47 : m_impl(characters ? StringImpl::create(characters, length) : nullptr) {} 72 : m_impl(characters ? StringImpl::create(characters, length) : nullptr) {}
48 73
49 // Construct a string with UTF-16 data, from a null-terminated source. 74 // Construct a string with UTF-16 data, from a null-terminated source.
50 String::String(const UChar* str) { 75 String::String(const UChar* str) {
51 if (!str) 76 if (!str)
52 return; 77 return;
53 m_impl = StringImpl::create(str, lengthOfNullTerminatedString(str)); 78 m_impl = StringImpl::create(str, lengthOfNullTerminatedString(str));
54 } 79 }
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 out.setf(std::ios_base::hex, std::ios_base::basefield); 829 out.setf(std::ios_base::hex, std::ios_base::basefield);
805 out.setf(std::ios::uppercase); 830 out.setf(std::ios::uppercase);
806 out << character; 831 out << character;
807 } 832 }
808 break; 833 break;
809 } 834 }
810 } 835 }
811 return out << '"'; 836 return out << '"';
812 } 837 }
813 838
814 } // namespace WTF
815
816 #ifndef NDEBUG 839 #ifndef NDEBUG
817 // For use in the debugger
818 String* string(const char*);
819 Vector<char> asciiDebug(StringImpl*);
820 Vector<char> asciiDebug(String&);
821
822 void String::show() const { 840 void String::show() const {
823 dataLogF("%s\n", asciiDebug(impl()).data()); 841 dataLogF("%s\n", asciiDebug(impl()).data());
824 } 842 }
843 #endif
825 844
826 String* string(const char* s) { 845 } // namespace WTF
827 // leaks memory!
828 return new String(s);
829 }
830
831 Vector<char> asciiDebug(StringImpl* impl) {
832 if (!impl)
833 return asciiDebug(String("[null]").impl());
834
835 Vector<char> buffer;
836 for (unsigned i = 0; i < impl->length(); ++i) {
837 UChar ch = (*impl)[i];
838 if (isASCIIPrintable(ch)) {
839 if (ch == '\\')
840 buffer.push_back('\\');
841 buffer.push_back(static_cast<char>(ch));
842 } else {
843 buffer.push_back('\\');
844 buffer.push_back('u');
845 appendUnsignedAsHexFixedSize(ch, buffer, 4);
846 }
847 }
848 buffer.push_back('\0');
849 return buffer;
850 }
851
852 Vector<char> asciiDebug(String& string) {
853 return asciiDebug(string.impl());
854 }
855
856 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/WTFString.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698