- added some logic to 'try' to figure out when to render font test right to left and when not to

This commit is contained in:
Mark Vejvoda
2011-06-09 05:54:04 +00:00
parent bc2c59a82a
commit fc3f5bbfa0
8 changed files with 202 additions and 28 deletions

View File

@@ -691,4 +691,59 @@ namespace Shared { namespace Util {
pBuffer[len] = 0;
}
void strrev(char *p) {
char *q = p;
while(q && *q) ++q;
for(--q; p < q; ++p, --q)
*p = *p ^ *q,
*q = *p ^ *q,
*p = *p ^ *q;
}
#define SWP(x,y) (x^=y, y^=x, x^=y)
void strrev_utf8(char *p) {
char *q = p;
strrev(p); /* call base case */
/* Ok, now fix bass-ackwards UTF chars. */
while(q && *q) ++q; /* find eos */
while(p < --q)
switch( (*q & 0xF0) >> 4 ) {
case 0xF: /* U+010000-U+10FFFF: four bytes. */
SWP(*(q-0), *(q-3));
SWP(*(q-1), *(q-2));
q -= 3;
break;
case 0xE: /* U+000800-U+00FFFF: three bytes. */
SWP(*(q-0), *(q-2));
q -= 2;
break;
case 0xC: /* fall-through */
case 0xD: /* U+000080-U+0007FF: two bytes. */
SWP(*(q-0), *(q-1));
q--;
break;
}
}
void strrev_utf8(std::string &p) {
char szBuf[p.size()+1];
strcpy(szBuf,p.c_str());
szBuf[p.size()+1] = '\0';
strrev_utf8(&szBuf[0]);
p = szBuf;
}
bool is_string_all_ascii(std::string str) {
bool result = true;
for(int i = 0; i < str.length(); ++i) {
if(isascii(str[i]) == false) {
result = false;
break;
}
}
return result;
}
}}