comparison Core/Toolbox.cpp @ 608:0bedf8ff9288 find-move-scp

basic find scp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2013 18:07:55 +0200
parents 2737806bcf60
children dc12a3fa4961
comparison
equal deleted inserted replaced
606:ce5d2040c47b 608:0bedf8ff9288
40 #include <boost/filesystem/fstream.hpp> 40 #include <boost/filesystem/fstream.hpp>
41 #include <boost/date_time/posix_time/posix_time.hpp> 41 #include <boost/date_time/posix_time/posix_time.hpp>
42 #include <boost/uuid/sha1.hpp> 42 #include <boost/uuid/sha1.hpp>
43 #include <algorithm> 43 #include <algorithm>
44 #include <ctype.h> 44 #include <ctype.h>
45 #include <boost/regex.hpp>
45 46
46 #if defined(_WIN32) 47 #if defined(_WIN32)
47 #include <windows.h> 48 #include <windows.h>
48 #endif 49 #endif
49 50
724 725
725 default: 726 default:
726 throw OrthancException(ErrorCode_NotImplemented); 727 throw OrthancException(ErrorCode_NotImplemented);
727 } 728 }
728 } 729 }
730
731
732 std::string Toolbox::WildcardToRegularExpression(const std::string& source)
733 {
734 // TODO - Speed up this with a regular expression
735
736 std::string result = source;
737
738 // Escape all special characters
739 boost::replace_all(result, "\\", "\\\\");
740 boost::replace_all(result, "^", "\\^");
741 boost::replace_all(result, ".", "\\.");
742 boost::replace_all(result, "$", "\\$");
743 boost::replace_all(result, "|", "\\|");
744 boost::replace_all(result, "(", "\\(");
745 boost::replace_all(result, ")", "\\)");
746 boost::replace_all(result, "[", "\\[");
747 boost::replace_all(result, "]", "\\]");
748 boost::replace_all(result, "+", "\\+");
749 boost::replace_all(result, "/", "\\/");
750 boost::replace_all(result, "{", "\\{");
751 boost::replace_all(result, "}", "\\}");
752
753 // Convert wildcards '*' and '?' to their regex equivalents
754 boost::replace_all(result, "?", ".");
755 boost::replace_all(result, "*", ".*");
756
757 return result;
758 }
759
760
761
762 void Toolbox::TokenizeString(std::vector<std::string>& result,
763 const std::string& value,
764 char separator)
765 {
766 result.clear();
767
768 std::string currentItem;
769
770 for (size_t i = 0; i < value.size(); i++)
771 {
772 if (value[i] == separator)
773 {
774 result.push_back(currentItem);
775 currentItem.clear();
776 }
777 else
778 {
779 currentItem.push_back(value[i]);
780 }
781 }
782
783 result.push_back(currentItem);
784 }
729 } 785 }
786