Delphi 5 Use Pos / PosIgnoreCase for whole words only

257 Views Asked by At

I know Delphi 5 is really old but I have no other choice for now because my employer doesn't want to change, so I am stuck with old functions etc.

I would like to know if there was a way to get the position of the whole words I am looking for:

I have a list of words (if, then, else, and etc) named KEYWORDS, and for each word in it I have to check in every .pas file if this word contains some uppercase characters.

On my code, I am reading each line, and for each line, I am using this to find if I find any word in the list and if it has some uppercase characters:

if(PosIgnoreCase(KEYWORDS[I], S) <> Pos(KEYWORDS[I], S)) //Then the keyword has some uppercases in this line and I must raise an error

My problem is that if I use some words that contains the keywords ( for example "MODIFICATION") this will detect the uppercase IF in it and raise an error

I tried using if(PosIgnoreCase(' ' + KEYWORDS[I] + ' ', S) <> Pos(' ' + KEYWORDS[I] + ' ', S)) but there may be some parentheses or other characters instead of the spaces so I would like to avoid making a new condition for each character.

Is there a clean way to do it ? I found myself struggling quite often with the lack of functions in Delphi 5

Sorry if my question is somewhat confusing, english is not my first language.

Thank you for your time.


Update (from comments):

My list of keywords only contains the reserved keywords on Delphi

0

There are 0 best solutions below