DCL 4.0
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__DCL_BEGIN_NAMESPACE
7
8String __mbstostr(const char* _mbs, size_t _nmbs)
10{
11 __DCL_ASSERT(_mbs != NULL);
12 return UTF8Decoder::decode(_mbs, _nmbs);
13}
14
15size_t __mbstostr_nt(const char* _mbs, size_t _nmbs, String& _str)
16{
17 try {
18 _str = __mbstostr(_mbs, _nmbs);
19 }
20 catch (CharsetConvertException* cause) {
21 cause->destroy();
22 return -1; // EILSEQ
23 }
24 return _str.length();
25}
26
27size_t __strtombs_nt(const String& _str, char* _mbs, size_t _nmbs)
28{
29 UTF8Encoder encoder(false);
30 if (_mbs == NULL) {
31 try {
32 return encoder.getEncodedLength(_str, _str.length());
33 }
34 catch (CharsetConvertException* cause) {
35 cause->destroy();
36 return -1; // EILSEQ
37 }
38 }
39
40 const wchar_t* pIn = _str;
41 size_t nInCount = _str.length();
42 size_t nOutCount = _nmbs;
43 int r = encoder.encode(pIn, nInCount, (byte_t*)_mbs, nOutCount);
44 if (r != CS_NOERROR)
45 return -1; // EILSEQ
46
47 if (nOutCount < _nmbs)
48 _mbs[nOutCount] = '\0';
49
50 return nOutCount;
51}
52
53__DCL_END_NAMESPACE
size_t __strtombs_nt(const String &_str, char *_mbs, size_t _nmbs)
Definition __strumbs.cpp:27
__DCL_BEGIN_NAMESPACE String __mbstostr(const char *_mbs, size_t _nmbs) __DCL_THROWS1(CharsetConvertException *)
Definition __strumbs.cpp:8
size_t __mbstostr_nt(const char *_mbs, size_t _nmbs, String &_str)
Definition __strumbs.cpp:15
@ CS_NOERROR
Definition Charset.h:61
#define NULL
Definition Config.h:340
unsigned char byte_t
Definition Config.h:274
#define __DCL_THROWS1(e)
Definition Config.h:167
#define __DCL_ASSERT(expr)
Definition Object.h:371
ByteString r
virtual void destroy()
Definition Exception.cpp:74