PAText UTF8: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Remove non-functioning "toc" command)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[toc align_right="yes" depth="3"]
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
 


= PAText (UTF-8 Version) =
= PAText (UTF-8 Version) =


Pointing to the previous multi-byte version ("link":http://wiki.qt.io/QPlugs_PAText_Add_Persian_and_Arabic_support_to_WindowsCE_Mobile_applications) the new version comes with improvements and better functionality.
Pointing to the previous multi-byte version ([http://wiki.qt.io/QPlugs_PAText_Add_Persian_and_Arabic_support_to_WindowsCE_Mobile_applications link]) the new version comes with improvements and better functionality.


== Changes ==
== Changes ==
Line 24: Line 25:
=== "patext.h" ===
=== "patext.h" ===


<code><br />/*''''''<br /> PAText (UTF-8) by Mohsen Kh.Akhlaghi<br /> Ver 2.1.0 Release 2013/01/26<br /> www.madagon.com<br />*/<br />#ifndef PAText_H<br />#define PAText_H<br />#include <QString>
<code>
<br />class PAText<br />{<br />public:<br /> static QString translate(QByteArray pText);<br /> static QString detranslate(QByteArray pText);<br />};
/*''''''
<br />#endif // PAText_H<br /></code>
PAText (UTF-8) by Mohsen Kh.Akhlaghi
<br />h3. "patext.cpp"
Ver 2.1.0 Release 2013/01/26
<br /><code><br />/'''<br /> PAText (UTF-8) by Mohsen Kh.Akhlaghi<br /> Ver 2.1.0 Release 2013/01/26<br /> www.madagon.com<br />''''''*/<br />#include "PAText.h"<br />#include <QList>
www.madagon.com
*/
#ifndef PAText_H
#define PAText_H
#include <QString>
 
class PAText
{
public:
static QString translate(QByteArray pText);
static QString detranslate(QByteArray pText);
};
 
#endif // PAText_H
</code>
 
=== "patext.cpp" ===
<code>
/'''
PAText (UTF-8) by Mohsen Kh.Akhlaghi
Ver 2.1.0 Release 2013/01/26
www.madagon.com
''''''*/
#include "PAText.h"
#include <QList>
 
static const int mapsize=42;
static ushort PAMap[42][5]=
{ //Base Final Initial Medial Isolated
{0x630, 0xfeac, 0xfeab, 0xfeac, 0xfeab}, //ذ 0
{0x62f, 0xfeaa, 0xfea9, 0xfeaa, 0xfea9}, //د 1
{0x62c, 0xfe9e, 0xfe9f, 0xfea0, 0xfe9d}, //ج 2
{0x62d, 0xfea2, 0xfea3, 0xfea4, 0xfea1}, //ح 3
{0x62e, 0xfea6, 0xfea7, 0xfea8, 0xfea5}, //خ 4
{0x647, 0xfeea, 0xfeeb, 0xfeec, 0xfee9}, //ه 5
{0x639, 0xfeca, 0xfecb, 0xfecc, 0xfec9}, //ع 6
{0x63a, 0xfece, 0xfecf, 0xfed0, 0xfecd}, //غ 7
{0x641, 0xfed2, 0xfed3, 0xfed4, 0xfed1}, //ف 8
{0x642, 0xfed6, 0xfed7, 0xfed8, 0xfed5}, //ق 9
{0x62b, 0xfe9a, 0xfe9b, 0xfe9c, 0xfe99}, //ث 10
{0x635, 0xfeba, 0xfebb, 0xfebc, 0xfeb9}, //ص 11
{0x636, 0xfebe, 0xfebf, 0xfec0, 0xfebd}, //ض 12
{0x637, 0xfec2, 0xfec3, 0xfec4, 0xfec1}, //ط 13
{0x643, 0xfeda, 0xfedb, 0xfedc, 0xfed9}, //ك 14
{0x645, 0xfee2, 0xfee3, 0xfee4, 0xfee1}, //م 15
{0x646, 0xfee6, 0xfee7, 0xfee8, 0xfee5}, //ن 16
{0x62a, 0xfe96, 0xfe97, 0xfe98, 0xfe95}, //ت 17
{0x627, 0xfe8e, 0xfe8d, 0xfe8e, 0xfe8d}, //ا 18
{0x644, 0xfede, 0xfedf, 0xfee0, 0xfedd}, //ل 19
{0x628, 0xfe90, 0xfe91, 0xfe92, 0xfe8f}, //ب 20
{0x64a, 0xfef2, 0xfef3, 0xfef4, 0xfef1}, //21 ي
{0x633, 0xfeb2, 0xfeb3, 0xfeb4, 0xfeb1}, //س 22
{0x634, 0xfeb6, 0xfeb7, 0xfeb8, 0xfeb5}, //ش 23
{0x638, 0xfec6, 0xfec7, 0xfec8, 0xfec5}, //ظ 24
{0x632, 0xfeb0, 0xfeaf, 0xfeb0, 0xfeaf}, //ز 25
{0x625, 0xfe88, 0xfe87, 0xfe88, 0xfe87}, //إ 26
{0x6A9, 0xfb8f, 0xfb90, 0xfb91, 0xfb8e}, //ک 27
{0x6Af, 0xfb93, 0xfb94, 0xfb95, 0xfb92}, //گ 28
{0x698, 0xfb8b, 0xfb8a, 0xfb8b, 0xfb8a}, //ژ 29
{0x686, 0xfb7b, 0xfb7c, 0xfb7d, 0xfb7a}, //چ 30
{0x67E, 0xfb57, 0xfb58, 0xfb59, 0xfb56}, //پ 31
{0x648, 0xfeee, 0xfeed, 0xfeee, 0xfeed}, //و 32
{0x629, 0xfe94, 0xfe93, 0xfe93, 0xfe93}, //ة 33
{0x649, 0xfef0, 0xfef3, 0xfef4, 0xfeef}, //ى 34
{0x631, 0xfeae, 0xfead, 0xfeae, 0xfead}, //ر 35
{0x624, 0xfe86, 0xfe85, 0xfe86, 0xfe85}, //ؤ 36
{0x621, 0xfe80, 0xfe80, 0xfe80, 0xfe7f}, //ء 37
{0x626, 0xfe8a, 0xfe8b, 0xfe8c, 0xfe89}, //ئ 38
{0x623, 0xfe84, 0xfe83, 0xfe84, 0xfe83}, //أ 39
{0x622, 0xfe82, 0xfe81, 0xfe82, 0xfe81}, //آ 40
{0x6cc, 0xfbfd, 0xfbfe, 0xfbff, 0xfbfc}, //ى 41
};
 
static int charInMap(QCharRef &pChar)
{
int j;
for (int i=0;i<mapsize;i+''){
for (j=0;j<5;j){
if (pChar==PAMap[i][j]) return i;
}
}
 
return –1;
}
 
static bool charC(QCharRef &pChar)
{
static const int sp_sz=13;
static int sp[]={0,1,18,25,26,29,32,33,35,36,37,39,40};
 
int j;
 
for (int i=0;i<mapsize;i){
for (j=0;j<5;j){
if (pCharPAMap[i][j]){
                for (j=0;j<sp_sz;j++) if (sp[j]i) return true;
return false;
}
}
}
 
return true;
}
 
static QString &isolate(QString &str, bool reverse=false)
{
static QString find[]={
QString().append(PAMap[19][2]).append(PAMap[18][1]),//ﻻ
QString().append(PAMap[19][3]).append(PAMap[18][1]),//ﻼ
QString().append(PAMap[19][2]).append(PAMap[26][1]),//ﻹ
QString().append(PAMap[19][3]).append(PAMap[26][1]),//ﻺ
QString().append(PAMap[19][2]).append(PAMap[39][1]),//ﻷ
QString().append(PAMap[19][3]).append(PAMap[39][1]),//ﻸ
QString().append(PAMap[18][0]).append(PAMap[19][2]).append(PAMap[19][3]).append(PAMap[5][1]) //ﷲ
};
 
static QString replace[]={
QString(0xfefb),
QString(0xfefc),
QString(0xfef9),
QString(0xfefa),
QString(0xfef7),
QString(0xfef8),
QString(0xfdf2)
};
 
static const int sz=7;
 
if (!reverse){
for (int i=0; i<sz; i) str.replace(find[i],replace[i]);
} else{
for (int i=0; i<sz; i) str.replace(replace[i],find[i]);
}
 
return str;
}
 
QString PAText::translate(QByteArray pText)
{
QString text=isolate(QString::fromUtf8(pText),true);
int sz=text.size();
QString r;
int cpoint;
QList<int> cursor;
 
for (int i=0; i<sz; i){
cpoint=charInMap(text[i]);
 
cursor << cpoint;
if (cpoint<0){
r.append(text[i]);
continue;
}
 
if (i==0){
r.append(PAMap[cpoint][0]);
} else{
QCharRef prev=text[i-1];
if (charC(prev)){ //prev special
r.append(PAMap[cpoint][0]);
} else{
if (cursor[i-1]>0){
if (i>1){
QCharRef pprev=text[i-2];
if (charC(pprev)){ //pprev special
r[i-1]=PAMap[cursor[i-1]][2];
} else{
r[i-1]=PAMap[cursor[i-1]][3];
}
} else{
r[i-1]=PAMap[cursor[i-1]][2];
}
 
r.append(PAMap[cpoint][1]);
} else{
r.append(PAMap[cpoint][0]);
}
 
}
}
}
 
return isolate®;
}


static const int mapsize=42;<br />static ushort PAMap[42][5]=<br />{ //Base Final Initial Medial Isolated<br /> {0x630, 0xfeac, 0xfeab, 0xfeac, 0xfeab}, //ذ 0<br /> {0x62f, 0xfeaa, 0xfea9, 0xfeaa, 0xfea9}, //د 1<br /> {0x62c, 0xfe9e, 0xfe9f, 0xfea0, 0xfe9d}, //ج 2<br /> {0x62d, 0xfea2, 0xfea3, 0xfea4, 0xfea1}, //ح 3<br /> {0x62e, 0xfea6, 0xfea7, 0xfea8, 0xfea5}, //خ 4<br /> {0x647, 0xfeea, 0xfeeb, 0xfeec, 0xfee9}, //ه 5<br /> {0x639, 0xfeca, 0xfecb, 0xfecc, 0xfec9}, //ع 6<br /> {0x63a, 0xfece, 0xfecf, 0xfed0, 0xfecd}, //غ 7<br /> {0x641, 0xfed2, 0xfed3, 0xfed4, 0xfed1}, //ف 8<br /> {0x642, 0xfed6, 0xfed7, 0xfed8, 0xfed5}, //ق 9<br /> {0x62b, 0xfe9a, 0xfe9b, 0xfe9c, 0xfe99}, //ث 10<br /> {0x635, 0xfeba, 0xfebb, 0xfebc, 0xfeb9}, //ص 11<br /> {0x636, 0xfebe, 0xfebf, 0xfec0, 0xfebd}, //ض 12<br /> {0x637, 0xfec2, 0xfec3, 0xfec4, 0xfec1}, //ط 13<br /> {0x643, 0xfeda, 0xfedb, 0xfedc, 0xfed9}, //ك 14<br /> {0x645, 0xfee2, 0xfee3, 0xfee4, 0xfee1}, //م 15<br /> {0x646, 0xfee6, 0xfee7, 0xfee8, 0xfee5}, //ن 16<br /> {0x62a, 0xfe96, 0xfe97, 0xfe98, 0xfe95}, //ت 17<br /> {0x627, 0xfe8e, 0xfe8d, 0xfe8e, 0xfe8d}, //ا 18<br /> {0x644, 0xfede, 0xfedf, 0xfee0, 0xfedd}, //ل 19<br /> {0x628, 0xfe90, 0xfe91, 0xfe92, 0xfe8f}, //ب 20<br /> {0x64a, 0xfef2, 0xfef3, 0xfef4, 0xfef1}, //21 ي<br /> {0x633, 0xfeb2, 0xfeb3, 0xfeb4, 0xfeb1}, //س 22<br /> {0x634, 0xfeb6, 0xfeb7, 0xfeb8, 0xfeb5}, //ش 23<br /> {0x638, 0xfec6, 0xfec7, 0xfec8, 0xfec5}, //ظ 24<br /> {0x632, 0xfeb0, 0xfeaf, 0xfeb0, 0xfeaf}, //ز 25<br /> {0x625, 0xfe88, 0xfe87, 0xfe88, 0xfe87}, //إ 26<br /> {0x6A9, 0xfb8f, 0xfb90, 0xfb91, 0xfb8e}, //ک 27<br /> {0x6Af, 0xfb93, 0xfb94, 0xfb95, 0xfb92}, //گ 28<br /> {0x698, 0xfb8b, 0xfb8a, 0xfb8b, 0xfb8a}, //ژ 29<br /> {0x686, 0xfb7b, 0xfb7c, 0xfb7d, 0xfb7a}, //چ 30<br /> {0x67E, 0xfb57, 0xfb58, 0xfb59, 0xfb56}, //پ 31<br /> {0x648, 0xfeee, 0xfeed, 0xfeee, 0xfeed}, //و 32<br /> {0x629, 0xfe94, 0xfe93, 0xfe93, 0xfe93}, //ة 33<br /> {0x649, 0xfef0, 0xfef3, 0xfef4, 0xfeef}, //ى 34<br /> {0x631, 0xfeae, 0xfead, 0xfeae, 0xfead}, //ر 35<br /> {0x624, 0xfe86, 0xfe85, 0xfe86, 0xfe85}, //ؤ 36<br /> {0x621, 0xfe80, 0xfe80, 0xfe80, 0xfe7f}, //ء 37<br /> {0x626, 0xfe8a, 0xfe8b, 0xfe8c, 0xfe89}, //ئ 38<br /> {0x623, 0xfe84, 0xfe83, 0xfe84, 0xfe83}, //أ 39<br /> {0x622, 0xfe82, 0xfe81, 0xfe82, 0xfe81}, //آ 40<br /> {0x6cc, 0xfbfd, 0xfbfe, 0xfbff, 0xfbfc}, //ى 41<br />};
QString PAText::detranslate(QByteArray pText)
{
QString text=isolate(QString::fromUtf8(pText),true);
QString r;
int sz=text.size();
int cpoint;


static int charInMap(QCharRef &amp;pChar)<br />{<br /> int j;<br /> for (int i=0;i<mapsize;i+''){<br /> for (j=0;j<5;j){<br /> if (pChar==PAMap[i][j]) return i;<br /> }<br /> }
for (int i=0; i<sz; i''+){
<br /> return –1;<br />}
cpoint=charInMap(text[i]);
<br />static bool charC(QCharRef &amp;pChar)<br />{<br /> static const int sp_sz=13;<br /> static int sp[]={0,1,18,25,26,29,32,33,35,36,37,39,40};
<br /> int j;
<br /> for (int i=0;i<mapsize;i){<br /> for (j=0;j<5;j){<br /> if (pCharPAMap[i][j]){
                for (j=0;j<sp_sz;j++) if (sp[j]i) return true;<br /> return false;<br /> }<br /> }<br /> }
<br /> return true;<br />}
<br />static QString &amp;isolate(QString &amp;str, bool reverse=false)<br />{<br /> static QString find[]={<br /> QString().append(PAMap[19][2]).append(PAMap[18][1]),//ﻻ<br /> QString().append(PAMap[19][3]).append(PAMap[18][1]),//ﻼ<br /> QString().append(PAMap[19][2]).append(PAMap[26][1]),//ﻹ<br /> QString().append(PAMap[19][3]).append(PAMap[26][1]),//ﻺ<br /> QString().append(PAMap[19][2]).append(PAMap[39][1]),//ﻷ<br /> QString().append(PAMap[19][3]).append(PAMap[39][1]),//ﻸ<br /> QString().append(PAMap[18][0]).append(PAMap[19][2]).append(PAMap[19][3]).append(PAMap[5][1]) //ﷲ<br /> };
<br /> static QString replace[]={<br /> QString(0xfefb),<br /> QString(0xfefc),<br /> QString(0xfef9),<br /> QString(0xfefa),<br /> QString(0xfef7),<br /> QString(0xfef8),<br /> QString(0xfdf2)<br /> };
<br /> static const int sz=7;
<br /> if (!reverse){<br /> for (int i=0; i<sz; i) str.replace(find[i],replace[i]);<br /> } else{<br /> for (int i=0; i<sz; i) str.replace(replace[i],find[i]);<br /> }
<br /> return str;<br />}
<br />QString PAText::translate(QByteArray pText)<br />{<br /> QString text=isolate(QString::fromUtf8(pText),true);<br /> int sz=text.size();<br /> QString r;<br /> int cpoint;<br /> QList<int> cursor;
<br /> for (int i=0; i<sz; i){<br /> cpoint=charInMap(text[i]);
<br /> cursor << cpoint;<br /> if (cpoint<0){<br /> r.append(text[i]);<br /> continue;<br /> }
<br /> if (i==0){<br /> r.append(PAMap[cpoint][0]);<br /> } else{<br /> QCharRef prev=text[i-1];<br /> if (charC(prev)){ //prev special<br /> r.append(PAMap[cpoint][0]);<br /> } else{<br /> if (cursor[i-1]>0){<br /> if (i>1){<br /> QCharRef pprev=text[i-2];<br /> if (charC(pprev)){ //pprev special<br /> r[i-1]=PAMap[cursor[i-1]][2];<br /> } else{<br /> r[i-1]=PAMap[cursor[i-1]][3];<br /> }<br /> } else{<br /> r[i-1]=PAMap[cursor[i-1]][2];<br /> }
<br /> r.append(PAMap[cpoint][1]);<br /> } else{<br /> r.append(PAMap[cpoint][0]);<br /> }
<br /> }<br /> }<br /> }
<br /> return isolate®;<br />}
<br />QString PAText::detranslate(QByteArray pText)<br />{<br /> QString text=isolate(QString::fromUtf8(pText),true);<br /> QString r;<br /> int sz=text.size();<br /> int cpoint;
<br /> for (int i=0; i<sz; i''+){<br /> cpoint=charInMap(text[i]);


if (cpoint<0){<br /> r.append(text[i]);<br /> continue;<br /> }
if (cpoint<0){
r.append(text[i]);
continue;
}


r.append(PAMap[cpoint][4]);<br /> }
r.append(PAMap[cpoint][4]);
}


return r;<br />}<br /></code>
return r;
}
</code>


== Sample Code ==
== Sample Code ==


<code><br />#include "patext.h"<br />.<br />.<br />qDebug() << PAText::translate("سلام");
<code>
#include "patext.h"
.
.
qDebug() << PAText::translate("سلام");

Latest revision as of 12:26, 17 April 2015

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.


PAText (UTF-8 Version)

Pointing to the previous multi-byte version (link) the new version comes with improvements and better functionality.

Changes

2.0.0

  • Process UTF-8 encoded bytes
  • Changed comparison method from "byte to byte" to "byte(s) to table", so even translated chars would be reformatted
  • Added isolator function which replaces ligature words
  • Fixed the character "ی" problems with Persian layout
  • No longer in QPlugs namespace

2.1.0

  • Added another Persian 'ی' character to the map table
  • Added "detranslate()" function for a reverse action

Source Code

"patext.h"

/*''''''
 PAText (UTF-8) by Mohsen Kh.Akhlaghi
 Ver 2.1.0 Release 2013/01/26
 www.madagon.com
*/
#ifndef PAText_H
#define PAText_H
#include <QString>

class PAText
{
public:
 static QString translate(QByteArray pText);
 static QString detranslate(QByteArray pText);
};

#endif // PAText_H

"patext.cpp"

/'''
 PAText (UTF-8) by Mohsen Kh.Akhlaghi
 Ver 2.1.0 Release 2013/01/26
 www.madagon.com
''''''*/
#include "PAText.h"
#include <QList>

static const int mapsize=42;
static ushort PAMap[42][5]=
{ //Base Final Initial Medial Isolated
 {0x630, 0xfeac, 0xfeab, 0xfeac, 0xfeab}, //ذ 0
 {0x62f, 0xfeaa, 0xfea9, 0xfeaa, 0xfea9}, //د 1
 {0x62c, 0xfe9e, 0xfe9f, 0xfea0, 0xfe9d}, //ج 2
 {0x62d, 0xfea2, 0xfea3, 0xfea4, 0xfea1}, //ح 3
 {0x62e, 0xfea6, 0xfea7, 0xfea8, 0xfea5}, //خ 4
 {0x647, 0xfeea, 0xfeeb, 0xfeec, 0xfee9}, //ه 5
 {0x639, 0xfeca, 0xfecb, 0xfecc, 0xfec9}, //ع 6
 {0x63a, 0xfece, 0xfecf, 0xfed0, 0xfecd}, //غ 7
 {0x641, 0xfed2, 0xfed3, 0xfed4, 0xfed1}, //ف 8
 {0x642, 0xfed6, 0xfed7, 0xfed8, 0xfed5}, //ق 9
 {0x62b, 0xfe9a, 0xfe9b, 0xfe9c, 0xfe99}, //ث 10
 {0x635, 0xfeba, 0xfebb, 0xfebc, 0xfeb9}, //ص 11
 {0x636, 0xfebe, 0xfebf, 0xfec0, 0xfebd}, //ض 12
 {0x637, 0xfec2, 0xfec3, 0xfec4, 0xfec1}, //ط 13
 {0x643, 0xfeda, 0xfedb, 0xfedc, 0xfed9}, //ك 14
 {0x645, 0xfee2, 0xfee3, 0xfee4, 0xfee1}, //م 15
 {0x646, 0xfee6, 0xfee7, 0xfee8, 0xfee5}, //ن 16
 {0x62a, 0xfe96, 0xfe97, 0xfe98, 0xfe95}, //ت 17
 {0x627, 0xfe8e, 0xfe8d, 0xfe8e, 0xfe8d}, //ا 18
 {0x644, 0xfede, 0xfedf, 0xfee0, 0xfedd}, //ل 19
 {0x628, 0xfe90, 0xfe91, 0xfe92, 0xfe8f}, //ب 20
 {0x64a, 0xfef2, 0xfef3, 0xfef4, 0xfef1}, //21 ي
 {0x633, 0xfeb2, 0xfeb3, 0xfeb4, 0xfeb1}, //س 22
 {0x634, 0xfeb6, 0xfeb7, 0xfeb8, 0xfeb5}, //ش 23
 {0x638, 0xfec6, 0xfec7, 0xfec8, 0xfec5}, //ظ 24
 {0x632, 0xfeb0, 0xfeaf, 0xfeb0, 0xfeaf}, //ز 25
 {0x625, 0xfe88, 0xfe87, 0xfe88, 0xfe87}, //إ 26
 {0x6A9, 0xfb8f, 0xfb90, 0xfb91, 0xfb8e}, //ک 27
 {0x6Af, 0xfb93, 0xfb94, 0xfb95, 0xfb92}, //گ 28
 {0x698, 0xfb8b, 0xfb8a, 0xfb8b, 0xfb8a}, //ژ 29
 {0x686, 0xfb7b, 0xfb7c, 0xfb7d, 0xfb7a}, //چ 30
 {0x67E, 0xfb57, 0xfb58, 0xfb59, 0xfb56}, //پ 31
 {0x648, 0xfeee, 0xfeed, 0xfeee, 0xfeed}, //و 32
 {0x629, 0xfe94, 0xfe93, 0xfe93, 0xfe93}, //ة 33
 {0x649, 0xfef0, 0xfef3, 0xfef4, 0xfeef}, //ى 34
 {0x631, 0xfeae, 0xfead, 0xfeae, 0xfead}, //ر 35
 {0x624, 0xfe86, 0xfe85, 0xfe86, 0xfe85}, //ؤ 36
 {0x621, 0xfe80, 0xfe80, 0xfe80, 0xfe7f}, //ء 37
 {0x626, 0xfe8a, 0xfe8b, 0xfe8c, 0xfe89}, //ئ 38
 {0x623, 0xfe84, 0xfe83, 0xfe84, 0xfe83}, //أ 39
 {0x622, 0xfe82, 0xfe81, 0xfe82, 0xfe81}, //آ 40
 {0x6cc, 0xfbfd, 0xfbfe, 0xfbff, 0xfbfc}, //ى 41
};

static int charInMap(QCharRef &pChar)
{
 int j;
 for (int i=0;i<mapsize;i+''){
 for (j=0;j<5;j){
 if (pChar==PAMap[i][j]) return i;
 }
 }

 return 1;
}

static bool charC(QCharRef &pChar)
{
 static const int sp_sz=13;
 static int sp[]={0,1,18,25,26,29,32,33,35,36,37,39,40};

 int j;

 for (int i=0;i<mapsize;i){
 for (j=0;j<5;j){
 if (pCharPAMap[i][j]){
                for (j=0;j<sp_sz;j++) if (sp[j]i) return true;
 return false;
 }
 }
 }

 return true;
}

static QString &isolate(QString &str, bool reverse=false)
{
 static QString find[]={
 QString().append(PAMap[19][2]).append(PAMap[18][1]),//ﻻ
 QString().append(PAMap[19][3]).append(PAMap[18][1]),//ﻼ
 QString().append(PAMap[19][2]).append(PAMap[26][1]),//ﻹ
 QString().append(PAMap[19][3]).append(PAMap[26][1]),//ﻺ
 QString().append(PAMap[19][2]).append(PAMap[39][1]),//ﻷ
 QString().append(PAMap[19][3]).append(PAMap[39][1]),//ﻸ
 QString().append(PAMap[18][0]).append(PAMap[19][2]).append(PAMap[19][3]).append(PAMap[5][1]) //ﷲ
 };

 static QString replace[]={
 QString(0xfefb),
 QString(0xfefc),
 QString(0xfef9),
 QString(0xfefa),
 QString(0xfef7),
 QString(0xfef8),
 QString(0xfdf2)
 };

 static const int sz=7;

 if (!reverse){
 for (int i=0; i<sz; i) str.replace(find[i],replace[i]);
 } else{
 for (int i=0; i<sz; i) str.replace(replace[i],find[i]);
 }

 return str;
}

QString PAText::translate(QByteArray pText)
{
 QString text=isolate(QString::fromUtf8(pText),true);
 int sz=text.size();
 QString r;
 int cpoint;
 QList<int> cursor;

 for (int i=0; i<sz; i){
 cpoint=charInMap(text[i]);

 cursor << cpoint;
 if (cpoint<0){
 r.append(text[i]);
 continue;
 }

 if (i==0){
 r.append(PAMap[cpoint][0]);
 } else{
 QCharRef prev=text[i-1];
 if (charC(prev)){ //prev special
 r.append(PAMap[cpoint][0]);
 } else{
 if (cursor[i-1]>0){
 if (i>1){
 QCharRef pprev=text[i-2];
 if (charC(pprev)){ //pprev special
 r[i-1]=PAMap[cursor[i-1]][2];
 } else{
 r[i-1]=PAMap[cursor[i-1]][3];
 }
 } else{
 r[i-1]=PAMap[cursor[i-1]][2];
 }

 r.append(PAMap[cpoint][1]);
 } else{
 r.append(PAMap[cpoint][0]);
 }

 }
 }
 }

 return isolate®;
}

QString PAText::detranslate(QByteArray pText)
{
 QString text=isolate(QString::fromUtf8(pText),true);
 QString r;
 int sz=text.size();
 int cpoint;

 for (int i=0; i<sz; i''+){
 cpoint=charInMap(text[i]);

if (cpoint<0){
 r.append(text[i]);
 continue;
 }

r.append(PAMap[cpoint][4]);
 }

return r;
}

Sample Code

  1. include "patext.h"

. . qDebug() << PAText::translate("سلام");