2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/text/text-impl.h>
23 #include <dali/internal/common/text-array.h>
24 #include <dali/internal/event/text/character-impl.h>
25 #include <dali/internal/event/text/utf8-impl.h>
38 Text::Text( const std::string& text )
43 // minimize allocations for ascii strings
44 mString.reserve( text.size() );
46 // break string into UTF-8 tokens
47 UTF8Tokenize( reinterpret_cast<const unsigned char*>( text.c_str() ), text.size(), mString );
51 Text::Text( const Character& character )
54 mString.push_back( character.GetCharacter() );
57 Text::Text( const Text& text )
58 : mString( text.mString )
62 void Text::GetText( std::string& text ) const
64 // minimize allocations for ascii strings
65 text.reserve( mString.size() );
67 for( TextArray::const_iterator it = mString.begin(), endIt = mString.end(); it != endIt; ++it )
69 unsigned char utf8Data[4];
70 unsigned int utf8Length;
72 utf8Length = UTF8Write( *it, utf8Data );
74 text.append( reinterpret_cast<const char*>( utf8Data ), utf8Length );
78 void Text::SetText( const Text& text )
80 mString = text.mString;
83 Text& Text::operator=( const Text& text )
85 mString = text.mString;
95 Dali::Character Text::operator[]( size_t position ) const
97 DALI_ASSERT_ALWAYS( position < mString.size() && "Text::operator[]: Character position is out of bounds" );
99 const uint32_t c = *( mString.begin() + position );
101 Dali::Character character( new Character( c ) );
106 bool Text::IsEmpty() const
108 return mString.empty();
111 size_t Text::GetLength() const
113 return mString.size();
116 void Text::Append( const Dali::Text& text )
118 const TextArray& utfCodes = text.GetImplementation().GetTextArray();
120 mString.insert( mString.end(), utfCodes.begin(), utfCodes.end() );
123 void Text::Remove( size_t position, size_t numberOfCharacters )
125 if( numberOfCharacters == 0 )
127 DALI_ASSERT_DEBUG( ( numberOfCharacters != 0 ) && ( "Text::Remove: numberOfCharacters is zero." ) );
130 DALI_ASSERT_ALWAYS( position < mString.size() && "Text::Remove: Character position is out of bounds" );
131 DALI_ASSERT_ALWAYS( position + numberOfCharacters <= mString.size() && "Text::Remove: Character position + numberOfCharacters is out of bounds" );
133 mString.erase( mString.begin() + position, mString.begin() + position + numberOfCharacters );
136 void Text::SetTextArray( const TextArray& textArray )
141 void Text::GetTextArray( TextArray& textArray ) const
146 const TextArray& Text::GetTextArray() const
151 } // namespace Internal