Command SET LEXICAL Foundation
Activates or deactivates lexical rules in the comparison of character strings.
SET LEXICAL on | OFF | <lToggle>
In Xbase++, character strings can be compared with one another on the basis of lexical rules. These rules build on the country specific language support of the operating system and can be extended by the function SetLexRule(). This results in a powerful tool for sorting, searching and comparing character strings.
When SET LEXICAL is ON, the lexical comparison mode is used for comparisons of character strings performed using the comparison operators (=, >, <, => and =<). SET LEXICAL ON has precedence over SET EXACT ON. When the lexical comparison mode is turned on, all comparisons of character strings are first performed in the usual manner by the comparison operators. If the comparison provides the value .F. (false), an additional lexical comparison is performed based on the translation rules defined with SetLexRule().
The exact equals operator == does not consider lexical rules, but performs its comparison only on the basis of the characters in the character strings (a binary comparison).
// In the example, three lexical translation rules are
// defined and then the effect of SET LEXICAL is shown.
PROCEDURE Main
SetLexRule( { "ü", "ue" } ) // ü is equal to ue
SetLexRule( { "." , "" } ) // dot is equal to
// null string ( "" )
SetLexRule( { " " , "" } ) // blank space is equal to
// null string ("")
SET LEXICAL OFF // different ways of writing same
// name
? "Dr.Müller" = "Dr Mueller" // result: .F.
SET LEXICAL ON // different ways of writing same
// name
? "Dr.Müller" = "Dr Mueller" // result: .T.
? "Dr. Müller" = "Dr.Mueller" // result: .T.
? "Dr. Müller" = "Dr Mueller" // result: .T.
** Exact comparison
? "Dr.Müller" == "Dr Mueller" // result: .F.
RETURN
// The procedure SetWildCollation() is programmed in this example.
// It can be used to search for words which are similar in writing.
// No distinction is made between upper and lower case letters.
// Blank spaces, tabs and punctuation characters are ignored in
// string comparison.
PROCEDURE Main
SetWildCollation()
SET LEXICAL ON
CLS
?
? "Ä" = "ae" // result: .T.
? "z" = "Z" // result: .T.
? "Mayer" = "meier" // result: .T.
? "Mr.Smith" = "mr smith" // result: .T.
? "Colour" = "COLOR" // result: .T.
? "DR. MüLLer" = "dr mueller" // result: .T.
? "Mc Kenzie" = "Mackenzie" // result: .T.
? "McDonald's" = "Mac. Donalds" // result: .T.
RETURN
PROCEDURE SetWildCollation
LOCAL aCollation[256]
LOCAL cNullChars := " .:;-'"+Chr(9)
LOCAL cUpperCase := "AÄBCDEFGHIJKLMNOÖPQRS TUÜVWXYZ"
LOCAL cLowerCase := "aäbcdefghijklmnoöpqrsßtuüvwxyz"
LOCAL aLexRules := { {"ä","ae"}, {"ö","oe"}, {"ü","ue"}, ;
{"Ä","AE"}, {"Ö","OE"}, {"Ü","UE"}, ;
{"ß","ss"}, {"ou","o"}, {"Mc","Mac"}, ;
{"ai","ay"},{"ay","ei"} }
LOCAL nAscii, i, imax := Len( cLowerCase ), nSortOrder := 0
AFill( aCollation, 256 )
// Upper and lower case letters get the same weighing factor
FOR i:=1 TO imax
nAscii := Asc( SubStr( cUpperCase, i, 1 ) )
IF nAscii <> 32
aCollation[ nAscii+1 ] := nSortOrder
ENDIF
nAscii := Asc( SubStr( cLowerCase, i, 1 ) )
aCollation[ nAscii+1 ] := nSortOrder ++
NEXT
// All other characters are sorted after letters
i := 0
DO WHILE i < 256 .AND. ( i := AScan( aCollation, 256, i+1 ) ) > 0
aCollation[ i ] := nSortOrder ++
ENDDO
Set( _SET_COLLATION, aCollation )
// Add lexikal rules for white space and
// punctuation characters
imax := Len( cNullChars )
FOR i:=1 TO imax
AAdd( aLexRules, { SubStr(cNullChars,i,1), "" } )
NEXT
SetLexRule( aLexRules )
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.