aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes/MCString.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/basetypes/MCString.cpp')
-rw-r--r--src/core/basetypes/MCString.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/core/basetypes/MCString.cpp b/src/core/basetypes/MCString.cpp
index c17c7074..b3beeb40 100644
--- a/src/core/basetypes/MCString.cpp
+++ b/src/core/basetypes/MCString.cpp
@@ -1184,6 +1184,9 @@ Data * String::encodedMIMEHeaderValueForSubject()
int String::compareWithCaseSensitive(String * otherString, bool caseSensitive)
{
+ if ((length() == 0) && (otherString->length() == 0)) {
+ return 0;
+ }
if ((unicodeCharacters() == NULL) && (otherString->unicodeCharacters() != NULL)) {
return 0;
}
@@ -1486,6 +1489,17 @@ int String::locationOfString(String * occurrence)
return (int) (location - mUnicodeChars);
}
+int String::lastLocationOfString(String * occurrence)
+{
+ UChar * location;
+ location = u_strrstr(mUnicodeChars, occurrence->unicodeCharacters());
+ if (location == NULL) {
+ return -1;
+ }
+
+ return (int) (location - mUnicodeChars);
+}
+
#pragma mark strip HTML
struct parserState {
@@ -2143,10 +2157,37 @@ String * String::stringByAppendingPathComponent(String * component)
String * String::stringByDeletingLastPathComponent()
{
- String * component = lastPathComponent();
- String * result = (String *) this->copy()->autorelease();
- result->deleteCharactersInRange(RangeMake(result->length() - component->length(), component->length()));
- return result;
+ String * currentString = this;
+ if (currentString->isEqual(MCSTR("/"))) {
+ return currentString;
+ }
+ if (currentString->length() == 0) {
+ return currentString;
+ }
+ if (currentString->unicodeCharacters()[currentString->length() - 1] == '/') {
+ currentString = currentString->substringToIndex(currentString->length() - 1);
+ }
+ String * component = currentString->lastPathComponent();
+ currentString = currentString->substringToIndex(currentString->length() - component->length());
+ if (currentString->isEqual(MCSTR("/"))) {
+ return currentString;
+ }
+ if (currentString->length() == 0) {
+ return currentString;
+ }
+ if (currentString->unicodeCharacters()[currentString->length() - 1] == '/') {
+ currentString = currentString->substringToIndex(currentString->length() - 1);
+ }
+ return currentString;
+}
+
+String * String::stringByDeletingPathExtension()
+{
+ int location = lastLocationOfString(MCSTR("."));
+ if ((location == -1) || (location == 0)) {
+ return this;
+ }
+ return substringToIndex(location);
}
Array * String::componentsSeparatedByString(String * separator)