Capitalizing 1st letters of First, and last name... ? Firstname_Lastname
#7

Here is full function list what you will need. It allows only Name_Lastname.
to check name use NameIsRP
Credits to PR-RP script
pawn Код:
IsUpper(ch)
{
    if(ch>64&&ch<91) return 1;
    return 0;
}

TooManyCaps(name[])
{
    new Float:caps,num,sz;
    sz=strlen(name[0]);
    while(sz--) {
    if(IsUpper(name[sz])) num++;
    }
    caps=floatdiv(num,float(strlen(name[0])-1)); //-1 because we don't include the _ in the percentage
    caps=floatmul(caps,float(100));
    if(caps>40) return 1; //40% seems to be the magic number for names
    return 0;
}

CapsOnEnd(name[])
{
    new sz;
    sz=strlen(name[0]);
    if(IsUpper(name[sz-1])) return 1;
    if(IsUpper(name[FirstSeperationLoc(name[0])-1])) return 1;
    return 0;
}

ConsecutiveCaps(name[])
{
    new sz,lastcaps;
    sz=strlen(name[0]);
    while(sz--) {
    if(IsUpper(name[sz])) {
    if(lastcaps==1) {
    return 1;
    }
    lastcaps=1;
    } else lastcaps=0;
    }
    return 0;
}

TooShortOnEnd(name[])
{
    new pnt;
    pnt=FirstSeperationLoc(name[0]);
    name[pnt]=0;
    if((strlen(name[0])<3)||strlen(name[pnt+1])<3) {
    name[pnt]='_'; //restore it for use later
    return 1;
     }
    name[pnt]='_';
    return 0;
}

NumOccurences(str[],ch)
{
    new num=0,strl;
    strl=strlen(str);
    while(strl--) {
    if(str[strl]==ch) num++;
    }
    return num;
}

IsInvalid(x)
{
    if(x==95) return 0;
    if(x>64&&x<91) return 0;
    if(x>96&&x<123) return 0;
    return 1;
}

FirstSeperationLoc(str[])
{
    new strl;
    strl=strlen(str);
    while(strl--) {
    if(str[strl]=='_') return strl;
    }
    return 0;
}

InvalidCaps(str[])
{
    if(!IsUpper(str[0])||!IsUpper(str[FirstSeperationLoc(str[0])+1])) return 1;
    return 0;
}

NameIsRP(name[])
{
    new len;
    len=strlen(name[0]);
    if(InvalidCaps(name[0]) || NumOccurences(name[0],'_') != 1) return 0;
    while(len--) {
    if(IsInvalid(name[len])) return 0;
    }
    if(TooManyCaps(name[0])) return 0;
    if(ConsecutiveCaps(name[0])) return 0;
    if(CapsOnEnd(name[0])) return 0;
    if(TooShortOnEnd(name[0])) return 0;
    return 1;
}
Edit: Bwah wrong thread
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)