Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/Utils.h

Issue 10897028: Create a shared dictionary class for plugin and engine (Closed)
Patch Set: Created June 7, 2013, 12:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/shared/Utils.h
===================================================================
--- a/src/shared/Utils.h
+++ b/src/shared/Utils.h
@@ -1,9 +1,25 @@
#ifndef UTILS_H
#define UTILS_H
+#include <algorithm>
+#include <locale>
+#include <functional>
#include <string>
-std::string ToUtf8String(std::wstring str);
+std::string ToUtf8String(const std::wstring& str);
+std::wstring ToUtf16String(const std::string& str);
+std::wstring GetDllDir();
std::wstring GetAppDataPath();
+template<class T>
+T TrimString(T text)
+{
+ // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
+ T trimmed(text);
+ std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_type>, std::placeholders::_1, std::locale::classic());
+ trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), std::not1(isspace)));
+ trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace)).base(), trimmed.end());
+ return trimmed;
+}
+
#endif // UTILS_H
« src/shared/Dictionary.cpp ('K') | « src/shared/Dictionary.cpp ('k') | src/shared/Utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld