I went ahead and adapted the code for allowing any non-Alpha leader to
force the following alpha character to UPPER case, and all other alpha characters to lower case. and wrote it in ASM for speed.
Code: Select all
;Note that either you have to change the Compiler/Compiler Options to allow
;Inline ASM Support for this code to compile correctly.
;Note that statements in ASM (Assembler) that refer to line lables have a "l_"
;(small L with underscore) added in front when referenced by an ASM instruction,
;and the characters must be in lower case. The actual line labels can be in
;mixed case, as illustrated in this code.
Procedure.s x_propercase(s.s) ;convert all groups of letters to Ucase form
MOV eax, [esp] ;string pointer on stack (pointed to by esp) into EAX reg
XOR dl, dl ;clear garbage for DL
Cycle: ;return point to repeat for each character in string
MOV dh,dl ;save the last processed char in DH
MOV dl,[eax] ;get the next character to process in DL
TEST dl,dl ;set flags against same register to check value
JZ l_endstring ;character is zero (Null), so exit process
AND dx,$DFDF ;get rid of lower case flag in DH and DL registers
CMP dl, 'Z' ;compare the value in DL with 90 (ascii code for 'Z')
JA l_not_alpha ;if above 'Z', it is not an Alpha character
CMP dl, 'A' ;compare the value in DL with 65 (ascii code for 'A')
JB l_not_alpha ;if below 'A', it is not an Alpha character
CMP dh, 'A' ;compare last character with 65 (ascii code for 'A')
JB l_high ;if below 'A', we keep the current letter in UPPER case
CMP dh, 'Z' ;compare last character with 90 (ascii code for 'Z')
JA l_high ;if above 'Z', we keep the current letter in UPPER case
Low: ;otherwise, we have two or more alpha characters in a row
OR dl, $20 ;and we force the current letter to lower case
High: ;and this is where the UPPER case letters merge in again
MOV [eax], dl ;so that we can store the correct case letter back
Not_Alpha:: ;or we skipped if current character not an Alpha character
INC eax ;we increment the string pointer for s.s to next character
JMP l_cycle ;and jump back to repeat for the next character
EndString:
ProcedureReturn s ;we make sure the changes are returned.
EndProcedure
OpenConsole()
ConsoleColor(15,1)
PrintN(x_propercase("tHIS iS a tESt of pROper *C*a(se)s."))
While Inkey()=""
Wend
I don't think that there are many more treatments left for this issue.
We now have examples in PB and in ASM for doing pretty much the
same thing, but some routines only capitalize immediately after a
space, and others (such as this example), capitalize immediately after
any non-alpha character.
I want to thank the contributors that gave some ASM examples, as these were great for helping me gain some insights as to how I can interface PB with ASM code.
has-been wanna-be (You may not agree with what I say, but it will make you think).