G
gry
[linux only, g++ 4.3.2]
I need to write a function that takes a char* containing utf-8 data
and,
'line' by 'line', edits the corresponding unicode text, dumping utf8
of the edited result into another
char *. The signature would be something like:
void doit(char *inbytes, char *outbytes){};
The 'editing' amounts to omitting some lines and maybe changing some
unicode characters to other characters.
The unicode text may include 1, 2, 3, and 4 byte characters.
My initial try looks like:
void doit(char *inbytes, char *outbytes){
wstringstream ins, outs;
ins.imbue(locale("en_US.UTF8"));
ins << inbytes;
wstring line;
while(line = ins.getline()) { //omit lines containing "X"
if(line.find(L"X")) {
outs << line << endl;
}
}
strcpy(outbytes, outs.rdbuf().c_str());
};
};
This gets a compiler error that:
no matching function for call to ‘std::basic_stringstream<wchar_t,
std::char_traits<wchar_t>, std::allocator<wchar_t> >::getline()’
If there's a clean solution to that, and that's the only significant
problem, that would be great.
Since this is my first c++ dealing with unicode, I fear there may be
more serious problems.
Please address the intention outlined above, more than my particular
code, assuming there is any hope at all...
I hope dearly to solve this cleanly without piling on extra libraries,
but I'll do what I must.
I need to write a function that takes a char* containing utf-8 data
and,
'line' by 'line', edits the corresponding unicode text, dumping utf8
of the edited result into another
char *. The signature would be something like:
void doit(char *inbytes, char *outbytes){};
The 'editing' amounts to omitting some lines and maybe changing some
unicode characters to other characters.
The unicode text may include 1, 2, 3, and 4 byte characters.
My initial try looks like:
void doit(char *inbytes, char *outbytes){
wstringstream ins, outs;
ins.imbue(locale("en_US.UTF8"));
ins << inbytes;
wstring line;
while(line = ins.getline()) { //omit lines containing "X"
if(line.find(L"X")) {
outs << line << endl;
}
}
strcpy(outbytes, outs.rdbuf().c_str());
};
};
This gets a compiler error that:
no matching function for call to ‘std::basic_stringstream<wchar_t,
std::char_traits<wchar_t>, std::allocator<wchar_t> >::getline()’
If there's a clean solution to that, and that's the only significant
problem, that would be great.
Since this is my first c++ dealing with unicode, I fear there may be
more serious problems.
Please address the intention outlined above, more than my particular
code, assuming there is any hope at all...
I hope dearly to solve this cleanly without piling on extra libraries,
but I'll do what I must.