Exemplo n.º 1
0
int main(int argc,char **argv)
    {
    FILE * f = fopen("foldingLenghts.txt","wb");
    int cmp = strCaseCmp("MASSE","Maße");
    fprintf(f,"MASSE %s Maße\n",cmp == 0? "==" : cmp < 0 ? "<" : ">");
    for(int y=0;y < 0x11000;++y)
        {
        int L = lowerEquivalent(y);
        int U = upperEquivalent(y);
        if(L == y && U == y)
            continue;
        char buf1[5];
        char buf2[5];
        char buf3[5];
        buf1[UnicodeToUtf8(y,buf1,5)] = '\0';
        buf2[UnicodeToUtf8(L,buf2,5)] = '\0';
        buf3[UnicodeToUtf8(U,buf3,5)] = '\0';
        if(y < 0x80)
            {
            if(L >= 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x>0x80  %x\n",L,y);
                }
            if(U >= 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x>0x80  %x\n",U,y);
                }
            }
        else if(y < 0x800)
            {
            if(L >= 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x>0x800  %x\n",L,y);
                }
            else if(L < 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x<0x80  %x\n",L,y);
                }
            if(U >= 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x>0x800  %x\n",U,y);
                }
            else if(U < 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x<0x80  %x\n",U,y);
                }
            }
        else if(y < 0x10000)
            {
            if(L >= 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x>0x10000 %x\n",L,y);
                }
            else if(L < 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x<0x800  %x\n",L,y);
                }
            if(U >= 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x>0x10000 %x\n",U,y);
                }
            else if(U < 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x<0x800  %x\n",U,y);
                }
            }
        else
            {
            if(L < 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x<0x10000  %x\n",L,y);
                }
            if(U < 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x<0x10000  %x\n",U,y);
                }
            }
        }
    fclose(f);
    return 0;
    }
Exemplo n.º 2
0
static unsigned int parseRoman(unsigned int k)
    {
    static unsigned int Romans[] =
        {
/*   I_*/ 'i',I  ,F   ,     // i..
/*   I */  0 ,T  ,II_ ,     // i
/*  II_*/ 'i',II ,IV  ,     // ii..
/*  II */  0 ,T  ,III ,     // ii
/* III */ 'i',END,F   ,     // iii
/*  IV */ 'v',END,IX  ,     // iv
/*   V_*/ 'v',V  ,I_  ,     // v..
/*   V */  0 ,T  ,VI_ ,     // v
/*  VI_*/ 'i',VI ,F   ,     // vi..
/*  VI */  0 ,T  ,VII_,     // vi
/* VII_*/ 'i',II ,F   ,     // vii..
/*  IX */ 'x',END,F   ,
/*   X_*/ 'x',X  ,V_  ,     // x..
/*   X */  0 ,T  ,XX_ ,     // x
/*  XX_*/ 'x',XX ,XL  ,     // xx..
/*  XX */  0 ,T  ,XXX ,     // xx
/* XXX */ 'x',ONE,ONE ,     // xxx..
/*  XL */ 'l',ONE,XC_ ,     // xl..
/*   L_*/ 'l',L  ,X_  ,     // l..
/*   L */  0 ,T  ,LX_ ,     // l
/*  LX_*/ 'x',LX ,ONE ,     // lx..
/*  LX */  0 ,T  ,LXX_,     // lx
/* LXX_*/ 'x',XX ,ONE ,     // lxx.. 
/*  XC_*/ 'c',ONE,ONE ,     // XC..
/* ONE */  0 ,T  ,V_  ,     // 1-9
/*   C_*/ 'c',C  ,L_  ,     // c..
/*   C */  0 ,T  ,CC_ ,     // c
/*  CC_*/ 'c',CC ,CD  ,     // cc..
/*  CC */  0 ,T  ,CCC ,     // cc
/* CCC */ 'c',TEN,TEN ,     // ccc..
/*  CD */ 'd',TEN,CM_ ,     // cd..
/*   D_*/ 'd',D  ,C_  ,     // d..
/*   D */  0 ,T  ,DC_ ,     // d
/*  DC_*/ 'c',DC ,TEN ,     // dc..
/*  DC */  0 ,T  ,DCC_,     // dc
/* DCC_*/ 'c',CC ,TEN ,     // dcc.. 
/*  CM_*/ 'M',TEN,TEN ,     // cm..
/* TEN */  0 ,T  ,L_  ,     // 10-99
/*   M_*/ 'm',M  ,D_  ,     // m..
/*   M */  0 ,T  ,MM_ ,     // m
/*  MM_*/ 'm',MM ,D_   ,     // mm..
/*  MM */  0 ,T  ,MMM ,     // mm
/* MMM */ 'm',CEN,CEN ,     // mmm..
/* CEN */  0 ,T  ,D_  ,     // 1-9
/* END */  0 ,T ,F
        };
    static unsigned int index = M_;
    static bool Upper = false;

    if(k == 128)
        {
        index = M_;
        return M_;
        }

    if(index == T || index == F)
        {
        index = F;
        return F;
        }

    if(k <= ' ')
        k = 0;

    if(index == M_)
        {
        if(strchr("IVXLCDM",k))
            {
            Upper = true;
            k = lowerEquivalent(k);
            }
        else if(strchr("ivxlcdm",k))
            Upper = false;
        else
            {
            index = F;
            return F;
            }
        }
    else if(Upper)
        {
        if(!strchr("IVXLCDM",k))
            {
            index = F;
            return F;
            }
        k = lowerEquivalent(k);
        }
    else
        {
        if(!strchr("ivxlcdm",k))
            {
            index = F;
            return F;
            }
        }

    for(;index != T && index != F;)
        {
        if(k == Romans[3*index])
            {
            index = Romans[3*index+1];
            break;
            }
        else
            {
            index = Romans[3*index+2];
            }
        }

    return index;
    }