//morestrings.inc //by Tek //some more string manipulation functions. #macro IsWordChar( Char ) //test if this is any character that may appear in a "word" ( ( strcmp(strlwr(Char), "a") >= 0 & strcmp(strlwr(Char), "z") <= 0 ) | ( strcmp(strlwr(Char), "0") >= 0 & strcmp(strlwr(Char), "9") <= 0 ) | strcmp(strlwr(Char), "_") = 0 ) /* ( strcmp(Char, " ") //list of all word-terminating characters. || strcmp(Char, ",") || strcmp(Char, ".") || strcmp(Char, "\f") || strcmp(Char, "\n") || strcmp(Char, "\r") || strcmp(Char, "\t") ) */ #end #macro GetFirstWord( string ) #declare wordChar = 0; GetNextWord( string ) #end #macro avoidStupidLogicBug1(String) //pov always evaluates both parts of the condition, even if it doesn't need to! in this case this means it tries to read beyond the end of the string. so the standard C trick: while ( c < strlen(s) && somethingusing s[c] ) fails because the second part reads past the end of the string! pah! #local r = false; #if ( wordChar <= strlen(String) ) #local r = !IsWordChar( substr(String,wordChar,1) ); #end (r) #end #macro avoidStupidLogicBug2(String) #local r = false; #if ( wordChar <= strlen(String) ) #local r = IsWordChar( substr(String,wordChar,1) ); #end (r) #end #macro GetNextWord( String ) //skip whitespace and punctuation, etc. #while ( avoidStupidLogicBug1(String) ) #declare wordChar = wordChar + 1; #end #local Start = wordChar; //read until next whitespace #while ( avoidStupidLogicBug2(String) ) #declare wordChar = wordChar + 1; #end //return the word //returns "" when we're at the end of the string substr(String, Start, wordChar-Start) #end