2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FText_EncodingImpl.cpp
20 * @brief This is the implementation file for _EncodingImpl class.
23 #include <FBaseResult.h>
24 #include "FText_EncodingCore.h"
25 #include <FBaseSysLog.h>
26 #include "FText_EncodingImpl.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Utility;
32 #define AVAILABLE_ENCODING_COUNT 45
33 static String availableEncodings[] =
82 namespace Tizen { namespace Text
85 _EncodingImpl::_EncodingImpl(void)
88 , __pEncodingCore(null)
92 _EncodingImpl::~_EncodingImpl(void)
98 _EncodingImpl::Construct(const String& encodingType)
100 // Object is not allowed to construct twice
101 SysAssertf(__pEncodingCore == null,
102 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
104 SysTryReturnResult(NID_TEXT, IsEncodingSupported(encodingType),
105 E_UNSUPPORTED_TYPE, "[%s] encodingType[%ls] is not supported", GetErrorMessage(E_UNSUPPORTED_TYPE), encodingType.GetPointer());
107 __pEncodingCore.reset(_EncodingCore::GetEncodingCoreN(encodingType, L"WCHAR_T"));
109 result r = GetLastResult();
110 SysTryReturnResult(NID_TEXT, (__pEncodingCore != null), r, "[%s] Failed to open encoder/decoder.", GetErrorMessage(r));
112 __encodingType = encodingType;
113 _pEncodingImpl = this;
119 _EncodingImpl::Encode(const wchar_t* pSrc, int srcLength, ByteBuffer*& pByteBuffer, int index) const
121 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
123 SysTryReturnResult(NID_TEXT, (pSrc != null), E_INVALID_ARG, "[%s] Invalid argument is used. pSrc can not be null.", GetErrorMessage(E_INVALID_ARG));
124 SysTryReturnResult(NID_TEXT, (srcLength >= 0), E_INVALID_ARG,
125 "[%s] Invalid argument is used. srcLength(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), srcLength);
126 SysTryReturnResult(NID_TEXT, (index >= 0), E_INVALID_ARG,
127 "[%s] Invalid argument is used. index(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), index);
129 result r = E_SUCCESS;
130 int currPosition = 0;
132 bool isMemAllocReq = false;
134 std::unique_ptr<byte[]> pDst(__pEncodingCore->EncodeN(pSrc, srcLength, retLength));
136 SysTryReturnResult(NID_TEXT, (pDst != null), r, "[%s] Decoding failed", GetErrorMessage(r));
138 ByteBuffer* pOutBuffer = pByteBuffer;
141 if (pOutBuffer == null)
143 isMemAllocReq = true;
144 pOutBuffer = new (std::nothrow) ByteBuffer;
145 SysTryCatch(NID_TEXT, (pOutBuffer != null), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
147 r = pOutBuffer->Construct(retLength + 1);
148 SysTryCatch(NID_TEXT, !IsFailed(r), , r, "[%s] Unable to Construct Byte buffer", GetErrorMessage(r));
150 pByteBuffer = pOutBuffer;
154 currPosition = pOutBuffer->GetPosition();
156 r = pOutBuffer->SetPosition(index);
157 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
159 r = pOutBuffer->SetArray(pDst.get(), 0, retLength);
160 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
162 r = pOutBuffer->SetPosition(currPosition);
163 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
178 _EncodingImpl::Decode(const byte* pSrc, int srcLength, WcharBuffer*& pWcharBuffer, int index) const
180 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
182 SysTryReturnResult(NID_TEXT, (pSrc != null), E_INVALID_ARG, "[%s] Invalid argument is used. pSrc can not be null.", GetErrorMessage(E_INVALID_ARG));
183 SysTryReturnResult(NID_TEXT, (srcLength >= 0), E_INVALID_ARG,
184 "[%s] Invalid argument is used. srcLength(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), srcLength);
185 SysTryReturnResult(NID_TEXT, (index >= 0), E_INVALID_ARG,
186 "[%s] Invalid argument is used. index(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), index);
188 result r = E_SUCCESS;
189 int currPosition = 0;
191 bool isMemAllocReq = false;
193 std::unique_ptr<wchar_t[]> pDst(__pEncodingCore->DecodeN(pSrc, srcLength, retLength));
195 SysTryReturnResult(NID_TEXT, (pDst != null), r, "[%s] Decoding failed", GetErrorMessage(r));
197 WcharBuffer* pOutBuffer = pWcharBuffer;
200 if (pOutBuffer == null)
202 isMemAllocReq = true;
203 pOutBuffer = new (std::nothrow) WcharBuffer;
204 SysTryCatch(NID_TEXT, (pOutBuffer != null), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
206 r = pOutBuffer->Construct(retLength + 1);
207 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to Construct Byte buffer", GetErrorMessage(r));
209 r = pOutBuffer->SetArray(pDst.get(), 0, retLength);
210 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
212 r = pOutBuffer->Set(L'\0');
213 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set null Byte", GetErrorMessage(r));
215 pOutBuffer->Rewind();
216 pWcharBuffer = pOutBuffer;
220 currPosition = pOutBuffer->GetPosition();
222 r = pOutBuffer->SetPosition(index);
223 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
225 r = pOutBuffer->SetArray(pDst.get(), 0, retLength);
226 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
228 r = pOutBuffer->SetPosition(currPosition);
229 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Unable to set Byte buffer position", GetErrorMessage(r));
244 _EncodingImpl::Decode(const byte* pSrc, int srcLength, String& outStr, int index) const
246 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
248 SysTryReturnResult(NID_TEXT, (pSrc != null), E_INVALID_ARG, "[%s] Invalid argument is used. pSrc can not be null.", GetErrorMessage(E_INVALID_ARG));
249 SysTryReturnResult(NID_TEXT, (srcLength >= 0), E_INVALID_ARG,
250 "[%s] Invalid argument is used. srcLength(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), srcLength);
251 SysTryReturnResult(NID_TEXT, (index >= 0), E_INVALID_ARG,
252 "[%s] Invalid argument is used. index(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), index);
254 result r = E_SUCCESS;
257 std::unique_ptr<wchar_t[]> pDst(__pEncodingCore->DecodeN(pSrc, srcLength, retLength));
259 SysTryReturnResult(NID_TEXT, (pDst != null), r, "[%s] Decoding failed", GetErrorMessage(r));
267 _EncodingImpl::GetByteCount(const String& str, int& byteCount) const
269 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
272 int srcLength = str.GetLength();
273 SysTryReturnResult(NID_TEXT, (srcLength > 0), E_INVALID_ARG,
274 "[%s] Invalid argument is used. Input string is empty.", GetErrorMessage(E_INVALID_ARG));
276 return __pEncodingCore->GetByteCount(str.GetPointer(), srcLength, byteCount);
280 _EncodingImpl::GetByteCount(const WcharBuffer& chars, int& byteCount) const
282 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
286 result r = GetBufferSize(chars, srcLength);
287 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
289 return __pEncodingCore->GetByteCount(chars.GetPointer(), srcLength, byteCount);
293 _EncodingImpl::GetByteCount(const WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const
295 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
298 int inBufSize = chars.GetLimit();
299 result r = CheckBufferInput(inBufSize, charIndex, charCount);
300 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
302 return __pEncodingCore->GetByteCount((chars.GetPointer() + charIndex), charCount, byteCount);
306 _EncodingImpl::GetCharCount(const ByteBuffer& bytes, int& charCount) const
308 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
312 result r = GetBufferSize(bytes, srcLength);
313 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
315 return __pEncodingCore->GetCharCount(bytes.GetPointer(), srcLength, charCount);
319 _EncodingImpl::GetCharCount(const ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const
321 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
324 int inBufSize = bytes.GetLimit();
325 result r = CheckBufferInput(inBufSize, byteIndex, byteCount);
326 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
328 return __pEncodingCore->GetCharCount((bytes.GetPointer() + byteIndex), byteCount, charCount);
332 _EncodingImpl::GetBytesN(const WcharBuffer& chars) const
334 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
336 ByteBuffer* pBuffer = null;
338 result r = GetBufferSize(chars, srcLength);
339 SysTryReturn(NID_TEXT, (!IsFailed(r)), null, r, "[%s] Input validation failed", GetErrorMessage(r));
341 r = Encode(chars.GetPointer(), srcLength, pBuffer, 0);
348 _EncodingImpl::GetBytesN(const String& str) const
350 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
352 ByteBuffer* pBuffer = null;
353 int srcLength = str.GetLength();
354 SysTryReturn(NID_TEXT, (srcLength > 0), null, E_INVALID_ARG,
355 "[%s] Invalid argument is used. Input string is empty.", GetErrorMessage(E_INVALID_ARG));
357 result r = Encode(str.GetPointer(), srcLength, pBuffer, 0);
364 _EncodingImpl::GetBytes(const WcharBuffer& chars, int charIndex, int charCount, ByteBuffer& bytes, int byteIndex) const
366 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
368 ByteBuffer* pBuffer = &bytes;
369 int srcLen = chars.GetLimit();
370 int destLen = bytes.GetLimit();
372 result r = CheckBufferInput(srcLen, charIndex, charCount, destLen, byteIndex);
373 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
375 return Encode((chars.GetPointer() + charIndex), charCount, pBuffer, byteIndex);
379 _EncodingImpl::GetBytes(const String& str, int charIndex, int charCount, ByteBuffer& bytes, int byteIndex) const
381 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
383 ByteBuffer* pBuffer = &bytes;
384 int srcLen = str.GetLength();
385 int destLen = bytes.GetLimit();
387 result r = CheckBufferInput(srcLen, charIndex, charCount, destLen, byteIndex);
388 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
390 return Encode((str.GetPointer() + charIndex), charCount, pBuffer, byteIndex);
394 _EncodingImpl::GetCharsN(const ByteBuffer& bytes) const
396 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
398 WcharBuffer* pBuffer = null;
400 result r = GetBufferSize(bytes, srcLength);
401 SysTryReturn(NID_TEXT, (!IsFailed(r)), null, r, "[%s] Input validation failed", GetErrorMessage(r));
403 r = Decode(bytes.GetPointer(), srcLength, pBuffer, 0);
410 _EncodingImpl::GetChars(const ByteBuffer& bytes, int byteIndex, int byteCount, WcharBuffer& chars, int charIndex) const
412 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
414 WcharBuffer* pBuffer = &chars;
415 int srcLen = bytes.GetLimit();
416 int destLen = chars.GetLimit();
418 result r = CheckBufferInput(srcLen, byteIndex, byteCount, destLen, charIndex);
419 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
421 return Decode((bytes.GetPointer() + byteIndex), byteCount, pBuffer, charIndex);
425 _EncodingImpl::GetString(const ByteBuffer& bytes, Tizen::Base::String& str) const
427 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
430 result r = GetBufferSize(bytes, srcLength);
431 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
433 return Decode(bytes.GetPointer(), srcLength, str, 0);
437 _EncodingImpl::GetString(const ByteBuffer& bytes, int index, int count, String& str) const
439 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
441 int srcLen = bytes.GetLimit();
442 result r = CheckBufferInput(srcLen, index, count);
443 SysTryReturn(NID_TEXT, (!IsFailed(r)), r, r, "[%s] Input validation failed", GetErrorMessage(r));
451 return Decode((bytes.GetPointer() + index), count, str, 0);
455 _EncodingImpl::ConvertImplN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes)
457 const _EncodingImpl* pSrcEncodingImpl = src._pEncodingImpl;
458 SysTryReturn(NID_TEXT, (pSrcEncodingImpl != null), null, E_INVALID_ARG, "[E_INVALID_ARG] Unable to get encoder object");
461 result r = pSrcEncodingImpl->GetBufferSize(srcBytes, inBufSize);
462 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to get byte buffer size", GetErrorMessage(r));
464 return ConvertN(src, dst, srcBytes, 0, inBufSize);
468 _EncodingImpl::ConvertImplN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes, int index, int count)
470 const _EncodingImpl* pSrcEncodingImpl = src._pEncodingImpl;
471 SysTryReturn(NID_TEXT, (pSrcEncodingImpl != null), null, E_INVALID_ARG, "[%s] Unable to get encoder object", GetErrorMessage(E_INVALID_ARG));
473 _EncodingCore* pSrcConverter = pSrcEncodingImpl->__pEncodingCore.get();
474 SysTryReturn(NID_TEXT, (pSrcConverter != null), null, E_INVALID_ARG, "[%s] Unable to get encoder decoder object", GetErrorMessage(E_INVALID_ARG));
476 const _EncodingImpl* pDstEncodingImpl = dst._pEncodingImpl;
477 SysTryReturn(NID_TEXT, (pDstEncodingImpl != null), null, E_INVALID_ARG, "[%s] Unable to get encoder object", GetErrorMessage(E_INVALID_ARG));
479 _EncodingCore* pDstConverter = pDstEncodingImpl->__pEncodingCore.get();
480 SysTryReturn(NID_TEXT, (pDstConverter != null), null, E_INVALID_ARG, "[%s] Unable to get encoder decoder object", GetErrorMessage(E_INVALID_ARG));
482 int inBufSize = srcBytes.GetLimit();
484 result r = pSrcEncodingImpl->CheckBufferInput(inBufSize, index, count);
485 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to get byte buffer size", GetErrorMessage(r));
489 std::unique_ptr<byte[]> pByte(pSrcConverter->ConvertN(pDstConverter, srcBytes.GetPointer() + index, count, retLength));
491 SysTryReturn(NID_TEXT, (pByte != null), null, r, "[%s] Unable to get encoder object", GetErrorMessage(r));
493 std::unique_ptr<ByteBuffer> pOutBuffer(new (std::nothrow) ByteBuffer);
494 SysTryReturn(NID_TEXT, pOutBuffer != null, null,
495 E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
497 r = pOutBuffer->Construct(retLength + 1);
498 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to Construct Byte buffer", GetErrorMessage(r));
500 r = pOutBuffer->SetArray(pByte.get(), 0, retLength);
501 SysTryReturn(NID_TEXT, (!IsFailed(r)), null, r, "[%s] Unable to fill Byte buffer", GetErrorMessage(r));
503 pOutBuffer->Rewind();
505 SetLastResult(E_SUCCESS);
506 return pOutBuffer.release();
510 _EncodingImpl::GetMaxByteCount(int charCount) const
512 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
513 return __pEncodingCore->GetMaxByteCount(charCount);
517 _EncodingImpl::GetMaxCharCount(int byteCount) const
519 SysAssertf(__pEncodingCore != null, "Not yet constructed! Construct() should be called before use.");
520 return __pEncodingCore->GetMaxCharCount(byteCount);
524 _EncodingImpl::GetEncoderN(void) const
530 _EncodingImpl::GetDecoderN(void) const
536 _EncodingImpl::GetAvailableEncodingsImplN(void)
539 result r = E_SUCCESS;
541 std::unique_ptr<LinkedList, AllElementsDeleter> pList(new (std::nothrow) LinkedList());
543 SysTryReturn(NID_TEXT, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
545 for (int i = 0; i < AVAILABLE_ENCODING_COUNT; i++)
547 String* pEncodingStr = new (std::nothrow) String(availableEncodings[i]);
548 SysTryReturn(NID_TEXT, pEncodingStr, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
550 r = pList->Add(*pEncodingStr);
554 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Unable to add encoding to list", GetErrorMessage(r));
558 return pList.release();
562 _EncodingImpl::GetBufferSize(const WcharBuffer& chars, int& charBufSize) const
564 charBufSize = StringUtil::GetStringLengthInMb(chars);
566 // This check is to correct tmpSize if chars does not contain null char
567 if (charBufSize == -1)
569 charBufSize = chars.GetLimit();
572 SysTryReturnResult(NID_TEXT, (charBufSize > 0), E_INVALID_ARG,
573 "[%s] Invalid argument is used. charBufSize(%d) is less than 0.", GetErrorMessage(E_INVALID_ARG), charBufSize);
578 _EncodingImpl::GetBufferSize(const ByteBuffer& bytes, int& byteBufSize) const
580 // It is assumed that user has set limit properly
581 byteBufSize = bytes.GetLimit();
583 int minByteCountForEncoding = 1;
586 minByteCountForEncoding = 4 / __pEncodingCore->GetMaxCharCount(4);
589 byte lastByte = '\0';
590 bool nullAtTheEnd = false;
591 result r = bytes.GetByte(byteBufSize - 1, lastByte);
592 SysTryReturnResult(NID_TEXT, (!IsFailed(r)), E_INVALID_ARG, "[%s] Last byte check failed", GetErrorMessage(r));
594 if ((lastByte == '\0')and(byteBufSize > 1))
597 if ((byteBufSize % minByteCountForEncoding) == 0)
599 for (int i = 0; i < minByteCountForEncoding; i++)
602 result r = bytes.GetByte(byteBufSize - i - 1, lastByte);
603 SysTryReturnResult(NID_TEXT, (!IsFailed(r)), E_INVALID_ARG, "[%s] Last byte check failed", GetErrorMessage(r));
605 if (lastByte != '\0')
607 nullAtTheEnd = false;
618 SysTryReturnResult(NID_TEXT, (byteBufSize > 0), E_INVALID_ARG, "byteBufSize [%d] is invalid.", byteBufSize);
623 _EncodingImpl::CheckBufferInput(int inBufSize, int inIndex, int inCount) const
625 SysTryReturnResult(NID_TEXT, (inIndex >= 0), E_INVALID_ARG,
626 "[%s] Invalid argument is used. inIndex(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inIndex);
627 SysTryReturnResult(NID_TEXT, (inCount >= 0), E_INVALID_ARG,
628 "[%s] Invalid argument is used. inCount(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inCount);
629 SysTryReturnResult(NID_TEXT, (inBufSize > 0), E_INVALID_ARG,
630 "[%s] Invalid argument is used. inBufSize(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inBufSize);
632 SysTryReturnResult(NID_TEXT, (inBufSize > inIndex), E_OUT_OF_RANGE,
633 "[%s] inIndex(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inIndex);
634 SysTryReturnResult(NID_TEXT, (inBufSize >= inCount), E_OUT_OF_RANGE,
635 "[%s] inCount(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inCount);
636 SysTryReturnResult(NID_TEXT, (inBufSize >= (inIndex + inCount)), E_UNDERFLOW,
637 "[%s] sum of the length of the inIndex(%d) and inCount(%d) is greater than inBufSize(%d).",
638 GetErrorMessage(E_UNDERFLOW), inIndex, inCount, inBufSize);
644 _EncodingImpl::CheckBufferInput(int inBufSize, int inIndex, int inCount, int outBufSize, int outIndex) const
646 SysTryReturnResult(NID_TEXT, (inIndex >= 0), E_INVALID_ARG,
647 "[%s] Invalid argument is used. inIndex(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inIndex);
648 SysTryReturnResult(NID_TEXT, (inCount >= 0), E_INVALID_ARG,
649 "[%s] Invalid argument is used. inCount(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inCount);
650 SysTryReturnResult(NID_TEXT, (outIndex >= 0), E_INVALID_ARG,
651 "[%s] Invalid argument is used. outIndex(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), outIndex);
652 SysTryReturnResult(NID_TEXT, (inBufSize > 0), E_INVALID_ARG,
653 "[%s] Invalid argument is used. inBufSize(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), inBufSize);
655 SysTryReturnResult(NID_TEXT, (inBufSize > inIndex), E_OUT_OF_RANGE,
656 "[%s] inIndex(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inIndex);
657 SysTryReturnResult(NID_TEXT, (inBufSize >= inCount), E_OUT_OF_RANGE,
658 "[%s] inCount(%d) is outside the valid range.", GetErrorMessage(E_OUT_OF_RANGE), inCount);
659 SysTryReturnResult(NID_TEXT, (inBufSize >= (inIndex + inCount)), E_UNDERFLOW,
660 "[%s] sum of the length of the inIndex(%d) and inCount(%d) is greater than inBufSize(%d).",
661 GetErrorMessage(E_UNDERFLOW), inIndex, inCount, inBufSize);
663 SysTryReturnResult(NID_TEXT, (outBufSize > 0), E_INVALID_ARG,
664 "[%s] Invalid argument is used. outBufSize(%d) cannot be negative.", GetErrorMessage(E_INVALID_ARG), outBufSize);
665 SysTryReturnResult(NID_TEXT, (outBufSize > outIndex), E_OVERFLOW, "[%s] outIndex [%d] is outside the valid range.", GetErrorMessage(E_OVERFLOW), outIndex);
671 _EncodingImpl::GetEncodingType(void) const
673 return __encodingType;
677 _EncodingImpl::IsEncodingSupported(const Tizen::Base::String& encodingStr) const
679 SysTryReturn(NID_TEXT, !encodingStr.IsEmpty(), false, E_INVALID_ARG, "[%s] Invalid argument is used. Input string is empty", GetErrorMessage(E_INVALID_ARG));
681 bool retValue = false;
682 for (int i = 0; i < AVAILABLE_ENCODING_COUNT; i++)
684 if (encodingStr.Equals(availableEncodings[i], false))