FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

TEXT

Manipulate text with missing toolbox functions


Here how I’ve implemented missing toolbox functions in FB to manipulate text stored whether in a handle or regular FB string.

' All functions can be called that way:
' FN functionName(@text$)
' or
' FN functionName (strHndl&)
' or
' FN functionName (efID,FBstrPtr&)

CLEAR LOCAL MODE
  DIM startAdr&,textLen,state%,OSErr%
LOCAL FN UpperText(textPtr&)
  state% = FN HGETSTATE(textPtr&)
  LONG IF state% >-1
    textLen% = FN GETHANDLESIZE(textPtr&)
    OSErr% = FN HLOCK(textPtr&)
    startAdr& = [textPtr&]
  XELSE
    textLen% = PEEK(textPtr&)
    startAdr& = textPtr& +1
  END IF
  `
  ` MOVE.L ^startAdr&,A0
  ` MOVE.W ^textLen,D0
  ` DC.W uppertext
  `
  IF state%>-1 THEN state% = FN HSETSTATE(textPtr&,state%)
END FN
'======================================
CLEAR LOCAL MODE
  DIM startAdr&,textLen,state%,OSErr%
LOCAL FN LowerText(textPtr&)
  state% = FN HGETSTATE(textPtr&)
  LONG IF state% >-1
    textLen% = FN GETHANDLESIZE(textPtr&)
    OSErr% = FN HLOCK(textPtr&)
    startAdr& = [textPtr&]
  XELSE
    textLen% = PEEK(textPtr&)
    startAdr& = textPtr& +1
  END IF
  `
  ` MOVE.L ^startAdr&,A0
  ` MOVE.W ^textLen,D0
  ` DC.W lowertext
  `
  IF state%>-1 THEN state% = FN HSETSTATE(textPtr&,state%)
END FN
'======================================
CLEAR LOCAL MODE
  DIM startAdr&,textLen,state%,OSErr%
LOCAL FN StripText(textPtr&)
  state% = FN HGETSTATE(textPtr&)
  LONG IF state% >-1
    textLen% = FN GETHANDLESIZE(textPtr&)
    OSErr% = FN HLOCK(textPtr&)
    startAdr& = [textPtr&]
  XELSE
    textLen% = PEEK(textPtr&)
    startAdr& = textPtr& +1
END IF
  `
  ` MOVE.L ^startAdr&,A0
  ` MOVE.W ^textLen,D0
  ` DC.W striptext
  `
  IF state%>-1 THEN state% = FN HSETSTATE(textPtr&,state%)
END FN
'======================================
CLEAR LOCAL MODE
  DIM startAdr&,textLen,state%,OSErr%
LOCAL FN StripUpperText(textPtr&)
  state% = FN HGETSTATE(textPtr&)
  LONG IF state% >-1
    textLen% = FN GETHANDLESIZE(textPtr&)
    OSErr% = FN HLOCK(textPtr&)
    startAdr& = [textPtr&]
  XELSE
    textLen% = PEEK(textPtr&)
    startAdr& = textPtr& +1
  END IF
  `
  ` MOVE.L ^startAdr&,A0
  ` MOVE.W ^textLen,D0
  ` DC.W stripuppertext
  `
  IF state%>-1 THEN state% = FN HSETSTATE(textPtr&,state%)
END FN
'=============================
CLEAR LOCAL MODE
  DIM txtPtr&,lgth
LOCAL FN UprString$(theString$, diacSens)
  txtPtr& = @theString$+1
 lght = LEN(theString$)

  ` move.l ^txtPtr&,a0
  ` move.w ^lght,d0
  ` tst.w ^diacSens
  ` beq.s L1
  ` dc.w $A054
  ` bra.s L2
  `L1 dc.w $A254
  `L2
END FN = theString$
'=============================
WINDOW 1
CALL TEXTFONT(_courier):CALL TEXTSIZE(14)
CLS:PRINT
test$ = "aàââäeéèêëiîïoôöuûücç"
PRINT "Test string =====> ";test$:PRINT

FN StripText(@test$)
PRINT "StripText =======> ";test$:PRINT

test$ = "aàââäeéèêëiîïoôöuûücç"
FN UpperText(@test$)
PRINT "UpperText =======> ";test$:PRINT

FN LowerText(@test$)
PRINT "LowerText =======> ";test$:PRINT

test$ = "aàââäeéèêëiîïoôöuûücç"
FN UpperText(@test$)
FN StripUpperText(@test$)
PRINT "StripUpperText ==> ";test$

DO
UNTIL FN BUTTON

Alain