get rid of JavaScriptCore's CString

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2016-06-19 14:42:13 +00:00
parent ac3f25c3b7
commit e7c2e08e62
5 changed files with 17 additions and 138 deletions

View file

@ -56,7 +56,7 @@ double parseDate(ExecState* exec, const UString &date)
{
if (date == exec->globalData().cachedDateString)
return exec->globalData().cachedDateStringValue;
double value = parseDateFromNullTerminatedCharacters(exec, date.UTF8String().c_str());
double value = parseDateFromNullTerminatedCharacters(exec, date.UTF8String());
exec->globalData().cachedDateString = date;
exec->globalData().cachedDateStringValue = value;
return value;

View file

@ -53,13 +53,13 @@ namespace JSC {
static JSValue encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
{
UString str = args.at(0).toString(exec);
CString cstr = str.UTF8String(true);
if (!cstr.c_str())
const char* cstr = str.UTF8String(true);
if (!cstr)
return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
StringBuilder builder;
const char* p = cstr.c_str();
for (size_t k = 0; k < cstr.size(); k++, p++) {
const char* p = cstr;
for (size_t k = 0; k < strlen(cstr); k++, p++) {
char c = *p;
if (c && strchr(doNotEscape, c))
builder.append(c);

View file

@ -57,95 +57,6 @@ namespace JSC {
extern const double NaN;
extern const double Inf;
CString::CString(const char* c)
: m_length(strlen(c))
, m_data(new char[m_length + 1])
{
memcpy(m_data, c, m_length + 1);
}
CString::CString(const char* c, size_t length)
: m_length(length)
, m_data(new char[length + 1])
{
memcpy(m_data, c, m_length);
m_data[m_length] = 0;
}
CString::CString(const CString& b)
{
m_length = b.m_length;
if (b.m_data) {
m_data = new char[m_length + 1];
memcpy(m_data, b.m_data, m_length + 1);
} else
m_data = 0;
}
CString::~CString()
{
delete [] m_data;
}
CString CString::adopt(char* c, size_t length)
{
CString s;
s.m_data = c;
s.m_length = length;
return s;
}
CString& CString::append(const CString& t)
{
char* n;
n = new char[m_length + t.m_length + 1];
if (m_length)
memcpy(n, m_data, m_length);
if (t.m_length)
memcpy(n + m_length, t.m_data, t.m_length);
m_length += t.m_length;
n[m_length] = 0;
delete [] m_data;
m_data = n;
return *this;
}
CString& CString::operator=(const char* c)
{
if (m_data)
delete [] m_data;
m_length = strlen(c);
m_data = new char[m_length + 1];
memcpy(m_data, c, m_length + 1);
return *this;
}
CString& CString::operator=(const CString& str)
{
if (this == &str)
return *this;
if (m_data)
delete [] m_data;
m_length = str.m_length;
if (str.m_data) {
m_data = new char[m_length + 1];
memcpy(m_data, str.m_data, m_length + 1);
} else
m_data = 0;
return *this;
}
bool operator==(const CString& c1, const CString& c2)
{
size_t len = c1.size();
return len == c2.size() && (len == 0 || memcmp(c1.c_str(), c2.c_str(), len) == 0);
}
// These static strings are immutable, except for rc, whose initial value is chosen to
// reduce the possibility of it becoming zero due to ref/deref not being thread-safe.
static UChar sharedEmptyChar;
@ -877,7 +788,7 @@ bool equal(const UString::Rep* r, const UString::Rep* b)
return true;
}
CString UString::UTF8String(bool strict) const
const char* UString::UTF8String(bool strict) const
{
// Allocate a buffer big enough to hold all the characters.
const int length = size();
@ -888,9 +799,9 @@ CString UString::UTF8String(bool strict) const
const UChar* d = reinterpret_cast<const UChar*>(&data()[0]);
ConversionResult result = convertUTF16ToUTF8(&d, d + length, &p, p + buffer.size(), strict);
if (result != conversionOK)
return CString();
return 0;
return CString(buffer.data(), p - buffer.data());
return buffer.data();
}
// For use in error handling code paths -- having this not be inlined helps avoid PIC branches to fetch the global on Mac OS X.

View file

@ -43,37 +43,6 @@ namespace JSC {
using WTF::PlacementNewAdoptType;
using WTF::PlacementNewAdopt;
class CString {
public:
CString()
: m_length(0)
, m_data(0)
{
}
CString(const char*);
CString(const char*, size_t);
CString(const CString&);
~CString();
static CString adopt(char*, size_t); // buffer should be allocated with new[].
CString& append(const CString&);
CString& operator=(const char* c);
CString& operator=(const CString&);
CString& operator+=(const CString& c) { return append(c); }
size_t size() const { return m_length; }
const char* c_str() const { return m_data; }
private:
size_t m_length;
char* m_data;
};
bool operator==(const CString&, const CString&);
typedef Vector<char, 32> CStringBuffer;
class UString {
@ -91,7 +60,6 @@ namespace JSC {
}
typedef UStringImpl Rep;
public:
// UString constructors passed char*s assume ISO Latin-1 encoding; for UTF8 use 'createFromUTF8', below.
UString();
UString(const char*); // Constructor for null-terminated string.
@ -162,7 +130,7 @@ namespace JSC {
* guaranteed to be otherwise valid.
* In strict mode, error is returned as null CString.
*/
CString UTF8String(bool strict = false) const;
const char* UTF8String(bool strict = false) const;
UString& operator=(const char*c);

View file

@ -832,9 +832,9 @@ JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState *exec, JSC::JSObje
#endif
JSC::UString result;
#ifndef QT_NO_QOBJECT
result = QCoreApplication::translate(context.UTF8String().c_str(),
text.UTF8String().c_str(),
comment.UTF8String().c_str(),
result = QCoreApplication::translate(context.UTF8String(),
text.UTF8String(),
comment.UTF8String(),
encoding, n);
#else
result = text;
@ -887,9 +887,9 @@ JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState *exec, JSC::JSObject*, JS
#endif
JSC::UString result;
#ifndef QT_NO_QOBJECT
result = QCoreApplication::translate(context.UTF8String().c_str(),
text.UTF8String().c_str(),
comment.UTF8String().c_str(),
result = QCoreApplication::translate(context.UTF8String(),
text.UTF8String(),
comment.UTF8String(),
QCoreApplication::UnicodeUTF8, n);
#else
result = text;
@ -916,7 +916,7 @@ JSC::JSValue JSC_HOST_CALL functionQsTrId(JSC::ExecState *exec, JSC::JSObject*,
int n = -1;
if (args.size() > 1)
n = args.at(1).toInt32(exec);
return JSC::jsString(exec, qtTrId(id.UTF8String().c_str(), n));
return JSC::jsString(exec, qtTrId(id.UTF8String(), n));
}
JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)