TextEncoder.h 660 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright 2016 Nu-book Inc.
  3. */
  4. // SPDX-License-Identifier: Apache-2.0
  5. #pragma once
  6. #include "CharacterSet.h"
  7. #include <string>
  8. namespace ZXing {
  9. class TextEncoder
  10. {
  11. static void GetBytes(const std::string& str, CharacterSet charset, std::string& bytes);
  12. static void GetBytes(const std::wstring& str, CharacterSet charset, std::string& bytes);
  13. public:
  14. static std::string FromUnicode(const std::string& str, CharacterSet charset) {
  15. std::string r;
  16. GetBytes(str, charset, r);
  17. return r;
  18. }
  19. static std::string FromUnicode(const std::wstring& str, CharacterSet charset) {
  20. std::string r;
  21. GetBytes(str, charset, r);
  22. return r;
  23. }
  24. };
  25. } // ZXing