'===========================================================================
' Subject: UPPERCASE PB LINE OF CODE          Date: 12-20-95 (00:00)       
'  Author: Jamshid Khoshrangi                 Code: PB                     
'  Origin: qjackson@direct.ca               Packet: PB.ABC
'===========================================================================
$IF 0

                           Released to the public domain.
                           Written by Jamshid Khoshrangi.

                                    20 DEC 1995

    PB_UCASE() returns the uppercase of a PowerBASIC line of code --

    That is to say, everything is uppercased that is OUTSIDE of quotes
    and that ISN'T a comment.

    I've used as many tricks as I can think of to make it as fast as
    possible, short of using inline ASM.

    For speed, this code uses pointers, and therefore is compatible 
    with PowerBASIC 3.2+ only.

$ENDIF

DEFINT A-Z

CLS

Q$= CHR$(34)

InText$ = "Print "+Q$+"This is a test!"+Q$+_
          "; SomeOtherStuff ' This is a comment"

'InText$ = "Print 5 ' comment"

PRINT InText$

MTIMER
Temp$ = PB_UCASE (InText$)
PRINT MTIMER

PRINT Temp$

FUNCTION PB_UCASE (BYVAL InText AS STRING) AS STRING

    FirstQuote = INSTR(InText, CHR$(34))

    ' We uppercase every up to the first quotatation mark.  It's a
    ' bit faster this way, since we can skip over a lot of initial
    ' command stuff at once.
    MID$(InText, 1, FirstQuote) = UCASE$(LEFT$(InText, FirstQuote))

    ' I love pointers.  Thank you PowerBASIC!
    DIM InTextPtr AS BYTE PTR
    InTextPtr  = STRPTR32(InText) + FirstQuote

    IF FirstQuote THEN
        InLiteral = -1
    END IF

    FOR i = 1 TO LEN(InText) - FirstQuote

        IF @InTextPtr > 96 THEN
            IF @InTextPtr < 123 THEN
                IF NOT InLiteral THEN
                    '   This has the effect of uppercasing the byte.
                    BIT RESET @InTextPtr, 5
                END IF
            END IF
        ELSE
            IF @InTextPtr = 34 THEN
                InLiteral = NOT InLiteral
            ELSE
                IF NOT InLiteral THEN
                    IF @InTextPtr = 39 THEN
                        FUNCTION = InText
                        EXIT FUNCTION
                    END IF
                END IF
            END IF
        END IF

        INCR InTextPtr

    NEXT i

    FUNCTION = InText

END FUNCTION
