CamelCase in Pike

Example for versions Pike 7.8

This example implements character-by-character string processing. The only thing to note is that Pike provides no data type for characters. text[i] would return an integer — ASCII-code of the corresponding character. To get i-th character as a string variable, one has to use text[i..i] which is operation of extracting substring from a string.

void main() 
{
    string text = lower_case(Stdio.stdin->gets());
    string cc = "";
    int i, lastSpace = 1;

    for (i=0; i<sizeof(text); i++) 
    {
        if (text[i] >= 'a' && text[i] <= 'z') 
        {
            if (lastSpace == 1)
                cc += upper_case(text[i..i]);
            else
                cc += text[i..i];
            lastSpace = 0;
        }
        else
            lastSpace = 1;
    }
    write(cc+"\n");
}