template <typename TEnco, typename TChar = typename Text::Encoding::CodeUnit<TEnco>::codeunit> class StringBase {
public:
template <typename TOtherEnc, TOtherChar> friend class StringBase<TOtherEnc, TOtherChar>;
typedef TEnco TEncoding;
typedef TChar TCodeUnit;
typedef basic_string<TChar> TStd;
typedef TStd TStorage;
typedef DecoderIterator<TEncoding, typename TStorage::iterator> TIterator;
typedef DecoderIterator<TEncoding, typename TStorage::const_iterator> TConstIterator;
typedef TIterator iterator;
typedef TConstIterator const_iterator;
protected:
static TEncoding encoding;
TStorage codeunitstorage;
public:
const static StringBase Empty;
StringBase ( ) : codeunitstorage( ) {
}
StringBase ( charcodepoint* codepoints ) : StringBase( codepoints, std::char_traits<charcodepoint>::length( codepoints ) ) {
}
StringBase ( charcodepoint* codepoints, lword count ) : codeunitstorage( encoding.GetMaxCount( codepoints, count ), '\0' ) {
codeunitstorage.resize( encoding.GetEncoded( codepoints, count, (TChar*)codeunitstorage.data(), codeunitstorage.size( ) ) );
}
template < typename tcharcodepoint = TChar >
StringBase ( TChar* value ) : StringBase( value, std::char_traits<TChar>::length( value ) ) {
}
template < typename tcharcodepoint = TChar >
StringBase ( TChar* value, lword count ) : codeunitstorage( characters, characters + count ) {
}
StringBase ( TStorage&& codeunitstorage ) : codeunitstorage( codeunitstorage ) {
}
StringBase ( TStorage codeunitstorage ) : codeunitstorage( std::move( codeunitstorage ) ) {
}
StringBase ( const TStorage& codeunitstorage ) : codeunitstorage( codeunitstorage ) {
}
StringBase ( const StringBase<TEnco, TChar>& other ) : codeunitstorage( other.codeunitstorage ) {
}
StringBase ( StringBase<TEnco, TChar>&& other ) : codeunitstorage( other.codeunitstorage ) {
}
template <typename TOtherEnco, typename TOtherChar>
StringBase ( const StringBase<TOtherEnco, TOtherChar>& other ) : codeunitstorage( encoding.GetMaxCount( other.Length() ), '\0' ) {
std::vector<charcodepoint> codepoints = other.encoding.GetDecoded( (TOtherChar*)other.Storage().data(), other.Storage().size() );
codeunitstorage.resize( encoding.GetDecoded( codepoints.data(), codepoints.size(), codeunitstorage.data( ), codeunitstorage.size( ) ) )
}
iterator begin () {
return iterator( codeunitstorage.begin(), codeunitstorage.end() );
}
iterator end () {
return iterator( codeunitstorage.end(), codeunitstorage.end() );
}
const_iterator begin () const {
return const_iterator( codeunitstorage.begin(), codeunitstorage.end() );
}
const_iterator end () const {
return const_iterator( codeunitstorage.end(), codeunitstorage.end() );
}
const TChar* Data () const {
return codeunitstorage.data();
}
const TStorage& Storage () const {
return codeunitstorage;
}
TStorage&& MoveStorage () {
return std::move( codeunitstorage );
}
};