SHARE
TWEET

Untitled

a guest Mar 21st, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. struct TranslateStringOptions {
  3.     bool _allowCP1252 = false;
  4.     bool _allowSurrogate = false;
  5.     bool _byteSwap = false;
  6.     bool _addBOM = false;
  7.  
  8.     TranslateStringOptions &allowCP1252(bool allowCP1252_value = true) {
  9.         _allowCP1252 = allowCP1252_value;
  10.         return *this;
  11.     }
  12.     TranslateStringOptions &allowSurrogate(bool allowSurrogate_value = true) {
  13.         _allowSurrogate = allowSurrogate_value;
  14.         return *this;
  15.     }
  16.     TranslateStringOptions &byteSwap(bool byteSwap_value = true) {
  17.         _byteSwap = byteSwap_value;
  18.         return *this;
  19.     }
  20.     TranslateStringOptions &addBOM(bool addBOM_value = true) {
  21.         _addBOM = addBOM_value;
  22.         return *this;
  23.     }
  24. };
  25.  
  26. template<typename T, typename U, std::enable_if_t<sizeof(T::value_type) == sizeof(U::value_Type), int> = 0>
  27. T translateString(const T &inputString, TranslateStringOptions)
  28. {
  29.     T outputString;
  30.  
  31.     for (auto inputCharacter: inputString) {
  32.         outputString.push_back(inputCharacter);
  33.     }
  34.     return outputString;
  35. }
  36.  
  37. template<typename T, typename U, std::enable_if_t<sizeof(T::value_type) != sizeof(U::value_Type), int> = 0>
  38. T translateString(const U &inputString, TranslateStringOptions options = {})
  39. {
  40.     const auto intermediateString = translateString<std::u32string>(inputString, options);
  41.     return translateString<T>(intermediateString, options);
  42. }
  43.  
  44. template<>
  45. std::u32string translateString(const std::string &inputString, TranslateStringOptions options)
  46. {
  47.     return {};
  48. }
  49.  
  50. template<>
  51. std::u32string translateString(const std::u16string &inputString, TranslateStringOptions options)
  52. {
  53.     return {};
  54. }
  55.  
  56. template<>
  57. std::u16string translateString(const std::u32string &inputString, TranslateStringOptions options)
  58. {
  59.     return {};
  60. }
  61.  
  62. template<>
  63. std::string translateString(const std::u32string &inputString, TranslateStringOptions options)
  64. {
  65.     return {};
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top