16#ifndef LIMA_COMMONS_MISC_STRWSTRTOOLS_H
17#define LIMA_COMMONS_MISC_STRWSTRTOOLS_H
27#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
28#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
29#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
30#define U16_GET_SUPPLEMENTARY(lead, trail) \
31(((char32_t)(lead)<<10UL)+(char32_t)(trail)-U16_SURROGATE_OFFSET)
33#define U16_LEAD(supplementary) (char32_t)(((supplementary)>>10)+0xd7c0)
34#define U16_TRAIL(supplementary) (char32_t)(((supplementary)&0x3ff)|0xdc00)
36#define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800)
37#define U16_IS_SINGLE(c) !U_IS_SURROGATE(c)
38#define U16_IS_SURROGATE(c) U_IS_SURROGATE(c)
39#define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
45#define U16_NEXT(s, i, length, c) { \
46(c)=(s)[(i)++].unicode(); \
49 if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)].unicode())) { \
51 (c)=U16_GET_SUPPLEMENTARY((c), __c2); \
56#define U16_PREV(s, start, i, c) { \
57(c)=(s)[--(i)].unicode(); \
58if(U16_IS_TRAIL(c)) { \
60 if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1].unicode())) { \
62 (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \
67#define U_MASK(x) ((uint32_t)1<<(x))
164template <
typename C >
165void chomp(std::basic_string< C >& str)
168 if ( ( str.begin() != str.end() )
169 && ( *(--str.end()) == C(
'\n') ) ) str.erase(--str.end());
172template <
typename C >
173void chop(std::basic_string< C >& str)
176 if ( str.begin() != str.end() ) str.erase(--str.end());
184template <
typename charT>
186 static const char hexSymbol[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'};
188 for(
typename std::basic_string<charT>::const_iterator i = input.begin() ; i != input.end() ; i++ ) {
190 uint64_t val = (*i).unicode();
191 if (
sizeof(charT) == 4 ) {
192 result.append( 1, hexSymbol[ (val>>28)&0xF ] );
193 result.append( 1, hexSymbol[ (val>>24)&0xF ] );
194 result.append( 1, hexSymbol[ (val>>20)&0xF ] );
195 result.append( 1, hexSymbol[ (val>>16)&0xF ] );
197 if (
sizeof(charT) >= 2 ) {
198 result.append( 1, hexSymbol[ (val>>12)&0xF ] );
199 result.append( 1, hexSymbol[ (val>>8)&0xF ] );
201 result.append( 1, hexSymbol[ (val>>4)&0xF ] );
202 result.append( 1, hexSymbol[ val&0x0F ] );
204 if (
sizeof(charT) == 1 ) {
205 const void *ptr =
static_cast<const void*
>(&input);
206 const std::string* strPtr =
static_cast<const std::string*
>(ptr);
207 const std::string text = *strPtr;
208 result += std::string(
"(") + text + std::string(
")");
std::string localestring2utf8string(const std::string &src)
␈rief Convert a string in the locale codepage to a UTF8 string
void writeUTF8StringField(std::ostream &file, const Lima::LimaString &s)
Binary write a a LimaString in a file as an utf8 string.
void readString(istream &file, string &s)
Read an input stream into a wide string, until EOF.
void chomp(std::basic_string< C > &str)
std::string readLine(std::istream &inputFile)
void writeString(ostream &file, const string &s)
write a string on an output file stream
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
std::string convertString(const std::basic_string< charT > &input)
void readStringField(istream &file, string &s)
void readStream(std::istream &is, std::string &dest)
Read an input stream into a string, until EOF.
LimaString setStringSameEndian(const unsigned short *s, const uint32_t count)
redefine an existing LimaString from UTF-16
void writeStringField(ostream &file, const string &s)
void chop(std::basic_string< C > &str)
void readUTF8StringField(std::istream &file, Lima::LimaString &s)
Binary read an utf8 string from a file and store it in a LimaString.
LimaString transcodeToXmlEntities(const LimaString &str)
void writeStream(std::ostream &os, const std::string &src)
Write a string to an output stream.
LimaString latin15stdstring2limastring(const std::string &src)
Convert a latin15 string to a LimaString.
LimaString setStringReverseEndian(const unsigned short *s, const uint32_t count)
redefine an existing LimaString from UTF-16 changing the endian mode
LimaString utf8stdstring2limastring(const std::string &src)