Read Arabic file contents using string in c++ - c++

I have a text file (ansi encoding) that contains an arabic contents and I have read it using c++ as:
ifstream ifs(file.GetFileName());
std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
unfortunately the content variable holds encrypted strings (which must be in arabic lang) i.e:
121101 ÇáÒÈæä ßãÇá
121102 ÇáÒÈæä ÓÚíÏ
121103 ÇáÒÈæä ÚãÇÑ
any solution???
Thanks :)

Related

CJson - Insert missing quotes around strings

I have a text file of format given below (this is just sample file, but actually file is big one with key, values). Some of the values for the key will have format in file (look for value of Port key in below file). This is input file for me.
I am converting this file into Json using CJson Library in C++. Since value corresponding to Port key is not a valid string or value, CJson gives error message saying "Insert missing quotes around strings". So I tried to convert Port value to string using below code. But I am unable to insert missing quotes around. Could you please help me how to "Insert missing quotes around strings".
Code I tried:
ifstream infile { "conf_file.conf" };
string file_contents{ istreambuf_iterator<char>(infile), istreambuf_iterator<char>() };
pParentJson = cJSON_Parse( (char*)file_contents.c_str() );
cJSON* pJsonObj = cJSON_GetObjectItem(pParentJson,"port");
char* pDataBuffer = cJSON_Print(pJsonObj);
cout<<pDataBuffer<<endl;
Text File
{
"port": <CbTcpPortVariable>
"IP" : "127.0.0.1"
"Message": "Hello"
}

How to write ACE_Tstring to file in c++

I'm using windows OS and trying to write ACE_Tstring that contains multiple languages sentence(by Unicode) to a file using ACE_OS::write().
But the result I'm getting in the file is unpredictable characters(gibberish text).
This is my code implemented :
ACE_Tstring *str = new ACE_Tstring(L"مرحبا привет świecie Hello")
ACE_HANDL hFile = ACE_OS::open(L"myfile", _O_WRONLY);
ACE_OS::write(hFile, str, 1048);
wprintf(L"%ls",str->c_str());
As you can see I also print the string to the screen, and on screen I get the characters "????" where any character accept for English characters appear.
Written Text
مرحبا привет świecie Hello
Result on Screen :
?????? ????? ??????? Hello
What am I missing and what is wrong with my code?
ACE_TString is a typedef for ACE_CString when ACE_USES_WCHAR is not set. Try using ACE_WString if you need to force it to wide-chars.

Parse string in xmllib instead of xmlParseFile

I have string with xml content, writing it into a file and reading it back with xmlParseFile affects performance, if there is a way to parse the string directly, can you please show it with an example?
Consider xmlParseMemory instead.
I have string with xml content
So you should be able to do it like so:
const std::string xmlContent = "<something> </something>";
xmlDocPtr doc = xmlParseMemory(xmlContent.c_str(), xmlContent.length());

QXmlStreamWriter and cyrillic

I have a problem with encoding when writing XML files via QXmlStreamWriter in windows, how can I resolve it? Using stream.setCodec("UTF-8") or "windows-1251" is not helped.
QFile *file = new QFile(filename);
if (file->open(QIODevice::WriteOnly | QIODevice::Text))
{
QXmlStreamWriter stream(file);
stream.setAutoFormatting(true);
stream.writeStartDocument();
stream.writeStartElement("СЕКЦИЯ"); // start root section
stream.writeStartElement("FIELD");
stream.writeAttribute("name", "Имя");
stream.writeAttribute("value", "Иван");
stream.writeEndElement();
stream.writeEndElement(); // END СЕКЦИЯ
file->close();
}
Most likely the interpretation of the string literals in your source file is the problem, not the configuration of the stream writer.
Make sure your source file is encoded in UTF-8 and use QString::fromUtf8("Imja") etc. (Imja in cyrillic of course) instead of the implicit literal to QString conversion.

How to write programmatically some unicode text in RTF format?

In order to generate RTF programmatically I have decided to use rtflib v1.0 from codeproject.com. But I can't understand how to generate text in russian unicode. So I need to generate a unicode text. Could someone help me?
P.S. Honeslty, I could write in .rtf file some text in, only by opening it with MS Word. But after writing some text in unicode, WordPad showed text is correctly.
Here are steps:
Create a file named .rtf
Open .rtf
Write there the following code in order to generate an RTF file which contains UTF-8 encoded content:
{\rtf1\adeflang1025\ansi
{\fonttbl
{\f26\fbidi \froman\fcharset204\fprq2{\*\panose 010a0502050306030303}Sylfaen;}
}
{\rtlch\fcs1 \af31507 \ltrch\fcs0 \f26 \u<unicode number>\'3f\u<unicode number>\'3f\u<unicode number>\'3 A lot of other text and symbols
like this: + - * _ }
}
For example:
{\rtf1\adeflang1025\ansi
{\fonttbl
{\f26\fbidi \froman\fcharset204\fprq2{\*\panose 010a0502050306030303}Sylfaen;}
}
{\rtlch\fcs1 \af31507 \ltrch\fcs0 \f26 \u1329\'3f\u1330\'3f\u1331\'3f\u1332\'3f - these are first 4 latters of Armenian alphabet}
}
Foe more details see the UTF-8 encoding table here. And RTF spec is here.