Reviewed by Maciej.
Add CString. CString is a simple, null-terminated byte buffer that supports data
sharing. Its main use is to be a better const char*.
Also add latin1 and utf8 methods to String which returns CStrings.
* platform/CString.cpp: Added.
(WebCore::CString::CString):
(WebCore::CString::init):
(WebCore::CString::data):
(WebCore::CString::length):
(WebCore::CString::deprecatedCString):
* platform/CString.h: Added.
(WebCore::CStringBuffer::CStringBuffer):
(WebCore::CStringBuffer::data):
(WebCore::CStringBuffer::length):
(WebCore::CString::CString):
(WebCore::CString::operator const char*):
(WebCore::CString::isNull):
* platform/PlatformString.h:
* platform/String.cpp:
(WebCore::String::latin1):
(WebCore::String::utf8):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16153
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-08-31 Anders Carlsson <acarlsson@apple.com>
+
+ Reviewed by Maciej.
+
+ Add CString. CString is a simple, null-terminated byte buffer that supports data
+ sharing. Its main use is to be a better const char*.
+
+ Also add latin1 and utf8 methods to String which returns CStrings.
+
+ * platform/CString.cpp: Added.
+ (WebCore::CString::CString):
+ (WebCore::CString::init):
+ (WebCore::CString::data):
+ (WebCore::CString::length):
+ (WebCore::CString::deprecatedCString):
+ * platform/CString.h: Added.
+ (WebCore::CStringBuffer::CStringBuffer):
+ (WebCore::CStringBuffer::data):
+ (WebCore::CStringBuffer::length):
+ (WebCore::CString::CString):
+ (WebCore::CString::operator const char*):
+ (WebCore::CString::isNull):
+ * platform/PlatformString.h:
+ * platform/String.cpp:
+ (WebCore::String::latin1):
+ (WebCore::String::utf8):
+
2006-08-31 Brady Eidson <beidson@apple.com>
Reviewed by Hyatt
1A85B2110A1B258700D8C87C /* JSHTMLUListElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A85B20F0A1B258700D8C87C /* JSHTMLUListElement.h */; };
1A85B2B60A1B2AC700D8C87C /* JSHTMLDivElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A85B2B40A1B2AC700D8C87C /* JSHTMLDivElement.cpp */; };
1A85B2B70A1B2AC700D8C87C /* JSHTMLDivElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A85B2B50A1B2AC700D8C87C /* JSHTMLDivElement.h */; };
+ 1A98955C0AA78149005EF5EF /* CString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A98955A0AA78149005EF5EF /* CString.cpp */; };
+ 1A98955D0AA78149005EF5EF /* CString.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A98955B0AA78149005EF5EF /* CString.h */; };
1A9EF4570A1B957D00332B63 /* JSCanvasRenderingContext2DCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A9EF4560A1B957D00332B63 /* JSCanvasRenderingContext2DCustom.cpp */; };
1AB7FC680A8B92EC00D9D37B /* XPathEvaluator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB7FC470A8B92EC00D9D37B /* XPathEvaluator.cpp */; };
1AB7FC690A8B92EC00D9D37B /* XPathEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB7FC480A8B92EC00D9D37B /* XPathEvaluator.h */; };
1A85B2AD0A1B2A6D00D8C87C /* HTMLDivElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLDivElement.idl; sourceTree = "<group>"; };
1A85B2B40A1B2AC700D8C87C /* JSHTMLDivElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLDivElement.cpp; sourceTree = "<group>"; };
1A85B2B50A1B2AC700D8C87C /* JSHTMLDivElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLDivElement.h; sourceTree = "<group>"; };
+ 1A98955A0AA78149005EF5EF /* CString.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CString.cpp; sourceTree = "<group>"; };
+ 1A98955B0AA78149005EF5EF /* CString.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CString.h; sourceTree = "<group>"; };
1A9EF4560A1B957D00332B63 /* JSCanvasRenderingContext2DCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCanvasRenderingContext2DCustom.cpp; sourceTree = "<group>"; };
1AB7FC470A8B92EC00D9D37B /* XPathEvaluator.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = XPathEvaluator.cpp; sourceTree = "<group>"; };
1AB7FC480A8B92EC00D9D37B /* XPathEvaluator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = XPathEvaluator.h; sourceTree = "<group>"; };
BCC8CFC90986CD2400140BF2 /* Color.h */,
BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
9352088109BD45E900F2038D /* CookieJar.h */,
+ 1A98955A0AA78149005EF5EF /* CString.cpp */,
+ 1A98955B0AA78149005EF5EF /* CString.h */,
F587868402DE3B8601EA4122 /* Cursor.h */,
BCB16B880979B01400467741 /* DeprecatedArray.h */,
F58784D502DE375901EA4122 /* DeprecatedCString.cpp */,
85183B460AA6926100F19FA3 /* DOMHTMLParagraphElement.h in Headers */,
85183B480AA6926100F19FA3 /* DOMHTMLPreElement.h in Headers */,
85183B4A0AA6926100F19FA3 /* DOMHTMLQuoteElement.h in Headers */,
+ 1A98955D0AA78149005EF5EF /* CString.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
85183B470AA6926100F19FA3 /* DOMHTMLParagraphElement.mm in Sources */,
85183B490AA6926100F19FA3 /* DOMHTMLPreElement.mm in Sources */,
85183B4B0AA6926100F19FA3 /* DOMHTMLQuoteElement.mm in Sources */,
+ 1A98955C0AA78149005EF5EF /* CString.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
--- /dev/null
+/*
+ * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "config.h"
+#include "CString.h"
+#include "DeprecatedCString.h"
+
+namespace WebCore {
+
+CString::CString(const char* str)
+{
+ init(str, strlen(str));
+}
+
+CString::CString(const char* str, unsigned length)
+{
+ init(str, length);
+}
+
+CString::CString(const DeprecatedCString& str)
+{
+ init(str.data(), str.length());
+}
+
+void CString::init(const char* str, unsigned length)
+{
+ if (!str)
+ return;
+
+ m_buffer = new CStringBuffer(length + 1);
+ memcpy(m_buffer->data(), str, length);
+ m_buffer->data()[length] = '\0';
+}
+
+const char* CString::data() const
+{
+ return m_buffer ? m_buffer->data() : 0;
+}
+
+unsigned CString::length() const
+{
+ return m_buffer ? m_buffer->length() - 1 : 0;
+}
+
+DeprecatedCString CString::deprecatedCString() const
+{
+ return DeprecatedCString(data(), length() + 1);
+}
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CString_h
+#define CString_h
+
+#include <wtf/Vector.h>
+#include "Shared.h"
+
+namespace WebCore {
+ class DeprecatedCString;
+
+ class CStringBuffer : public Shared<CStringBuffer> {
+ public:
+ CStringBuffer(unsigned length) : m_vector(length) { }
+
+ char* data() { return m_vector.data(); }
+ unsigned length() const { return m_vector.size(); }
+ private:
+ Vector<char> m_vector;
+ };
+
+ class CString {
+ public:
+ CString() { }
+ CString(const char* str);
+ CString(const char* str, unsigned length);
+
+ const char* data() const;
+ unsigned length() const;
+
+ operator const char*() const { return data(); }
+
+ bool isNull() const { return !m_buffer; }
+
+ CString(const DeprecatedCString& str);
+ DeprecatedCString deprecatedCString() const;
+ private:
+ void init(const char*str, unsigned length);
+ RefPtr<CStringBuffer> m_buffer;
+ };
+
+}
+
+#endif // CString_h
namespace WebCore {
+class CString;
+
/**
* Currently, strings are explicitly shared (they behave like pointers), meaning
* that modifications to one instance will also modify all others. If you
Vector<char> ascii() const;
#endif
+ CString latin1() const;
+ CString utf8() const;
+
String(const DeprecatedString&);
DeprecatedString deprecatedString() const;
#include "config.h"
#include "PlatformString.h"
+#include "CString.h"
#include "DeprecatedString.h"
+#include "TextEncoding.h"
#include <kjs/identifier.h>
#include <wtf/Vector.h>
#include <stdarg.h>
}
#endif
+CString String::latin1() const
+{
+ return TextEncoding(Latin1Encoding).fromUnicode(deprecatedString());
+}
+
+CString String::utf8() const
+{
+ return TextEncoding(UTF8Encoding).fromUnicode(deprecatedString());
+}
+
bool operator==(const String& a, const DeprecatedString& b)
{
unsigned l = a.length();