//theSingleNode is only valid if numNodes is 1. void ConvertNodesString(const std::wstring & includedNodes, boost::uint64_t & converted, int & numNodes, int & theSingleNode) { if (includedNodes.size() != static_cast<size_t>(NUM_NODES)) { throw Dob::Typesystem::ConfigurationErrorException (L"Length of IncludedNodes string must be 64",__WFILE__,__LINE__); } converted = 0; numNodes = 0; for (std::wstring::const_reverse_iterator it = includedNodes.rbegin(); it!= includedNodes.rend();++it) { if (*it == '-') { converted = converted << 1; //add a 0 to the end } else if (*it == '+') { converted = converted << 1 | 0x1; //add a 1 to the end theSingleNode = static_cast<int>(std::distance(it,includedNodes.rend()) - 1); ++numNodes; } else { throw Dob::Typesystem::ConfigurationErrorException(L"Illegal character in IncludedNodes string (can only be + or -)",__WFILE__,__LINE__); } } }
vFindRegex::vFindRegex(std::wstring patternInput, bool recursive) { if (recursive) state = new RvFindRegex(); else state = new NRvFindRegex(); if (globalOptions::expandRegex && std::find(patternInput.begin(), patternInput.end(), L'\\') != patternInput.end()) { DWORD len = GetLongPathName(patternInput.c_str(), NULL, NULL); wchar_t *tempExpandedPath = new wchar_t[len]; GetLongPathName(patternInput.c_str(), tempExpandedPath, len); patternInput = tempExpandedPath; delete [] tempExpandedPath; } std::wstring::const_iterator middle(std::find(patternInput.rbegin(), patternInput.rend(), L'\\').base()); if (middle == patternInput.begin()) { regex = patternInput; } else { regex = std::wstring(middle, patternInput.end()); pathRoot = std::wstring(patternInput.begin(), middle); } if (!fpattern_isvalid(regex.c_str())) throw L"There is an error in the syntax of your VFIND regular expression."; stripEscapes(pathRoot); }
std::wstring wideShorten(const std::wstring &ws, size_t max_length) { std::wstring result; if (wideLength(ws) > max_length) { const size_t half_max = max_length/2 - 1; size_t len = 0; // get beginning of string for (auto it = ws.begin(); it != ws.end(); ++it) { len += wcwidth(*it); if (len > half_max) break; result += *it; } len = 0; std::wstring end; // get end of string in reverse order for (auto it = ws.rbegin(); it != ws.rend(); ++it) { len += wcwidth(*it); if (len > half_max) break; end += *it; } // apply end of string to its beginning result += L".."; result.append(end.rbegin(), end.rend()); } else result = ws; return result; }
/** * Trims the front/back of the string of whitespace */ static void trim_string(std::wstring& str) { str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](int ch) { return !std::isspace(ch); })); str.erase(std::find_if(str.rbegin(), str.rend(), [](int ch) { return !std::isspace(ch); }).base(), str.end()); }
inline std::wstring trim(const std::wstring& str) { std::wstring::const_iterator begin = std::find_if(str.begin(), str.end(), std::not1(std::ptr_fun(_istspace))); if (begin == str.end()) begin = str.begin(); std::wstring::const_reverse_iterator end = std::find_if(str.rbegin(), str.rend(), std::not1(std::ptr_fun(_istspace))); return std::wstring(begin, end.base()); }
const std::wstring tolower_and_del_delims(const std::wstring& str, const bool reverse) { std::wstring ret_str; if(reverse) { remove_copy_if(str.rbegin(), str.rend(), std::back_inserter(ret_str), is_delim); } else { remove_copy_if(str.begin(), str.end(), std::back_inserter(ret_str), is_delim); } std::transform(ret_str.begin(), ret_str.end(), ret_str.begin(), std::towlower); return ret_str; }
static std::wstring Reverse(const std::wstring &str) { // reverse the string content std::wstring tmp; tmp.reserve( str.length() ); std::wstring::const_reverse_iterator riter = str.rbegin(); for(; riter != str.rend(); riter++) { tmp += *riter; } return tmp; }
void SyntaxHighlighter::Highlight(const std::wstring& s, SyntaxHighlighter::CallbackType highlight) { if (s.empty()) return; const int length = int(s.length()); for (auto i = s.begin(); i != s.end(); ++i) { if (!u_isblank(*i)) { int wlen = int(i - s.begin()); if (wlen) highlight(0, wlen, LeadingWhitespace); break; } } for (auto i = s.rbegin(); i != s.rend(); ++i) { if (!u_isblank(*i)) { int wlen = int(i - s.rbegin()); if (wlen) highlight(length - wlen, length, LeadingWhitespace); break; } } for (auto i = s.begin(); i != s.end(); ++i) { if (*i == '\\') { int pos = int(i - s.begin()); if (++i == s.end()) break; // TODO: highlight full syntax, incl. octals: http://en.cppreference.com/w/cpp/language/escape switch (*i) { case '0': case 'n': case 'r': case 't': case '"': case '\\': highlight(pos, pos + 2, Escape); break; default: break; } } } }
/** * Trims the specified character from the back of the string */ static void right_trim_string(std::wstring& str, wchar_t c) { str.erase(std::find_if(str.rbegin(), str.rend(), [c](const wchar_t& ch) { return ch != c; }).base(), str.end()); }
std::wstring TrimEnd(std::wstring s) { s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); return s; }