StringUtil.h 986 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Copyright (c) 2014 ownCloud GmbH. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; version 2.1 of the License
  7. *
  8. * This library is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  11. * details.
  12. */
  13. #ifndef STRINGUTIL_H
  14. #define STRINGUTIL_H
  15. #pragma once
  16. #include <string>
  17. class __declspec(dllexport) StringUtil {
  18. public:
  19. static std::string toUtf8(const wchar_t* utf16, int len = -1);
  20. static std::wstring toUtf16(const char* utf8, int len = -1);
  21. template<class T>
  22. static bool begins_with(const T& input, const T& match)
  23. {
  24. return input.size() >= match.size()
  25. && std::equal(match.begin(), match.end(), input.begin());
  26. }
  27. };
  28. #endif // STRINGUTIL_H