Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added the SplitPathFilename subroutine and unit tests
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 25 Apr 2016 23:05:39 +0000 (00:05 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 25 Apr 2016 23:05:39 +0000 (00:05 +0100)
source/common/text.cpp
source/common/text.h
source/tests/xestiacalendar_commonfunctions.h

index f6549d2..fff4c83 100644 (file)
@@ -266,4 +266,42 @@ bool IntToHex(int *Number, std::string *HexString, int HexFill){
        
        return true;
        
+}
+
+void SplitPathFilename(string *CalendarEntryHREF, string *EntryURIPath, 
+       string *EntryFilename){
+       
+       // Look for the last forward slash.
+               
+       int LastForwardSlash = -1;
+       int CharSeek = 0;
+       string StringIterChar = "";
+               
+       for (string::iterator StringIter = CalendarEntryHREF->begin();
+               StringIter != CalendarEntryHREF->end(); StringIter++){
+               
+               StringIterChar = *StringIter;
+                       
+               if (StringIterChar == "/"){
+                       LastForwardSlash = CharSeek;
+               }
+               
+               CharSeek++;
+                       
+       }
+       
+       if (LastForwardSlash == -1){
+               
+               return;
+               
+       }
+       
+       // Get the string before the last hash for the path.
+       
+       (*EntryURIPath) = CalendarEntryHREF->substr(0, (LastForwardSlash + 1));
+       
+       // Get the string after the last hash for the filename.
+       
+       (*EntryFilename) = CalendarEntryHREF->substr((LastForwardSlash + 1));
+               
 }
\ No newline at end of file
index fa74d9b..993547a 100644 (file)
@@ -22,5 +22,7 @@ std::map<std::string, std::string> SplitValues(std::string InputData);
 PropertyNameValue SplitNameValue(std::string InputData);
 bool HexToInt(std::string *HexString, int *Number);
 bool IntToHex(int *Number, std::string *HexString, int HexFill);
+void SplitPathFilename(std::string *CalendarEntryHREF, std::string *EntryURIPath, 
+       std::string *EntryFilename);
 
 #endif
\ No newline at end of file
index e667aa6..1b8af0b 100644 (file)
@@ -261,6 +261,39 @@ TEST(CommonFunctions, HexToInt){
 
 }
 
+TEST(CommonFunctions, SplitPathFilename){
+       
+       // Setup the file split.
+       
+       string PathFilenameOriginal = "/example/file/yay.txt";
+       string Path = "";
+       string File = "";
+       
+       SplitPathFilename(&PathFilenameOriginal, &Path, &File);
+       
+       ASSERT_EQ("/example/file/", Path);
+       ASSERT_EQ("yay.txt", File);
+       
+       PathFilenameOriginal = "/a/path/with/lots/of/bits/in/andthenthis.html";
+       Path.clear();
+       File.clear();
+       
+       SplitPathFilename(&PathFilenameOriginal, &Path, &File);
+       
+       ASSERT_EQ("/a/path/with/lots/of/bits/in/", Path);
+       ASSERT_EQ("andthenthis.html", File);
+
+       PathFilenameOriginal = "/one/more/for/a/laugh/hahaha.zip";
+       Path.clear();
+       File.clear();
+       
+       SplitPathFilename(&PathFilenameOriginal, &Path, &File);
+       
+       ASSERT_EQ("/one/more/for/a/laugh/", Path);
+       ASSERT_EQ("hahaha.zip", File);
+
+}
+
 TEST(CommonFunctions, ColourStruct){
        
        Colour Colour1;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy