2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 * @author Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
24 #include <dpl/exception.h>
25 #include <dpl/char_traits.h>
32 typedef std::basic_string<wchar_t, CharTraits> String;
34 // @brief String exception class
38 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
40 // @brief Invalid init for UTF8 to UTF32 converter
41 DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF8ToUTF32)
43 // @brief Invalid taStdContainerinit for UTF32 to UTF32 converter
44 DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF32ToUTF8)
46 // @brief Invalid conversion for UTF8 to UTF32 converter
47 DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF8ToUTF32)
49 // @brief Invalid conversion for UTF8 to UTF32 converter
50 DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF32ToUTF8)
52 // @brief Invalid ASCII character detected in FromASCII
53 DECLARE_EXCEPTION_TYPE(Base, InvalidASCIICharacter)
55 // @brief Invalid ASCII character detected in FromASCII
56 DECLARE_EXCEPTION_TYPE(Base, ICUInvalidCharacterFound)
59 //!\brief convert ASCII string to DPL::String
60 String FromASCIIString(const std::string& aString);
62 //!\brief convert UTF32 string to DPL::String
63 String FromUTF32String(const std::wstring& aString);
65 //@brief Returns String object created from UTF8 string
66 //@param[in] aString input UTF-8 string
67 String FromUTF8String(const std::string& aString);
69 //@brief Returns String content as std::string
70 std::string ToUTF8String(const String& aString);
72 //@brief Compare two unicode strings
73 int StringCompare(const String &left,
75 bool caseInsensitive = false);
77 //@brief Splits the string into substrings.
78 //@param[in] str Input string
79 //@param[in] delimiters array or string containing a sequence of substring delimiters. Can be also a single delimiter character.
80 //@param[in] it InserterIterator that is used to save the generated substrings.
81 template<typename StringType, typename Delimiters, typename InserterIterator>
82 void Tokenize(const StringType& str, const Delimiters& delimiters, InserterIterator it, bool ignoreEmpty = false)
84 typename StringType::size_type nextSearchStart = 0;
85 typename StringType::size_type pos;
86 typename StringType::size_type length;
90 pos = str.find_first_of(delimiters, nextSearchStart);
91 length = ((pos == StringType::npos) ? str.length() : pos) - nextSearchStart;
93 if ( !ignoreEmpty || length > 0 )
95 *it = str.substr(nextSearchStart, length);
99 if ( pos == StringType::npos )
102 nextSearchStart = pos + 1;
108 std::ostream& operator<<(std::ostream& aStream, const DPL::String& aString);