00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "debug/Log.h"
00019 #include "StringUtils.h"
00020
00021 namespace oasys {
00022
00023 int
00024 tokenize(const std::string& str,
00025 const std::string& sep,
00026 std::vector<std::string>* tokens)
00027 {
00028 size_t start, end;
00029
00030 tokens->clear();
00031
00032 start = str.find_first_not_of(sep);
00033 if (start == std::string::npos || start == str.length()) {
00034 return 0;
00035 }
00036
00037 while (1) {
00038 end = str.find_first_of(sep, start);
00039 if (end == std::string::npos) {
00040 end = str.length();
00041 }
00042
00043 tokens->push_back(str.substr(start, end - start));
00044
00045 if (end == str.length()) {
00046 break;
00047 }
00048
00049 start = str.find_first_not_of(sep, end);
00050 if (start == std::string::npos) {
00051 break;
00052 }
00053 }
00054
00055 return tokens->size();
00056 }
00057
00058 void
00059 StringSet::dump(const char* log) const
00060 {
00061 logf(log, LOG_DEBUG, "dumping string set...");
00062 for (iterator i = begin(); i != end(); ++i) {
00063 logf(log, LOG_DEBUG, "\t%s", i->c_str());
00064 }
00065 }
00066
00067 void
00068 StringHashSet::dump(const char* log) const
00069 {
00070 logf(log, LOG_DEBUG, "dumping string set...");
00071 for (iterator i = begin(); i != end(); ++i) {
00072 logf(log, LOG_DEBUG, "\t%s", i->c_str());
00073 }
00074 }
00075
00076
00077 const char*
00078 bool_to_str(bool b)
00079 {
00080 if (b)
00081 {
00082 return "true";
00083 }
00084
00085 return "false";
00086 }
00087
00088
00089 const char*
00090 str_if(bool b, const char* true_str, const char* false_str)
00091 {
00092 if (b)
00093 {
00094 return true_str;
00095 }
00096 else
00097 {
00098 return false_str;
00099 }
00100 }
00101
00102 }