36 #if defined(BLOCXX_HAVE_ICONV_SUPPORT) 51 : m_iconv(iconv_t(-1))
57 IConv_t::IConv_t(
const String &fromEncoding,
const String &toEncoding)
59 m_iconv = ::iconv_open(toEncoding.c_str(), fromEncoding.c_str());
60 if( m_iconv == iconv_t(-1))
63 Format(
"Unable to convert from \"%1\" to \"%2\"",
64 fromEncoding, toEncoding).c_str());
78 IConv_t::open(
const String &fromEncoding,
const String &toEncoding)
81 m_iconv = ::iconv_open(toEncoding.c_str(), fromEncoding.c_str());
82 return ( m_iconv != iconv_t(-1));
88 IConv_t::convert(
char **istr,
size_t *ibytesleft,
89 char **ostr,
size_t *obytesleft)
91 #if defined(BLOCXX_ICONV_INBUF_CONST) 93 const char *ptr = *istr;
94 int ret = ::iconv(m_iconv, &ptr, ibytesleft, ostr, obytesleft);
95 *istr =
const_cast<char*
>(ptr);
98 return ::iconv(m_iconv, istr, ibytesleft, ostr, obytesleft);
110 if( m_iconv != iconv_t(-1))
112 if( ::iconv_close(m_iconv) == -1)
114 m_iconv = iconv_t(-1);
128 mayThrowStringConversionException()
137 "Invalid character or multibyte sequence in the input");
143 "Incomplete multibyte sequence in the input");
150 fromByteString(
const String &enc,
const char *str,
size_t len)
152 if( !str || len == 0)
155 IConv_t iconv(enc,
"UTF-8");
161 char *sptr = (
char *)str;
168 olen =
sizeof(obuf) -
sizeof(obuf[0]);
170 size_t ret = iconv.convert(&sptr, &slen, &optr, &olen);
171 if( ret ==
size_t(-1))
173 mayThrowStringConversionException();
185 fromByteString(
const String &enc,
const std::string &str)
187 return fromByteString(enc, str.c_str(), str.length());
191 #ifdef BLOCXX_HAVE_STD_WSTRING 194 fromWideString(
const String &enc,
const std::wstring &str)
199 IConv_t iconv(enc,
"UTF-8");
205 char *sptr = (
char *)str.c_str();
206 size_t slen = str.length() *
sizeof(wchar_t);
212 olen =
sizeof(obuf) -
sizeof(obuf[0]);
214 size_t ret = iconv.convert(&sptr, &slen, &optr, &olen);
215 if( ret ==
size_t(-1))
217 mayThrowStringConversionException();
229 toByteString(
const String &enc,
const String &utf8)
232 return std::string();
234 IConv_t iconv(
"UTF-8", enc);
240 char *sptr = (
char *)utf8.c_str();
241 size_t slen = utf8.length();
247 olen =
sizeof(obuf) -
sizeof(obuf[0]);
249 size_t ret = iconv.convert(&sptr, &slen, &optr, &olen);
250 if( ret ==
size_t(-1))
252 mayThrowStringConversionException();
261 #ifdef BLOCXX_HAVE_STD_WSTRING 264 toWideString(
const String &enc,
const String &utf8)
267 return std::wstring();
269 IConv_t iconv(
"UTF-8", enc);
275 char *sptr = (
char *)utf8.c_str();
276 size_t slen = utf8.length();
282 olen =
sizeof(obuf) -
sizeof(obuf[0]);
284 size_t ret = iconv.convert(&sptr, &slen, &optr, &olen);
285 if( ret ==
size_t(-1))
287 mayThrowStringConversionException();
289 *((
wchar_t *)optr) = L
'\0';
308 command.push_back(
"--list");
320 return output.tokenize(
"\r\n");
330 #endif // BLOCXX_HAVE_ICONV_SUPPORT
#define BLOCXX_ASSERT(CON)
BLOCXX_ASSERT works similar to the assert() macro, but instead of calling abort(), it throws an AssertionException.
BLOCXX_COMMON_API int close(const FileHandle &hdl)
Close file handle.
Array< String > StringArray
void push_back(const T &x)
Append an element to the end of the Array.
#define BLOCXX_THROW(exType, msg)
Throw an exception using FILE and LINE.
Process::Status executeProcessAndGatherOutput(char const *const command[], String &output, char const *const envVars[], const Timeout &timeout, int outputLimit, char const *input)
Execute a command and run feedProcessAndGatherOutput() on the process.