fork download
  1. template <typename TEnco, typename TChar = typename Text::Encoding::CodeUnit<TEnco>::codeunit> class StringBase {
  2. public:
  3. template <typename TOtherEnc, TOtherChar> friend class StringBase<TOtherEnc, TOtherChar>;
  4. typedef TEnco TEncoding;
  5. typedef TChar TCodeUnit;
  6. typedef basic_string<TChar> TStd;
  7. typedef TStd TStorage;
  8. typedef DecoderIterator<TEncoding, typename TStorage::iterator> TIterator;
  9. typedef DecoderIterator<TEncoding, typename TStorage::const_iterator> TConstIterator;
  10. typedef TIterator iterator;
  11. typedef TConstIterator const_iterator;
  12.  
  13. protected:
  14. static TEncoding encoding;
  15. TStorage codeunitstorage;
  16.  
  17. public:
  18. const static StringBase Empty;
  19.  
  20. StringBase ( ) : codeunitstorage( ) {
  21.  
  22. }
  23.  
  24. StringBase ( charcodepoint* codepoints ) : StringBase( codepoints, std::char_traits<charcodepoint>::length( codepoints ) ) {
  25.  
  26. }
  27.  
  28. StringBase ( charcodepoint* codepoints, lword count ) : codeunitstorage( encoding.GetMaxCount( codepoints, count ), '\0' ) {
  29. codeunitstorage.resize( encoding.GetEncoded( codepoints, count, (TChar*)codeunitstorage.data(), codeunitstorage.size( ) ) );
  30. }
  31.  
  32. template < typename tcharcodepoint = TChar >
  33. StringBase ( TChar* value ) : StringBase( value, std::char_traits<TChar>::length( value ) ) {
  34.  
  35. }
  36.  
  37. template < typename tcharcodepoint = TChar >
  38. StringBase ( TChar* value, lword count ) : codeunitstorage( characters, characters + count ) {
  39.  
  40. }
  41.  
  42. StringBase ( TStorage&& codeunitstorage ) : codeunitstorage( codeunitstorage ) {
  43.  
  44. }
  45.  
  46. StringBase ( TStorage codeunitstorage ) : codeunitstorage( std::move( codeunitstorage ) ) {
  47.  
  48. }
  49.  
  50. StringBase ( const TStorage& codeunitstorage ) : codeunitstorage( codeunitstorage ) {
  51.  
  52. }
  53.  
  54. StringBase ( const StringBase<TEnco, TChar>& other ) : codeunitstorage( other.codeunitstorage ) {
  55.  
  56. }
  57.  
  58. StringBase ( StringBase<TEnco, TChar>&& other ) : codeunitstorage( other.codeunitstorage ) {
  59.  
  60. }
  61.  
  62. template <typename TOtherEnco, typename TOtherChar>
  63. StringBase ( const StringBase<TOtherEnco, TOtherChar>& other ) : codeunitstorage( encoding.GetMaxCount( other.Length() ), '\0' ) {
  64. std::vector<charcodepoint> codepoints = other.encoding.GetDecoded( (TOtherChar*)other.Storage().data(), other.Storage().size() );
  65. codeunitstorage.resize( encoding.GetDecoded( codepoints.data(), codepoints.size(), codeunitstorage.data( ), codeunitstorage.size( ) ) )
  66. }
  67.  
  68. iterator begin () {
  69. return iterator( codeunitstorage.begin(), codeunitstorage.end() );
  70. }
  71.  
  72. iterator end () {
  73. return iterator( codeunitstorage.end(), codeunitstorage.end() );
  74. }
  75.  
  76. const_iterator begin () const {
  77. return const_iterator( codeunitstorage.begin(), codeunitstorage.end() );
  78. }
  79.  
  80. const_iterator end () const {
  81. return const_iterator( codeunitstorage.end(), codeunitstorage.end() );
  82. }
  83.  
  84. const TChar* Data () const {
  85. return codeunitstorage.data();
  86. }
  87.  
  88. const TStorage& Storage () const {
  89. return codeunitstorage;
  90. }
  91.  
  92. TStorage&& MoveStorage () {
  93. return std::move( codeunitstorage );
  94. }
  95. };
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty