DCL 3.7.4
Loading...
Searching...
No Matches
__strumbs.cpp
Go to the documentation of this file.
1
2#include <dcl/Object.h>
3#include <dcl/Charset.h>
4#include "__strumbs.h"
5
6#if __DCL_HAVE_ALLOC_DEBUG
7#undef __DCL_ALLOC_LEVEL
8#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
9#endif
10
11#if __DCL_HAVE_THIS_FILE__
12#undef __THIS_FILE__
13static const char_t __THIS_FILE__[] = __T("dcl/__strumbs.cpp");
14#endif
15
16__DCL_BEGIN_NAMESPACE
17
18String __mbstostr(const char* _mbs, size_t _nmbs)
20{
21 __DCL_ASSERT(_mbs != NULL);
22 return UTF8Decoder::decode(_mbs, _nmbs);
23}
24
25size_t __mbstostr_nt(const char* _mbs, size_t _nmbs, String& _str)
26{
27 try {
28 _str = __mbstostr(_mbs, _nmbs);
29 }
30 catch (CharsetConvertException* cause) {
31 cause->destroy();
32 return -1; // EILSEQ
33 }
34 return _str.length();
35}
36
37size_t __strtombs_nt(const String& _str, char* _mbs, size_t _nmbs)
38{
39 UTF8Encoder encoder(false);
40 if (_mbs == NULL) {
41 try {
42 return encoder.getEncodedLength(_str, _str.length());
43 }
44 catch (CharsetConvertException* cause) {
45 cause->destroy();
46 return -1; // EILSEQ
47 }
48 }
49
50 const wchar_t* pIn = _str;
51 size_t nInCount = _str.length();
52 size_t nOutCount = _nmbs;
53 int r = encoder.encode(pIn, nInCount, (byte_t*)_mbs, nOutCount);
54 if (r != CS_NOERROR)
55 return -1; // EILSEQ
56
57 if (nOutCount < _nmbs)
58 _mbs[nOutCount] = '\0';
59
60 return nOutCount;
61}
62
63__DCL_END_NAMESPACE
size_t __strtombs_nt(const String &_str, char *_mbs, size_t _nmbs)
Definition __strumbs.cpp:37
__DCL_BEGIN_NAMESPACE String __mbstostr(const char *_mbs, size_t _nmbs) __DCL_THROWS1(CharsetConvertException *)
Definition __strumbs.cpp:18
size_t __mbstostr_nt(const char *_mbs, size_t _nmbs, String &_str)
Definition __strumbs.cpp:25
#define __THIS_FILE__
Definition _trace.h:14
@ CS_NOERROR
Definition Charset.h:66
#define NULL
Definition Config.h:312
wchar_t char_t
Definition Config.h:247
unsigned char byte_t
Definition Config.h:246
#define __DCL_THROWS1(e)
Definition Config.h:152
IOException *size_t r
Definition MediaInfo.cpp:82
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60
virtual void destroy()
Definition Exception.cpp:74