aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes/MCString.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/basetypes/MCString.cc')
-rw-r--r--src/core/basetypes/MCString.cc54
1 files changed, 49 insertions, 5 deletions
diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc
index 054cbb80..5c2da323 100644
--- a/src/core/basetypes/MCString.cc
+++ b/src/core/basetypes/MCString.cc
@@ -761,6 +761,9 @@ String * String::string()
String * String::stringWithData(Data * data, const char * charset)
{
+ if (data == NULL) {
+ return String::string();
+ }
String * result = NULL;
result = new String(data->bytes(), data->length(), charset);
result->autorelease();
@@ -807,6 +810,9 @@ String * String::stringWithCharacters(const UChar * characters, unsigned int len
void String::appendCharactersLength(const UChar * unicodeCharacters, unsigned int length)
{
+ if (unicodeCharacters == NULL) {
+ return;
+ }
allocate(mLength + length);
u_strncpy(&mUnicodeChars[mLength], unicodeCharacters, length);
mLength += length;
@@ -815,6 +821,9 @@ void String::appendCharactersLength(const UChar * unicodeCharacters, unsigned in
void String::appendString(String * otherString)
{
+ if (otherString == NULL) {
+ return;
+ }
appendCharactersLength(otherString->unicodeCharacters(), otherString->length());
}
@@ -831,8 +840,9 @@ void String::appendUTF8Format(const char * format, ...)
void String::appendUTF8CharactersLength(const char * UTF8Characters, unsigned int length)
{
- if (UTF8Characters == NULL)
+ if (UTF8Characters == NULL) {
return;
+ }
UChar * dest;
int32_t destLength;
@@ -1124,6 +1134,10 @@ String * String::uppercaseString()
void String::appendBytes(const char * bytes, unsigned int length, const char * charset)
{
+ if (bytes == NULL) {
+ return;
+ }
+
#if __APPLE__
CFStringEncoding encoding;
if (strcasecmp(charset, "mutf-7") == 0) {
@@ -1138,7 +1152,16 @@ void String::appendBytes(const char * bytes, unsigned int length, const char * c
if (cfStr != NULL) {
CFDataRef data = CFStringCreateExternalRepresentation(NULL, cfStr, kCFStringEncodingUTF16LE, '_');
if (data != NULL) {
- appendCharactersLength((const UChar *) CFDataGetBytePtr(data), (unsigned int) CFDataGetLength(data) / 2);
+ UChar * fixedData = (UChar *) malloc(CFDataGetLength(data));
+ memcpy(fixedData, CFDataGetBytePtr(data), CFDataGetLength(data));
+ unsigned int length = (unsigned int) CFDataGetLength(data) / 2;
+ for(int32_t i = 0 ; i < length ; i ++) {
+ if (fixedData[i] == 0) {
+ fixedData[i] = ' ';
+ }
+ }
+ appendCharactersLength(fixedData, length);
+ free(fixedData);
CFRelease(data);
}
CFRelease(cfStr);
@@ -1269,7 +1292,10 @@ void String::deleteCharactersInRange(Range range)
if (range.location > mLength)
return;
- if (range.location + range.length > mLength) {
+ if (range.length > mLength) {
+ range.length = mLength - range.location;
+ }
+ else if (range.location + range.length > mLength) {
range.length = mLength - range.location;
}
@@ -1795,6 +1821,24 @@ String * String::flattenHTML()
return flattenHTMLAndShowBlockquote(true);
}
+String * String::stripWhitespace()
+{
+ String *str = (String *)copy();
+
+ str->replaceOccurrencesOfString(MCSTR("\t"), MCSTR(" "));
+ str->replaceOccurrencesOfString(MCSTR("\n"), MCSTR(" "));
+ str->replaceOccurrencesOfString(MCSTR("\v"), MCSTR(" "));
+ str->replaceOccurrencesOfString(MCSTR("\f"), MCSTR(" "));
+ str->replaceOccurrencesOfString(MCSTR("\r"), MCSTR(" "));
+
+ while (str->replaceOccurrencesOfString(MCSTR(" "), MCSTR(" ")) > 0) {
+ /* do nothing */
+ }
+
+ return str;
+}
+
+
bool String::hasSuffix(String * suffix)
{
if (mLength >= suffix->mLength) {
@@ -2187,9 +2231,9 @@ String * String::htmlMessageContent()
}
}
- if (quoted != nil) {
+ if (quoted != NULL) {
localString->appendString(MCSTR("<blockquote type=\"cite\">"));
- localString->appendString(quoted);
+ localString->appendString(quoted->htmlMessageContent());
localString->appendString(MCSTR("</blockquote>"));
MC_SAFE_RELEASE(quoted);
}