summaryrefslogtreecommitdiff
path: root/base/base_rune.c
diff options
context:
space:
mode:
Diffstat (limited to 'base/base_rune.c')
-rw-r--r--base/base_rune.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/base/base_rune.c b/base/base_rune.c
index 4aa81df3..32168792 100644
--- a/base/base_rune.c
+++ b/base/base_rune.c
@@ -41,7 +41,8 @@ chartorune(int *rune, char *str)
* 00000-0007F => T1
*/
c = *(unsigned char*)str;
- if(c < Tx) {
+ if (c < Tx)
+ {
*rune = c;
return 1;
}
@@ -51,13 +52,14 @@ chartorune(int *rune, char *str)
* 0080-07FF => T2 Tx
*/
c1 = *(unsigned char*)(str+1) ^ Tx;
- if(c1 & Testx)
+ if (c1 & Testx)
goto bad;
- if(c < T3) {
- if(c < T2)
+ if (c < T3)
+ {
+ if (c < T2)
goto bad;
l = ((c << Bitx) | c1) & Rune2;
- if(l <= Rune1)
+ if (l <= Rune1)
goto bad;
*rune = l;
return 2;
@@ -68,11 +70,12 @@ chartorune(int *rune, char *str)
* 0800-FFFF => T3 Tx Tx
*/
c2 = *(unsigned char*)(str+2) ^ Tx;
- if(c2 & Testx)
+ if (c2 & Testx)
goto bad;
- if(c < T4) {
+ if (c < T4)
+ {
l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
- if(l <= Rune2)
+ if (l <= Rune2)
goto bad;
*rune = l;
return 3;
@@ -96,7 +99,8 @@ runetochar(char *str, int *rune)
* 00000-0007F => 00-7F
*/
c = *rune;
- if(c <= Rune1) {
+ if (c <= Rune1)
+ {
str[0] = c;
return 1;
}
@@ -105,7 +109,8 @@ runetochar(char *str, int *rune)
* two character sequence
* 0080-07FF => T2 Tx
*/
- if(c <= Rune2) {
+ if (c <= Rune2)
+ {
str[0] = T2 | (c >> 1*Bitx);
str[1] = Tx | (c & Maskx);
return 2;
@@ -137,12 +142,12 @@ runenlen(int *r, int nrune)
int nb, c;
nb = 0;
- while(nrune--) {
+ while (nrune--)
+ {
c = *r++;
- if(c <= Rune1)
+ if (c <= Rune1)
nb++;
- else
- if(c <= Rune2)
+ else if (c <= Rune2)
nb += 2;
else
nb += 3;
@@ -155,12 +160,13 @@ fullrune(char *str, int n)
{
int c;
- if(n > 0) {
+ if (n > 0)
+ {
c = *(unsigned char*)str;
- if(c < Tx)
+ if (c < Tx)
return 1;
- if(n > 1)
- if(c < T3 || n > 2)
+ if (n > 1)
+ if (c < T3 || n > 2)
return 1;
}
return 0;