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

Side by Side Diff: third_party/WebKit/Source/wtf/text/CString.h

Issue 1382583002: Add toStdString methods to CString and WTF::String (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserv ed.
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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // A container for a null-terminated char array supporting copy-on-write 57 // A container for a null-terminated char array supporting copy-on-write
58 // assignment. The contained char array may be null. 58 // assignment. The contained char array may be null.
59 class WTF_EXPORT CString { 59 class WTF_EXPORT CString {
60 public: 60 public:
61 CString() { } 61 CString() { }
62 CString(const char*); 62 CString(const char*);
63 CString(const char*, size_t length); 63 CString(const char*, size_t length);
64 CString(CStringBuffer* buffer) : m_buffer(buffer) { } 64 CString(CStringBuffer* buffer) : m_buffer(buffer) { }
65 static CString newUninitialized(size_t length, char*& characterBuffer); 65 static CString newUninitialized(size_t length, char*& characterBuffer);
66 66
67 std::string toStdString() const
68 {
69 return std::string(data(), length());
Mikhail 2015/09/30 14:02:01 length() includes NULL terminator, so should be 'l
Primiano Tucci (use gerrit) 2015/09/30 15:08:28 Just tried: String("").length() returns 0 not 1.
Mikhail 2015/09/30 15:58:39 Right. CStringBuffer's length != its size, sorry f
70 }
71
67 const char* data() const 72 const char* data() const
68 { 73 {
69 return m_buffer ? m_buffer->data() : 0; 74 return m_buffer ? m_buffer->data() : 0;
70 } 75 }
71 char* mutableData(); 76 char* mutableData();
72 size_t length() const 77 size_t length() const
73 { 78 {
74 return m_buffer ? m_buffer->length() : 0; 79 return m_buffer ? m_buffer->length() : 0;
75 } 80 }
76 81
(...skipping 11 matching lines...) Expand all
88 WTF_EXPORT bool operator==(const CString& a, const CString& b); 93 WTF_EXPORT bool operator==(const CString& a, const CString& b);
89 inline bool operator!=(const CString& a, const CString& b) { return !(a == b); } 94 inline bool operator!=(const CString& a, const CString& b) { return !(a == b); }
90 WTF_EXPORT bool operator==(const CString& a, const char* b); 95 WTF_EXPORT bool operator==(const CString& a, const char* b);
91 inline bool operator!=(const CString& a, const char* b) { return !(a == b); } 96 inline bool operator!=(const CString& a, const char* b) { return !(a == b); }
92 97
93 } // namespace WTF 98 } // namespace WTF
94 99
95 using WTF::CString; 100 using WTF::CString;
96 101
97 #endif // CString_h 102 #endif // CString_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/text/CStringTest.cpp » ('j') | third_party/WebKit/Source/wtf/text/WTFString.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698