2 // Copyright (c) 2012 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.
18 * @file FText_EncodingImpl.cpp
19 * @brief This is the implementation file for _EncodingImpl class.
22 #include <FBaseResult.h>
23 #include "FText_EncodingCore.h"
24 #include <FBaseSysLog.h>
25 #include "FText_EncodingImpl.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
31 #define AVAILABLE_ENCODING_COUNT 45
32 static String availableEncodings[] =
81 namespace Tizen { namespace Text
84 _EncodingImpl::_EncodingImpl(void)
87 , __pEncodingCore(null)
91 _EncodingImpl::~_EncodingImpl(void)
97 _EncodingImpl::Construct(const String& encodingType)
99 // Object is not allowed to construct twice
100 SysAssertf(__pEncodingCore == null,
101 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
103 SysTryReturnResult(NID_TEXT, IsEncodingSupported(encodingType),
104 E_UNSUPPORTED_TYPE, "[%s] encodingType[%ls] is not supported", GetErrorMessage(E_UNSUPPORTED_TYPE), encodingType.GetPointer());
106 __pEncodingCore.reset(_EncodingCore::GetEncodingCoreN(encodingType, L"WCHAR_T"));
108 result r = GetLastResult();
109 SysTryReturnResult(NID_TEXT, (__pEncodingCore != null), r, "[%s] Failed to open encoder/decoder.", GetErrorMessage(r));
111 __encodingType = encodingType;
112 _pEncodingImpl = this;
118 _EncodingImpl::Encode(const wchar_t* pSrc, int srcLength, ByteBuffer*& pByteBuffer, int index) const
120 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
122 SysTryReturnResult(NID_TEXT, (pSrc != null), E_INVALID_ARG, "[%s] Invalid argument is used. pSrc can not be null.", GetErrorMessage(E_INVALID_ARG));
123 SysTryReturnResult(NID_TEXT, (srcLength >= 0), E_INVALID_ARG,
124 "[%s] Invalid argument is used. srcLength(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), srcLength);
125 SysTryReturnResult(NID_TEXT, (index >= 0), E_INVALID_ARG,
126 "[%s] Invalid argument is used. index(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), index);
128 result r = E_SUCCESS;
129 int currPosition = 0;
131 bool isMemAllocReq = false;
133 std::unique_ptr<byte[]> pDst(__pEncodingCore->EncodeN(pSrc, srcLength, retLength));
135 SysTryReturnResult(NID_TEXT, (pDst != null), r, "[%s] Encoding failed", GetErrorMessage(r));
137 ByteBuffer* pOutBuffer = pByteBuffer;
140 if (pOutBuffer == null)
142 isMemAllocReq = true;
143 pOutBuffer = new (std::nothrow) ByteBuffer;
144 SysTryCatch(NID_TEXT, (pOutBuffer != null), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
146 r = pOutBuffer->Construct(retLength + 1);
147 SysTryCatch(NID_TEXT, !IsFailed(r), , r, "[%s] Unable to Construct Byte buffer", GetErrorMessage(r));
149 pByteBuffer = pOutBuffer;
153 currPosition = pOutBuffer->GetPosition();
155 r = pOutBuffer->SetPosition(index);
156 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
158 r = pOutBuffer->SetArray(pDst.get(), 0, retLength);
159 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
161 r = pOutBuffer->SetPosition(currPosition);
162 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
177 _EncodingImpl::Decode(const byte* pSrc, int srcLength, WcharBuffer*& pWcharBuffer, int index) const
179 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
181 SysTryReturnResult(NID_TEXT, (pSrc != null), E_INVALID_ARG, "[%s] Invalid argument is used. pSrc can not be null.", GetErrorMessage(E_INVALID_ARG));
182 SysTryReturnResult(NID_TEXT, (srcLength >= 0), E_INVALID_ARG,
183 "[%s] Invalid argument is used. srcLength(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), srcLength);
184 SysTryReturnResult(NID_TEXT, (index >= 0), E_INVALID_ARG,
185 "[%s] Invalid argument is used. index(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), index);
187 result r = E_SUCCESS;
188 int currPosition = 0;
190 bool isMemAllocReq = false;
192 std::unique_ptr<wchar_t[]> pDst(__pEncodingCore->DecodeN(pSrc, srcLength, retLength));
194 SysTryReturnResult(NID_TEXT, (pDst != null), r, "[%s] Decoding failed", GetErrorMessage(r));
196 WcharBuffer* pOutBuffer = pWcharBuffer;
199 if (pOutBuffer == null)
201 isMemAllocReq = true;
202 pOutBuffer = new (std::nothrow) WcharBuffer;
203 SysTryCatch(NID_TEXT, (pOutBuffer != null), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
205 r = pOutBuffer->Construct(retLength + 1);
206 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to Construct Byte buffer", GetErrorMessage(r));
208 r = pOutBuffer->SetArray(pDst.get(), 0, retLength);
209 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
211 r = pOutBuffer->Set(L'\0');
212 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set null Byte", GetErrorMessage(r));
214 pOutBuffer->Rewind();
215 pWcharBuffer = pOutBuffer;
219 currPosition = pOutBuffer->GetPosition();
221 r = pOutBuffer->SetPosition(index);
222 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
224 r = pOutBuffer->SetArray(pDst.get(), 0, retLength);
225 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
227 r = pOutBuffer->SetPosition(currPosition);
228 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
243 _EncodingImpl::Decode(const byte* pSrc, int srcLength, String& outStr, int index) const
245 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
247 SysTryReturnResult(NID_TEXT, (pSrc != null), E_INVALID_ARG, "[%s] Invalid argument is used. pSrc can not be null.", GetErrorMessage(E_INVALID_ARG));
248 SysTryReturnResult(NID_TEXT, (srcLength >= 0), E_INVALID_ARG,
249 "[%s] Invalid argument is used. srcLength(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), srcLength);
250 SysTryReturnResult(NID_TEXT, (index >= 0), E_INVALID_ARG,
251 "[%s] Invalid argument is used. index(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), index);
253 result r = E_SUCCESS;
256 std::unique_ptr<wchar_t[]> pDst(__pEncodingCore->DecodeN(pSrc, srcLength, retLength));
258 SysTryReturnResult(NID_TEXT, (pDst != null), r, "[%s] Decoding failed", GetErrorMessage(r));
266 _EncodingImpl::GetByteCount(const String& str, int& byteCount) const
268 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
271 int srcLength = str.GetLength();
272 SysTryReturnResult(NID_TEXT, (srcLength > 0), E_INVALID_ARG,
273 "[%s] Invalid argument is used. Input string is empty.", GetErrorMessage(E_INVALID_ARG));
275 return __pEncodingCore->GetByteCount(str.GetPointer(), srcLength, byteCount);
279 _EncodingImpl::GetByteCount(const WcharBuffer& chars, int& byteCount) const
281 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
285 result r = GetBufferSize(chars, srcLength);
286 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
288 return __pEncodingCore->GetByteCount(chars.GetPointer(), srcLength, byteCount);
292 _EncodingImpl::GetByteCount(const WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const
294 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
297 int inBufSize = chars.GetLimit();
298 result r = CheckBufferInput(inBufSize, charIndex, charCount);
299 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
301 return __pEncodingCore->GetByteCount((chars.GetPointer() + charIndex), charCount, byteCount);
305 _EncodingImpl::GetCharCount(const ByteBuffer& bytes, int& charCount) const
307 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
311 result r = GetBufferSize(bytes, srcLength);
312 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
314 return __pEncodingCore->GetCharCount(bytes.GetPointer(), srcLength, charCount);
318 _EncodingImpl::GetCharCount(const ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const
320 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
323 int inBufSize = bytes.GetLimit();
324 result r = CheckBufferInput(inBufSize, byteIndex, byteCount);
325 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
327 return __pEncodingCore->GetCharCount((bytes.GetPointer() + byteIndex), byteCount, charCount);
331 _EncodingImpl::GetBytesN(const WcharBuffer& chars) const
333 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
335 ByteBuffer* pBuffer = null;
337 result r = GetBufferSize(chars, srcLength);
338 SysTryReturn(NID_TEXT, (!IsFailed(r)), null, r, "[%s] Input validation failed", GetErrorMessage(r));
340 r = Encode(chars.GetPointer(), srcLength, pBuffer, 0);
347 _EncodingImpl::GetBytesN(const String& str) const
349 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
351 ByteBuffer* pBuffer = null;
352 int srcLength = str.GetLength();
353 SysTryReturn(NID_TEXT, (srcLength > 0), null, E_INVALID_ARG,
354 "[%s] Invalid argument is used. Input string is empty.", GetErrorMessage(E_INVALID_ARG));
356 result r = Encode(str.GetPointer(), srcLength, pBuffer, 0);
363 _EncodingImpl::GetBytes(const WcharBuffer& chars, int charIndex, int charCount, ByteBuffer& bytes, int byteIndex) const
365 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
367 ByteBuffer* pBuffer = &bytes;
368 int srcLen = chars.GetLimit();
369 int destLen = bytes.GetLimit();
371 result r = CheckBufferInput(srcLen, charIndex, charCount, destLen, byteIndex);
372 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
374 return Encode((chars.GetPointer() + charIndex), charCount, pBuffer, byteIndex);
378 _EncodingImpl::GetBytes(const String& str, int charIndex, int charCount, ByteBuffer& bytes, int byteIndex) const
380 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
382 ByteBuffer* pBuffer = &bytes;
383 int srcLen = str.GetLength();
384 int destLen = bytes.GetLimit();
386 result r = CheckBufferInput(srcLen, charIndex, charCount, destLen, byteIndex);
387 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
389 return Encode((str.GetPointer() + charIndex), charCount, pBuffer, byteIndex);
393 _EncodingImpl::GetCharsN(const ByteBuffer& bytes) const
395 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
397 WcharBuffer* pBuffer = null;
399 result r = GetBufferSize(bytes, srcLength);
400 SysTryReturn(NID_TEXT, (!IsFailed(r)), null, r, "[%s] Input validation failed", GetErrorMessage(r));
402 r = Decode(bytes.GetPointer(), srcLength, pBuffer, 0);
409 _EncodingImpl::GetChars(const ByteBuffer& bytes, int byteIndex, int byteCount, WcharBuffer& chars, int charIndex) const
411 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
413 WcharBuffer* pBuffer = &chars;
414 int srcLen = bytes.GetLimit();
415 int destLen = chars.GetLimit();
417 result r = CheckBufferInput(srcLen, byteIndex, byteCount, destLen, charIndex);
418 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
420 return Decode((bytes.GetPointer() + byteIndex), byteCount, pBuffer, charIndex);
424 _EncodingImpl::GetString(const ByteBuffer& bytes, Tizen::Base::String& str) const
426 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
429 result r = GetBufferSize(bytes, srcLength);
430 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
432 return Decode(bytes.GetPointer(), srcLength, str, 0);
436 _EncodingImpl::GetString(const ByteBuffer& bytes, int index, int count, String& str) const
438 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
440 int srcLen = bytes.GetLimit();
441 result r = CheckBufferInput(srcLen, index, count);
442 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
450 return Decode((bytes.GetPointer() + index), count, str, 0);
454 _EncodingImpl::ConvertImplN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes)
456 const _EncodingImpl* pSrcEncodingImpl = src._pEncodingImpl;
457 SysTryReturn(NID_TEXT, (pSrcEncodingImpl != null), null, E_INVALID_ARG, "[E_INVALID_ARG] Unable to get encoder object");
460 result r = pSrcEncodingImpl->GetBufferSize(srcBytes, inBufSize);
461 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to get byte buffer size", GetErrorMessage(r));
463 return ConvertN(src, dst, srcBytes, 0, inBufSize);
467 _EncodingImpl::ConvertImplN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes, int index, int count)
469 const _EncodingImpl* pSrcEncodingImpl = src._pEncodingImpl;
470 SysTryReturn(NID_TEXT, (pSrcEncodingImpl != null), null, E_INVALID_ARG, "[%s] Unable to get encoder object", GetErrorMessage(E_INVALID_ARG));
472 _EncodingCore* pSrcConverter = pSrcEncodingImpl->__pEncodingCore.get();
473 SysTryReturn(NID_TEXT, (pSrcConverter != null), null, E_INVALID_ARG, "[%s] Unable to get encoder decoder object", GetErrorMessage(E_INVALID_ARG));
475 const _EncodingImpl* pDstEncodingImpl = dst._pEncodingImpl;
476 SysTryReturn(NID_TEXT, (pDstEncodingImpl != null), null, E_INVALID_ARG, "[%s] Unable to get encoder object", GetErrorMessage(E_INVALID_ARG));
478 _EncodingCore* pDstConverter = pDstEncodingImpl->__pEncodingCore.get();
479 SysTryReturn(NID_TEXT, (pDstConverter != null), null, E_INVALID_ARG, "[%s] Unable to get encoder decoder object", GetErrorMessage(E_INVALID_ARG));
481 int inBufSize = srcBytes.GetLimit();
483 result r = pSrcEncodingImpl->CheckBufferInput(inBufSize, index, count);
484 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to get byte buffer size", GetErrorMessage(r));
488 std::unique_ptr<byte[]> pByte(pSrcConverter->ConvertN(pDstConverter, srcBytes.GetPointer() + index, count, retLength));
490 SysTryReturn(NID_TEXT, (pByte != null), null, r, "[%s] Unable to get encoder object", GetErrorMessage(r));
492 std::unique_ptr<ByteBuffer> pOutBuffer(new (std::nothrow) ByteBuffer);
493 SysTryReturn(NID_TEXT, pOutBuffer != null, null,
494 E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
496 r = pOutBuffer->Construct(retLength + 1);
497 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to Construct Byte buffer", GetErrorMessage(r));
499 r = pOutBuffer->SetArray(pByte.get(), 0, retLength);
500 SysTryReturn(NID_TEXT, (!IsFailed(r)), null, r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
502 pOutBuffer->Rewind();
504 SetLastResult(E_SUCCESS);
505 return pOutBuffer.release();
509 _EncodingImpl::GetMaxByteCount(int charCount) const
511 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
512 return __pEncodingCore->GetMaxByteCount(charCount);
516 _EncodingImpl::GetMaxCharCount(int byteCount) const
518 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
519 return __pEncodingCore->GetMaxCharCount(byteCount);
523 _EncodingImpl::GetEncoderN(void) const
529 _EncodingImpl::GetDecoderN(void) const
535 _EncodingImpl::GetAvailableEncodingsImplN(void)
538 result r = E_SUCCESS;
540 std::unique_ptr< LinkedList > pList(new (std::nothrow) LinkedList(SingleObjectDeleter));
542 SysTryReturn(NID_TEXT, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
544 for (int i = 0; i < AVAILABLE_ENCODING_COUNT; i++)
546 std::unique_ptr< String > pEncodingStr(new (std::nothrow) String(availableEncodings[i]));
547 SysTryReturn(NID_TEXT, pEncodingStr, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
549 r = pList->Add(*(pEncodingStr.get()));
550 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to add encoding to list", GetErrorMessage(r));
551 pEncodingStr.release();
554 return pList.release();
558 _EncodingImpl::GetBufferSize(const WcharBuffer& chars, int& charBufSize) const
560 charBufSize = StringUtil::GetStringLengthInMb(chars);
562 // This check is to correct tmpSize if chars does not contain null char
563 if (charBufSize == -1)
565 charBufSize = chars.GetLimit();
568 SysTryReturnResult(NID_TEXT, (charBufSize > 0), E_INVALID_ARG,
569 "[%s] Invalid argument is used. charBufSize(%d) is less than 0.", GetErrorMessage(E_INVALID_ARG), charBufSize);
574 _EncodingImpl::GetBufferSize(const ByteBuffer& bytes, int& byteBufSize) const
576 // It is assumed that user has set limit properly
577 byteBufSize = bytes.GetLimit();
579 int minByteCountForEncoding = 1;
582 minByteCountForEncoding = 4 / __pEncodingCore->GetMaxCharCount(4);
585 byte lastByte = '\0';
586 bool nullAtTheEnd = false;
587 result r = bytes.GetByte(byteBufSize - 1, lastByte);
588 SysTryReturnResult(NID_TEXT, (!IsFailed(r)), E_INVALID_ARG, "[%s] Last byte check failed", GetErrorMessage(r));
590 if ((lastByte == '\0')and(byteBufSize > 1))
593 if ((byteBufSize % minByteCountForEncoding) == 0)
595 for (int i = 0; i < minByteCountForEncoding; i++)
598 result r = bytes.GetByte(byteBufSize - i - 1, lastByte);
599 SysTryReturnResult(NID_TEXT, (!IsFailed(r)), E_INVALID_ARG, "[%s] Last byte check failed", GetErrorMessage(r));
601 if (lastByte != '\0')
603 nullAtTheEnd = false;
614 SysTryReturnResult(NID_TEXT, (byteBufSize > 0), E_INVALID_ARG, "byteBufSize [%d] is invalid.", byteBufSize);
619 _EncodingImpl::CheckBufferInput(int inBufSize, int inIndex, int inCount) const
621 SysTryReturnResult(NID_TEXT, (inIndex >= 0), E_INVALID_ARG,
622 "[%s] Invalid argument is used. inIndex(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inIndex);
623 SysTryReturnResult(NID_TEXT, (inCount >= 0), E_INVALID_ARG,
624 "[%s] Invalid argument is used. inCount(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inCount);
625 SysTryReturnResult(NID_TEXT, (inBufSize > 0), E_INVALID_ARG,
626 "[%s] Invalid argument is used. inBufSize(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inBufSize);
628 SysTryReturnResult(NID_TEXT, (inBufSize > inIndex), E_OUT_OF_RANGE,
629 "[%s] inIndex(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inIndex);
630 SysTryReturnResult(NID_TEXT, (inBufSize >= inCount), E_OUT_OF_RANGE,
631 "[%s] inCount(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inCount);
632 SysTryReturnResult(NID_TEXT, (inBufSize >= (inIndex + inCount)), E_UNDERFLOW,
633 "[%s] sum of the length of the inIndex(%d) and inCount(%d) is greater than inBufSize(%d).",
634 GetErrorMessage(E_UNDERFLOW), inIndex, inCount, inBufSize);
640 _EncodingImpl::CheckBufferInput(int inBufSize, int inIndex, int inCount, int outBufSize, int outIndex) const
642 SysTryReturnResult(NID_TEXT, (inIndex >= 0), E_INVALID_ARG,
643 "[%s] Invalid argument is used. inIndex(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inIndex);
644 SysTryReturnResult(NID_TEXT, (inCount >= 0), E_INVALID_ARG,
645 "[%s] Invalid argument is used. inCount(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inCount);
646 SysTryReturnResult(NID_TEXT, (outIndex >= 0), E_INVALID_ARG,
647 "[%s] Invalid argument is used. outIndex(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), outIndex);
648 SysTryReturnResult(NID_TEXT, (inBufSize > 0), E_INVALID_ARG,
649 "[%s] Invalid argument is used. inBufSize(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inBufSize);
651 SysTryReturnResult(NID_TEXT, (inBufSize > inIndex), E_OUT_OF_RANGE,
652 "[%s] inIndex(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inIndex);
653 SysTryReturnResult(NID_TEXT, (inBufSize >= inCount), E_OUT_OF_RANGE,
654 "[%s] inCount(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inCount);
655 SysTryReturnResult(NID_TEXT, (inBufSize >= (inIndex + inCount)), E_UNDERFLOW,
656 "[%s] sum of the length of the inIndex(%d) and inCount(%d) is greater than inBufSize(%d).",
657 GetErrorMessage(E_UNDERFLOW), inIndex, inCount, inBufSize);
659 SysTryReturnResult(NID_TEXT, (outBufSize > 0), E_INVALID_ARG,
660 "[%s] Invalid argument is used. outBufSize(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), outBufSize);
661 SysTryReturnResult(NID_TEXT, (outBufSize > outIndex), E_OVERFLOW, "[%s] outIndex [%d] is outside the valid range.", GetErrorMessage(E_OVERFLOW), outIndex);
667 _EncodingImpl::GetEncodingType(void) const
669 return __encodingType;
673 _EncodingImpl::IsEncodingSupported(const Tizen::Base::String& encodingStr) const
675 SysTryReturn(NID_TEXT, !encodingStr.IsEmpty(), false, E_INVALID_ARG, "[%s] Invalid argument is used. Input string is empty", GetErrorMessage(E_INVALID_ARG));
677 bool retValue = false;
678 for (int i = 0; i < AVAILABLE_ENCODING_COUNT; i++)
680 if (encodingStr.Equals(availableEncodings[i], false))