aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-10-25 09:12:24 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-10-25 09:12:24 -0700
commitcd37682217b0dafacfe02a3a3d64e2c80a329cce (patch)
treef241bc5de3a9855d1a94d9be80b8798b7ad37a69 /src/core/basetypes
parent128a11a36103c3a57372cf72a51e52744524d827 (diff)
parent386f84abe048c4b37cef42195d612b480021df3f (diff)
Merge branch 'master' into removing-icu-dependency
Diffstat (limited to 'src/core/basetypes')
-rw-r--r--src/core/basetypes/MCData.cc12
-rw-r--r--src/core/basetypes/MCData.h8
-rw-r--r--src/core/basetypes/MCDataMac.mm22
-rw-r--r--src/core/basetypes/MCString.cc6
4 files changed, 46 insertions, 2 deletions
diff --git a/src/core/basetypes/MCData.cc b/src/core/basetypes/MCData.cc
index 13c5fd61..5f2282d9 100644
--- a/src/core/basetypes/MCData.cc
+++ b/src/core/basetypes/MCData.cc
@@ -68,6 +68,7 @@ Data::Data(const char * bytes, unsigned int length)
{
mBytes = NULL;
reset();
+ allocate(length);
appendBytes(bytes, length);
}
@@ -482,6 +483,13 @@ String * Data::charsetWithFilteredHTML(bool filterHTML, String * hintCharset)
#endif
}
+void Data::replaceWithAllocatedBytes(char * bytes, unsigned int length)
+{
+ free(mBytes);
+ mBytes = (char *) bytes;
+ mLength = length;
+}
+
Data * Data::dataWithContentsOfFile(String * filename)
{
int r;
@@ -511,8 +519,8 @@ Data * Data::dataWithContentsOfFile(String * filename)
return NULL;
}
- data = Data::dataWithBytes(buf, (unsigned int) stat_buf.st_size);
- free(buf);
+ data = Data::data();
+ data->replaceWithAllocatedBytes(buf, (unsigned int) stat_buf.st_size);
fclose(f);
diff --git a/src/core/basetypes/MCData.h b/src/core/basetypes/MCData.h
index 6ba056e7..131cb722 100644
--- a/src/core/basetypes/MCData.h
+++ b/src/core/basetypes/MCData.h
@@ -5,6 +5,10 @@
#include <MailCore/MCObject.h>
#include <MailCore/MCMessageConstants.h>
+#ifdef __APPLE__
+#import <CoreFoundation/CoreFoundation.h>
+#endif
+
#ifdef __cplusplus
namespace mailcore {
@@ -41,6 +45,9 @@ namespace mailcore {
public: // private
virtual String * charsetWithFilteredHTML(bool filterHTML, String * hintCharset = NULL);
+#ifdef __APPLE__
+ virtual CFDataRef destructiveNSData();
+#endif
public: // subclass behavior
Data(Data * otherData);
@@ -58,6 +65,7 @@ namespace mailcore {
void allocate(unsigned int length);
void reset();
String * charsetWithFilteredHTMLWithoutHint(bool filterHTML);
+ void replaceWithAllocatedBytes(char * bytes, unsigned int length);
};
diff --git a/src/core/basetypes/MCDataMac.mm b/src/core/basetypes/MCDataMac.mm
new file mode 100644
index 00000000..8081b1f9
--- /dev/null
+++ b/src/core/basetypes/MCDataMac.mm
@@ -0,0 +1,22 @@
+//
+// MCDataMac.m
+// mailcore2
+//
+// Created by Hoa V. DINH on 10/24/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#include "MCData.h"
+
+#import <Foundation/Foundation.h>
+
+using namespace mailcore;
+
+CFDataRef Data::destructiveNSData()
+{
+ NSData * result = [NSData dataWithBytesNoCopy:(void *) mBytes length:mLength];
+ mBytes = NULL;
+ mAllocated = 0;
+ mLength = 0;
+ return (CFDataRef) result;
+}
diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc
index de975d44..a122c1e6 100644
--- a/src/core/basetypes/MCString.cc
+++ b/src/core/basetypes/MCString.cc
@@ -753,6 +753,9 @@ String::String(const UChar * unicodeChars)
{
mUnicodeChars = NULL;
reset();
+ if (unicodeChars != NULL) {
+ allocate(u_strlen(unicodeChars));
+ }
appendCharacters(unicodeChars);
}
@@ -760,6 +763,7 @@ String::String(const UChar * unicodeChars, unsigned int length)
{
mUnicodeChars = NULL;
reset();
+ allocate(length);
appendCharactersLength(unicodeChars, length);
}
@@ -788,6 +792,7 @@ String::String(const char * bytes, unsigned int length, const char * charset)
{
mUnicodeChars = NULL;
reset();
+ allocate(length);
if (charset == NULL) {
appendUTF8CharactersLength(bytes, length);
}
@@ -1966,6 +1971,7 @@ String * String::stripWhitespace()
/* do nothing */
}
+ str->autorelease();
return str;
}